Window > Arrange: drag the borders between arranged documents (#10101)

In 2-up, 3-up, 4-up, 6-up and the tiled layouts the border between two
documents now drags, as in Photoshop: the documents either side take the
new sizes, no cell goes narrower than 80 pt, and a border stops short of
its neighbours. The positions are kept in ViewOptions::arrange_splits,
checked before use (count, order, 0-1, finite) so a damaged or stale list
lays out even cells; choosing an arrangement starts from even cells.
Grabbing a border inside another document's edge no longer activates it.
This commit is contained in:
Lcoding15 committed 2026-11-01 14:04:42 +01:00
1 parent 5d815c5a4b
commit cc41902216
4 files changed
+323 -47

No files matched your search

+36 -2
View File
@@ -21,7 +21,7 @@ pub(crate) fn arranged_cells(app: &PhotocraftApp, rect: Rect) -> Option<Vec<(usi
if n == 0 {
return None;
}
let cells = crate::view_cmds::cells(&app.ui.view.arrange, rect, n)?;
let cells = crate::view_cmds::cells(&app.ui.view.arrange, rect, n, &app.ui.view.arrange_splits)?;
// Keep stable tiles, expressing the remembered document index in the filtered docked list.
let start = documents.partition_point(|&d| d < app.arrange_start).min(n.saturating_sub(cells.len()));
let idx = app.session.active_index().and_then(|d| documents.iter().position(|&p| p == d));
@@ -85,19 +85,26 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if let Some(shown) = arranged_cells(app, rect) {
app.arrange_start = shown.first().map_or(0, |(d, _)| *d);
let t = crate::theme::Tokens::get(ui.ctx());
// A press on a border grip drags the border (`drag_borders`); it activates no document.
let grips: Vec<Rect> = border_grips(app, rect).into_iter().map(|(_, grip)| grip).collect();
for (d, cell) in shown {
let cell = cell.shrink(1.0);
let view = app.ui.views[d].clone();
let v = canvas_view(app, ui, d, cell, view, d == active_doc);
if d != active_doc {
app.ui.views[d] = v;
if main_focused && ui.input(|i| i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| cell.contains(p))) {
if main_focused
&& ui.input(|i| {
i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| cell.contains(p) && !grips.iter().any(|g| g.contains(p)))
})
{
app.session.set_active(d);
}
}
let stroke = if d == active_doc { Stroke::new(1.5, t.accent) } else { Stroke::new(1.0, Color32::from_black_alpha(160)) };
ui.painter().rect_stroke(cell, 0, stroke, egui::StrokeKind::Inside);
}
drag_borders(app, ui, rect);
return;
}
if idx != active_doc && main_focused && ui.input(|i| i.pointer.primary_pressed() && i.pointer.interact_pos().is_some_and(|p| rect.contains(p))) {
@@ -107,6 +114,33 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
canvas_view(app, ui, idx, rect, view, app.session.active_index() == Some(idx));
}
/// Window › Arrange: the borders between the documents are dragged to give one more room, as in
/// Photoshop (#10101). Laid out after the canvases, so a grip over a cell's edge takes the press.
fn drag_borders(app: &mut PhotocraftApp, ui: &egui::Ui, rect: Rect) {
let n = docked_document_indices(app).len();
let layout = app.ui.view.arrange.clone();
for (border, grip) in border_grips(app, rect) {
let response = ui.interact(grip, ui.scope_id().with(("arrange-border", border.split)), Sense::drag());
if response.hovered() || response.dragged() {
ui.ctx().set_cursor_icon(if border.vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical });
}
if response.dragged()
&& let Some(p) = response.interact_pointer_pos()
{
crate::view_cmds::drag_border(&layout, rect, n, &mut app.ui.view.arrange_splits, border.split, p);
}
}
}
/// The arrangement's borders, each with the strip either side of it that grabs it.
fn border_grips(app: &PhotocraftApp, rect: Rect) -> Vec<(crate::view_cmds::Border, Rect)> {
let n = docked_document_indices(app).len();
crate::view_cmds::borders(&app.ui.view.arrange, rect, n, &app.ui.view.arrange_splits)
.into_iter()
.map(|b| (b, b.line.expand2(if b.vertical { egui::vec2(3.0, 0.0) } else { egui::vec2(0.0, 3.0) })))
.collect()
}
/// The tab strip; returns where its document tabs are.
pub(super) fn tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {
let t = crate::theme::Tokens::get(ui.ctx());
+5 -1
View File
@@ -18,7 +18,7 @@ mod dialogs;
mod dispatch;
mod options;
pub use arrange::cells;
pub use arrange::{Border, borders, cells, drag_border};
pub(crate) use arrange::{document_is_floating, float_window};
pub(crate) use dialogs::write_copy;
#[cfg(test)]
@@ -106,6 +106,9 @@ pub struct ViewOptions {
pub pixel_art_preview: bool,
/// Window › Arrange layout of the document area: "tabs" or a tile/n-up layout id.
pub arrange: String,
/// Where the borders between arranged documents were dragged (#10101): fractions of the
/// area, column borders then row borders; empty (or not fitting the layout) is even cells.
pub arrange_splits: Vec<f32>,
/// Type › Font Preview Size: "small" | "medium" | "large" | "extraLarge" | "huge".
pub font_preview_size: String,
/// Type › Language Options: "defaultFeatures" | "eastAsianFeatures" | "middleEasternFeatures",
@@ -138,6 +141,7 @@ impl Default for ViewOptions {
pattern_preview: false,
pixel_art_preview: false,
arrange: "tabs".into(),
arrange_splits: Vec::new(),
font_preview_size: "medium".into(),
language_features: "defaultFeatures".into(),
middle_eastern_composer: false,
+153 -37
View File
@@ -51,6 +51,8 @@ pub(crate) fn float_window(app: &mut PhotocraftApp, doc: usize, offset: usize, f
pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result<Value, String> {
if LAYOUTS.contains(&k) {
app.ui.view.arrange = k.to_string();
// A new arrangement starts from even cells.
app.ui.view.arrange_splits.clear();
// Each document fits its new cell.
app.ui.views.iter_mut().for_each(|v| v.fit_pending = true);
return Ok(json!({"arrange": k}));
@@ -132,43 +134,157 @@ pub(crate) fn document_is_floating(app: &PhotocraftApp, doc: usize) -> bool {
app.ui.windows.iter().any(|w| w.open && w.floating && w.document == doc)
}
/// Screen rectangles for `n` documents in an arrangement (`None` = tabs). The active document
/// always gets a cell; n-up layouts show that many documents starting from the active one.
pub fn cells(layout: &str, rect: egui::Rect, n: usize) -> Option<Vec<egui::Rect>> {
use craft_ui::layout::{SplitAxis, SplitSize, split_rect};
if n < 2 || !LAYOUTS.contains(&layout) {
return None;
}
let grid = |cols: usize, rows: usize, count: usize| -> Vec<egui::Rect> {
let (w, h) = (rect.width() / cols as f32, rect.height() / rows as f32);
(0..count.min(cols * rows))
.map(|i| egui::Rect::from_min_size(rect.min + egui::vec2((i % cols) as f32 * w, (i / cols) as f32 * h), egui::vec2(w, h)))
.collect()
};
Some(match layout {
"tileAllVertically" => grid(n, 1, n),
"tileAllHorizontally" => grid(1, n, n),
"twoUpVertical" => {
let panes = split_rect(rect, SplitAxis::Horizontal, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![panes.first, panes.second]
}
"twoUpHorizontal" => {
let panes = split_rect(rect, SplitAxis::Vertical, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![panes.first, panes.second]
}
"threeUpVertical" => grid(3, 1, 3),
"threeUpHorizontal" => grid(1, 3, 3),
"threeUpStacked" => {
let columns = split_rect(rect, SplitAxis::Horizontal, SplitSize::Ratio(0.5), 0.0, 0.0)?;
let rows = split_rect(columns.second, SplitAxis::Vertical, SplitSize::Ratio(0.5), 0.0, 0.0)?;
vec![columns.first, rows.first, rows.second]
}
"fourUp" => grid(2, 2, 4),
"sixUp" => grid(3, 2, 6),
_ => {
let cols = (n as f32).sqrt().ceil() as usize;
grid(cols, n.div_ceil(cols), n)
/// Screen rectangles for `n` documents in an arrangement (`None` = tabs), with the borders
/// where they were left (`splits`, [`ViewOptions::arrange_splits`](super::ViewOptions)). The
/// active document always gets a cell; n-up layouts show that many documents starting from the
/// active one.
pub fn cells(layout: &str, rect: egui::Rect, n: usize, splits: &[f32]) -> Option<Vec<egui::Rect>> {
let shape = Shape::of(layout, n)?;
let (xs, ys) = shape.lines(rect, splits);
Some(match shape {
Shape::Grid { cols, rows, count } => (0..count.min(cols * rows))
.filter_map(|i| {
let (c, r) = (i % cols, i / cols);
Some(egui::Rect::from_min_max(egui::pos2(*xs.get(c)?, *ys.get(r)?), egui::pos2(*xs.get(c + 1)?, *ys.get(r + 1)?)))
})
.collect(),
// One tall cell on the left; the right column is cut in two.
Shape::Stacked => {
let (x, y) = (xs.get(1).copied().unwrap_or(rect.center().x), ys.get(1).copied().unwrap_or(rect.center().y));
vec![
egui::Rect::from_min_max(rect.min, egui::pos2(x, rect.max.y)),
egui::Rect::from_min_max(egui::pos2(x, rect.min.y), egui::pos2(rect.max.x, y)),
egui::Rect::from_min_max(egui::pos2(x, y), rect.max),
]
}
})
}
/// A border between arranged documents that can be dragged, as in Photoshop (#10101).
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Border {
/// Which of the arrangement's splits it is: the index for [`drag_border`].
pub split: usize,
/// It runs top to bottom (and moves left and right).
pub vertical: bool,
/// Its line on screen: zero wide (or tall) across the cells it divides.
pub line: egui::Rect,
}
/// The borders of an arrangement, as laid out by [`cells`].
pub fn borders(layout: &str, rect: egui::Rect, n: usize, splits: &[f32]) -> Vec<Border> {
let Some(shape) = Shape::of(layout, n) else { return Vec::new() };
let (xs, ys) = shape.lines(rect, splits);
let inner = |v: &[f32]| v.get(1..v.len().saturating_sub(1)).unwrap_or_default().to_vec();
let (inner_x, inner_y) = (inner(&xs), inner(&ys));
let vertical = inner_x.iter().enumerate().map(|(i, &x)| Border {
split: i,
vertical: true,
line: egui::Rect::from_min_max(egui::pos2(x, rect.min.y), egui::pos2(x, rect.max.y)),
});
// 3-up Stacked's row border spans only the right column.
let left = match shape {
Shape::Stacked => inner_x.first().copied().unwrap_or(rect.min.x),
Shape::Grid { .. } => rect.min.x,
};
let horizontal = inner_y.iter().enumerate().map(|(i, &y)| Border {
split: inner_x.len() + i,
vertical: false,
line: egui::Rect::from_min_max(egui::pos2(left, y), egui::pos2(rect.max.x, y)),
});
vertical.chain(horizontal).collect()
}
/// Move border `split` of the arrangement to `pointer` (screen points), keeping every cell at
/// least [`MIN_CELL`] points across where the area allows. `splits` is rewritten in full, so a
/// stale or damaged list starts again from even cells.
pub fn drag_border(layout: &str, rect: egui::Rect, n: usize, splits: &mut Vec<f32>, split: usize, pointer: egui::Pos2) {
let Some(shape) = Shape::of(layout, n) else { return };
let (cols, rows) = shape.counts();
let mut fractions = shape.fractions(splits);
// The borders on the dragged one's axis are `fractions[first..first + count]`.
let (axis_start, axis_len, first, count, pos) = if split < cols - 1 {
(rect.min.x, rect.width(), 0, cols - 1, pointer.x)
} else if split < (cols - 1) + (rows - 1) {
(rect.min.y, rect.height(), cols - 1, rows - 1, pointer.y)
} else {
return;
};
if !(axis_len > 0.0 && pos.is_finite()) {
return;
}
let own = fractions.get(first..first + count).map(<[f32]>::to_vec).unwrap_or_default();
let k = split - first;
let gap = (MIN_CELL / axis_len).min(0.5 / own.len().saturating_add(1) as f32);
let lo = if k == 0 { 0.0 } else { own.get(k - 1).copied().unwrap_or(0.0) } + gap;
let hi = own.get(k + 1).copied().unwrap_or(1.0) - gap;
if let Some(f) = fractions.get_mut(split) {
*f = ((pos - axis_start) / axis_len).clamp(lo.min(hi), hi.max(lo));
}
*splits = fractions;
}
/// The narrowest a cell is dragged to, in points.
pub const MIN_CELL: f32 = 80.0;
/// An arrangement as columns and rows of cells.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Shape {
/// `cols` × `rows` even cells, the first `count` of them used.
Grid { cols: usize, rows: usize, count: usize },
/// 3-up Stacked: two columns, the right one in two rows.
Stacked,
}
impl Shape {
fn of(layout: &str, n: usize) -> Option<Shape> {
if n < 2 || !LAYOUTS.contains(&layout) {
return None;
}
let grid = |cols: usize, rows: usize, count: usize| Shape::Grid { cols, rows, count };
Some(match layout {
"tileAllVertically" => grid(n, 1, n),
"tileAllHorizontally" => grid(1, n, n),
"twoUpVertical" => grid(2, 1, 2),
"twoUpHorizontal" => grid(1, 2, 2),
"threeUpVertical" => grid(3, 1, 3),
"threeUpHorizontal" => grid(1, 3, 3),
"threeUpStacked" => Shape::Stacked,
"fourUp" => grid(2, 2, 4),
"sixUp" => grid(3, 2, 6),
_ => {
let cols = (n as f32).sqrt().ceil() as usize;
grid(cols, n.div_ceil(cols), n)
}
})
}
fn counts(self) -> (usize, usize) {
match self {
Shape::Grid { cols, rows, .. } => (cols, rows),
Shape::Stacked => (2, 2),
}
}
/// The split positions as fractions: the column borders, then the row borders. `splits`
/// is used only when it fits this shape (as many values, each axis increasing within 0–1);
/// otherwise the cells are even.
fn fractions(self, splits: &[f32]) -> Vec<f32> {
let (cols, rows) = self.counts();
let even = |k: usize| (1..k).map(move |i| i as f32 / k as f32);
let ordered = |v: &[f32]| v.iter().all(|f| f.is_finite() && *f > 0.0 && *f < 1.0) && v.windows(2).all(|w| matches!(w, [a, b] if a < b));
let fit = splits.len() == (cols - 1) + (rows - 1) && splits.get(..cols - 1).is_some_and(ordered) && splits.get(cols - 1..).is_some_and(ordered);
if fit { splits.to_vec() } else { even(cols).chain(even(rows)).collect() }
}
/// Every column line's x and every row line's y on screen, the area's edges included.
fn lines(self, rect: egui::Rect, splits: &[f32]) -> (Vec<f32>, Vec<f32>) {
let (cols, _) = self.counts();
let fractions = self.fractions(splits);
let (fx, fy) = fractions.split_at((cols - 1).min(fractions.len()));
let at = |start: f32, len: f32, inner: &[f32]| {
std::iter::once(start).chain(inner.iter().map(|f| start + len * f)).chain(std::iter::once(start + len)).collect::<Vec<f32>>()
};
(at(rect.min.x, rect.width(), fx), at(rect.min.y, rect.height(), fy))
}
}
+129 -7
View File
@@ -160,14 +160,14 @@ fn print_size_uses_the_screen_resolution_preference() {
#[test]
fn arrange_layouts_floating_windows_and_matching() {
let (mut app, ctx) = app_with(3);
assert!(cells("tabs", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).is_none());
assert!(cells("tabs", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).is_none());
menu(&mut app, &ctx, "window.arrange.threeUpStacked", json!({})).unwrap();
assert_eq!(checked(&app, "window.arrange.threeUpStacked"), Some(true));
let c = cells(&app.ui.view.arrange, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).unwrap();
let c = cells(&app.ui.view.arrange, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).unwrap();
assert_eq!(c.len(), 3);
assert_eq!(c[0].height(), 600.0);
assert_eq!(c[1].height(), 300.0);
let six = cells("sixUp", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3).unwrap();
let six = cells("sixUp", egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0)), 3, &[]).unwrap();
assert_eq!((six.len(), six[1].min.x), (6, 300.0));
menu(&mut app, &ctx, "window.arrange.floatAllInWindows", json!({})).unwrap();
assert_eq!(app.ui.windows.len(), 3);
@@ -209,13 +209,91 @@ fn match_zoom_clamps_to_each_documents_zoom_range() {
fn two_up_and_stacked_cells_keep_their_existing_boundaries() {
let rect = egui::Rect::from_min_max(egui::pos2(40.0, 75.0), egui::pos2(940.0, 675.0));
let region = |left, top, right, bottom| egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(right, bottom));
assert_eq!(cells("twoUpVertical", rect, 2).unwrap(), vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpHorizontal", rect, 2).unwrap(), vec![region(40.0, 75.0, 940.0, 375.0), region(40.0, 375.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpVertical", rect, 2, &[]).unwrap(), vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 675.0)]);
assert_eq!(cells("twoUpHorizontal", rect, 2, &[]).unwrap(), vec![region(40.0, 75.0, 940.0, 375.0), region(40.0, 375.0, 940.0, 675.0)]);
assert_eq!(
cells("threeUpStacked", rect, 3).unwrap(),
cells("threeUpStacked", rect, 3, &[]).unwrap(),
vec![region(40.0, 75.0, 490.0, 675.0), region(490.0, 75.0, 940.0, 375.0), region(490.0, 375.0, 940.0, 675.0)]
);
assert!(cells("twoUpVertical", rect, 1).is_none());
assert!(cells("twoUpVertical", rect, 1, &[]).is_none());
}
#[test]
fn dragged_arrange_borders_resize_the_cells_beside_them() {
// #10101: in 2-up and the other arrangements the border between documents drags, as in
// Photoshop, and the documents on either side take the new sizes.
use super::arrange::{Border, MIN_CELL};
let near = |a: &[egui::Rect], b: &[egui::Rect]| {
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| (a.min - b.min).length() < 0.01 && (a.max - b.max).length() < 0.01)
};
let rect = egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(900.0, 600.0));
let region = |left, top, right, bottom| egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(right, bottom));
let mut splits = Vec::new();
let b = borders("twoUpVertical", rect, 2, &splits);
assert_eq!(b, vec![Border { split: 0, vertical: true, line: region(450.0, 0.0, 450.0, 600.0) }]);
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(300.0, 250.0));
assert!(near(&cells("twoUpVertical", rect, 2, &splits).unwrap(), &[region(0.0, 0.0, 300.0, 600.0), region(300.0, 0.0, 900.0, 600.0)]));
assert!((borders("twoUpVertical", rect, 2, &splits)[0].line.min.x - 300.0).abs() < 0.01);
// No cell is dragged narrower than MIN_CELL, nor past the area.
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(-500.0, 0.0));
assert!((cells("twoUpVertical", rect, 2, &splits).unwrap()[0].width() - MIN_CELL).abs() < 0.01);
drag_border("twoUpVertical", rect, 2, &mut splits, 0, egui::pos2(899.0, 0.0));
assert!((cells("twoUpVertical", rect, 2, &splits).unwrap()[1].width() - MIN_CELL).abs() < 0.01);
// 4-up: a column border and a row border, each across the whole area.
let mut splits = Vec::new();
let b = borders("fourUp", rect, 4, &splits);
assert_eq!(b.iter().map(|b| (b.split, b.vertical)).collect::<Vec<_>>(), vec![(0, true), (1, false)]);
drag_border("fourUp", rect, 4, &mut splits, 1, egui::pos2(10.0, 450.0));
let c = cells("fourUp", rect, 4, &splits).unwrap();
assert!(near(&[c[0], c[3]], &[region(0.0, 0.0, 450.0, 450.0), region(450.0, 450.0, 900.0, 600.0)]));
// 3-up Stacked: the row border is only across the right column, and follows the column.
let mut splits = Vec::new();
drag_border("threeUpStacked", rect, 3, &mut splits, 0, egui::pos2(600.0, 0.0));
drag_border("threeUpStacked", rect, 3, &mut splits, 1, egui::pos2(700.0, 200.0));
assert!(near(
&cells("threeUpStacked", rect, 3, &splits).unwrap(),
&[region(0.0, 0.0, 600.0, 600.0), region(600.0, 0.0, 900.0, 200.0), region(600.0, 200.0, 900.0, 600.0)]
));
assert!(near(&[borders("threeUpStacked", rect, 3, &splits)[1].line], &[region(600.0, 200.0, 900.0, 200.0)]));
// Tiled: a border stops short of its neighbours, so the cells keep their order.
let mut splits = Vec::new();
drag_border("threeUpVertical", rect, 3, &mut splits, 0, egui::pos2(800.0, 0.0));
let c = cells("threeUpVertical", rect, 3, &splits).unwrap();
assert!((c[0].max.x - (600.0 - MIN_CELL)).abs() < 0.01 && (c[1].width() - MIN_CELL).abs() < 0.01);
}
#[test]
fn damaged_or_stale_arrange_splits_lay_out_even_cells() {
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(900.0, 600.0));
let even = cells("threeUpVertical", rect, 3, &[]).unwrap();
// From a settings file or another layout: wrong count, out of order, outside 0–1, NaN.
for bad in [vec![0.5], vec![0.6, 0.3], vec![0.0, 0.5], vec![0.3, 1.5], vec![f32::NAN, 0.7], vec![0.2, 0.4, 0.6]] {
assert_eq!(cells("threeUpVertical", rect, 3, &bad).unwrap(), even, "{bad:?}");
assert_eq!(borders("threeUpVertical", rect, 3, &bad).len(), 2);
// A drag starts again from even cells.
let mut splits = bad.clone();
drag_border("threeUpVertical", rect, 3, &mut splits, 1, egui::pos2(700.0, 0.0));
assert_eq!(cells("threeUpVertical", rect, 3, &splits).unwrap()[0], even[0], "{bad:?}");
}
// A split that isn't the layout's, or a pointer off the numbers, changes nothing.
let mut splits = vec![0.25, 0.5];
drag_border("threeUpVertical", rect, 3, &mut splits, 2, egui::pos2(700.0, 0.0));
drag_border("threeUpVertical", rect, 3, &mut splits, 0, egui::pos2(f32::NAN, 0.0));
drag_border("threeUpVertical", egui::Rect::NOTHING, 3, &mut splits, 0, egui::pos2(10.0, 0.0));
assert_eq!(splits, vec![0.25, 0.5]);
assert!(borders("tabs", rect, 3, &[]).is_empty());
}
#[test]
fn choosing_an_arrangement_starts_from_even_cells() {
let (mut app, ctx) = app_with(2);
menu(&mut app, &ctx, "window.arrange.twoUpVertical", json!({})).unwrap();
app.ui.view.arrange_splits = vec![0.3];
menu(&mut app, &ctx, "window.arrange.twoUpHorizontal", json!({})).unwrap();
assert!(app.ui.view.arrange_splits.is_empty());
}
#[test]
@@ -749,6 +827,50 @@ fn arranged_documents_keep_their_tiles() {
assert_eq!(docs(&mut app, 1), vec![0, 1]);
}
/// #10101: dragging the border between two arranged documents moves it. Grabbed inside the
/// other document's edge, it doesn't make that document the active one.
#[test]
fn dragging_the_border_between_arranged_documents_resizes_them() {
use egui_kittest::Harness;
let (mut app, _) = app_with(2);
app.ui.view.arrange = "twoUpVertical".into();
app.ui.tool = crate::state::Tool::Brush;
// The right-hand document is active; the grab below is inside the left one's edge.
app.session.set_active(1);
let mut h = Harness::builder().with_size(egui::vec2(1000.0, 600.0)).build_ui_state(
|ui, app: &mut PhotocraftApp| {
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
return;
}
egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
},
app,
);
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
h.run_steps(4);
let area = h.state().last_canvas_rect;
let n = h.state().session.documents().len();
let border = borders("twoUpVertical", area, n, &[])[0].line;
// On the grip, 2 pt inside the left document (its cell ends 1 pt short of the border).
let from = border.center() - egui::vec2(2.0, 0.0);
let to = from - egui::vec2(200.0, 0.0);
let ev = |h: &mut Harness<'_, PhotocraftApp>, e: egui::Event| h.input_mut().events.push(e);
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
ev(&mut h, egui::Event::PointerMoved(from));
h.run();
ev(&mut h, button(from, true));
h.run();
for step in 1..=10 {
ev(&mut h, egui::Event::PointerMoved(from + (to - from) * (step as f32 / 10.0)));
h.run();
}
ev(&mut h, button(to, false));
h.run_steps(2);
let cells = cells("twoUpVertical", area, n, &h.state().ui.view.arrange_splits).unwrap();
assert!((cells[0].max.x - to.x).abs() < 1.0, "the border follows the pointer: {cells:?}, pointer at {}", to.x);
assert_eq!(h.state().session.active_index(), Some(1), "grabbing the border activates no document");
}
/// #6017: rulers showed in the active tile only; the other tile had none and no room for them.
#[test]
fn every_arranged_tile_has_rulers() {