diff --git a/crates/ui/src/docking/surface.rs b/crates/ui/src/docking/surface.rs index f133f190f..64046b323 100644 --- a/crates/ui/src/docking/surface.rs +++ b/crates/ui/src/docking/surface.rs @@ -51,9 +51,9 @@ pub struct DockStyle { /// The outer edge band also runs along the left and right edges, where a drop adds a /// full-height column. Off: only the top and bottom edges add a full-width row. pub side_edge_zones: bool, - /// How far a group's side drop zones reach into its body, below the tab strip. A body less - /// than three times as wide or tall gets zones a third of its extent deep in that axis, so - /// it keeps a center. + /// How far a group's side drop zones reach into its body, below the tab strip. All four + /// zones share one depth: this, or a quarter of the body's smaller side when that is less, + /// so the body keeps a center. pub zone_depth: f32, /// [D] The docked area's left and right edges, where no dock is yet, take a drop as a new /// dock (see [`Self::new_dock_band`]). diff --git a/crates/ui/src/docking/targets.rs b/crates/ui/src/docking/targets.rs index 89e235e0b..82eec3250 100644 --- a/crates/ui/src/docking/targets.rs +++ b/crates/ui/src/docking/targets.rs @@ -1,4 +1,4 @@ -use egui::{Pos2, Rangef, Rect, Vec2, pos2, vec2}; +use egui::{Pos2, Rangef, Rect, Vec2, pos2}; use super::{Placement, Side, Target, Zone}; @@ -32,10 +32,11 @@ pub(super) fn usable(rect: Rect) -> bool { } /// Tab header (the top `tab_height` of `rect`) is the center; otherwise the nearest side zone of -/// the body below it wins. A side zone reaches `depth` into the body, or a third of the body's -/// extent in that axis when that is less, so a body always keeps a center; a `depth` of zero -/// or less leaves only the center. Outside, non-finite, empty and inverted rectangles have no -/// target. +/// the body below it wins. Every side zone reaches the same depth into the body: `depth`, or a +/// quarter of the body's smaller side when that is less, so a body always keeps a center and a +/// narrow body's top and bottom zones are no deeper than its left and right ones. A `depth` of +/// zero or less leaves only the center. Outside, non-finite, empty and inverted rectangles have +/// no target. pub fn drop_zone(rect: Rect, tab_height: f32, depth: f32, pointer: Pos2) -> Option { if !usable(rect) || !pointer.is_finite() || !rect.contains(pointer) || !tab_height.is_finite() || tab_height < 0.0 { return None; @@ -65,10 +66,10 @@ fn body(rect: Rect, tab_height: f32) -> Rect { } /// How deep the side zones of `body` reach in from its left and right edges (`x`) and its top -/// and bottom edges (`y`). +/// and bottom edges (`y`): the same on all four sides. fn side_depths(body: Rect, depth: f32) -> Vec2 { let depth = if depth > 0.0 { depth } else { 0.0 }; - vec2(depth.min(body.width() / 3.0), depth.min(body.height() / 3.0)) + Vec2::splat(depth.min(body.width().min(body.height()) / 4.0)) } /// The outline of a drop zone of the group drawn at `rect`, as [`drop_zone`] finds it with the @@ -152,8 +153,8 @@ pub fn tab_insertion_marker(target: &DropTarget

, before: Option<&P>) - /// Resolve a pointer against visible groups. The frontmost containing group occludes groups /// behind it even if it rejects the drop. A strip reorders by midpoint; the body of the source /// group is a no-op at center. The body's side zones are [`drop_zone`]'s with `zone_depth` (see -/// [`crate::docking::DockStyle::zone_depth`]). Floating groups normally set `allow_splits` to -/// false. +/// [`crate::docking::DockStyle::zone_depth`]): one depth on all four sides, at most a quarter of +/// the body's smaller side. Floating groups normally set `allow_splits` to false. pub fn resolve_drop(panel: &P, pointer: Pos2, targets: &[DropTarget

], zone_depth: f32) -> Option> { if !pointer.is_finite() || targets.len() > super::MAX_PANELS { return None; diff --git a/crates/ui/src/docking/tests.rs b/crates/ui/src/docking/tests.rs index 2a3d7c56f..80c1fb97d 100644 --- a/crates/ui/src/docking/tests.rs +++ b/crates/ui/src/docking/tests.rs @@ -303,23 +303,30 @@ fn pointer_targets_distinguish_reorder_center_split_and_occlusion() { } #[test] -fn side_zones_are_40_pt_deep_or_a_third_of_a_small_body() { +fn side_zones_are_40_pt_deep_or_a_quarter_of_the_bodys_smaller_side() { let depth = DockStyle::default().zone_depth; assert_eq!(depth, 40.0); // The inner corner of the left trapezoid is the depth of both bands. let inner = |rect: Rect| zone_shape(rect, 0.0, depth, Zone::Left).unwrap()[1] - rect.min; - for size in [vec2(600.0, 400.0), vec2(130.0, 130.0)] { + for size in [vec2(600.0, 400.0), vec2(160.0, 160.0)] { let rect = Rect::from_min_size(pos2(10.0, 20.0), size); assert_eq!(inner(rect), vec2(40.0, 40.0), "{size:?}"); let y = rect.center().y; assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.left() + 39.0, y)), Some(Zone::Left), "{size:?}"); assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.left() + 41.0, y)), Some(Zone::Center), "{size:?}"); } - // A 90 pt body keeps a 30 pt center. + // A 90 pt body keeps a 45 pt center. let rect = Rect::from_min_size(pos2(10.0, 20.0), vec2(90.0, 90.0)); - assert_eq!(inner(rect), vec2(30.0, 30.0)); + assert_eq!(inner(rect), vec2(22.5, 22.5)); assert_eq!(drop_zone(rect, 0.0, depth, rect.center()), Some(Zone::Center)); - assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.left() + 29.0, rect.center().y)), Some(Zone::Left)); + assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.left() + 22.0, rect.center().y)), Some(Zone::Left)); + // A tall narrow body: its top and bottom zones are as deep as its left and right ones. + let rect = Rect::from_min_size(pos2(10.0, 20.0), vec2(120.0, 600.0)); + assert_eq!(inner(rect), vec2(30.0, 30.0)); + let top = zone_shape(rect, 0.0, depth, Zone::Top).unwrap(); + assert_eq!(top[2].y - rect.top(), 30.0); + assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.center().x, rect.top() + 29.0)), Some(Zone::Top)); + assert_eq!(drop_zone(rect, 0.0, depth, pos2(rect.center().x, rect.top() + 31.0)), Some(Zone::Center)); // The bands start below the tab header. let rect = Rect::from_min_size(pos2(10.0, 20.0), vec2(600.0, 400.0)); assert_eq!(drop_zone(rect, 24.0, depth, pos2(rect.center().x, rect.top() + 60.0)), Some(Zone::Top)); diff --git a/docs/ui-docking.md b/docs/ui-docking.md index 2cac493d9..33b27d092 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -211,8 +211,8 @@ A flyout fits its content the same way, without the title bar. limits and the screen. A focused resize handle moves its edge 8 pt per arrow key. - Over a frame, the tab strip and the middle join its tabs, and the nearest side splits it. The side zones are trapezoids along the four edges of the body below the tab strip, like a picture - frame: `DockStyle::zone_depth` (40 pt) deep, or a third of the body's width or height when that - is less, so every frame keeps a center. A split that would leave either half without + frame, all four the same depth: `DockStyle::zone_depth` (40 pt), or a quarter of the body's + smaller side when that is less, so every frame keeps a center. A split that would leave either half without `DockStyle::min_pane` joins the frame's tabs instead. The gap between two frames is no target. - The outer edge band (`DockStyle::edge_band`) takes a drop as a new frame across the whole window side: top and bottom, and left and right with `side_edge_zones`. It takes a quarter of