From 9012e52081825ee22714322f8bdf281bb3cbcd52 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Wed, 25 Nov 2026 10:09:21 +0700 Subject: [PATCH] dock, iconic column: under IconGroupSeparator::Rule a collapsed column's icon groups have no grip strips: the first icon stands right under the column's bar, a group's first icon drags the group, and the room between two groups is space.gap.stack and the rule, the rule in its middle; Grip, the default, keeps its strips --- crates/ui-panels/src/docking/group.rs | 2 +- crates/ui-panels/src/docking/iconic.rs | 67 +++++++++++-------- .../ui-panels/src/docking/iconic/stories.rs | 2 +- crates/ui-panels/src/docking/iconic/trials.rs | 46 ++++++++----- 4 files changed, 71 insertions(+), 46 deletions(-) diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index bc4a31f9a7..29c277e8ac 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -46,7 +46,7 @@ pub struct GroupGripStyle { /// (photocraft#16426): ticks, dots or one level bar, how many, how large and how far apart; by default eleven upright ticks, a thin /// stroke wide, five points tall and a thin stroke apart. The marks keep their ink under the pointer. A toolbar's grip /// under its column bar and the grip above each icon group of a collapsed column paint the same marks, unless the app -/// separates icon groups by a rule (`IconGroupSeparator::Rule`). +/// separates icon groups by a rule (`IconGroupSeparator::Rule`), where the groups have no grip strips. #[derive(Clone, Copy, Debug, PartialEq)] pub(super) struct GripMarks { ink: StyleColor, diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 2e843d283e..070779f3db 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -46,9 +46,11 @@ pub struct IconicSizes { pub column: DockSizes, /// The height of an icon cell (the rail button). pub cell: f32, - /// The height of the grip strip at the top of each icon group, above its first icon. + /// The height of the grip strip at the top of each icon group, above its first icon: none with + /// [`IconGroupSeparator::Rule`]. pub grip: f32, - /// The room between two icon groups. + /// The room between two icon groups: the tight gap, or with [`IconGroupSeparator::Rule`] the stack gap and the + /// rule. pub separator: f32, /// The column width from which each cell shows its panel's name beside its icon. pub labels: f32, @@ -61,13 +63,11 @@ impl IconicSizes { /// The sizes of the style context `cx`. pub fn style(cx: &StyleCx<'_>) -> Self { let size = &cx.tokens.size; - IconicSizes { - column: DockSizes::style(cx), - cell: size.rail.button, - grip: super::group::grip_strip(cx.tokens), - separator: cx.tokens.space.gap.tight, - labels: size.rail.width * LABELS_IN_RAIL_WIDTHS, - } + let (grip, separator) = match cx.env::() { + IconGroupSeparator::Grip => (super::group::grip_strip(cx.tokens), cx.tokens.space.gap.tight), + IconGroupSeparator::Rule => (0.0, cx.tokens.space.gap.stack + cx.rule(RuleKind::Edge).width.points(cx.frame_ctx().pixels_per_point())), + }; + IconicSizes { column: DockSizes::style(cx), cell: size.rail.button, grip, separator, labels: size.rail.width * LABELS_IN_RAIL_WIDTHS } } /// The sizes in the root scope's style, for code outside a style pass: @@ -98,16 +98,17 @@ pub enum IconicMode { Rail, } -/// What marks the icon groups of a collapsed column apart. An app sets it once at its root (`RootEnv::values`). Either -/// way each group keeps its grip strip above its first icon, which drags the group. +/// What marks the icon groups of a collapsed column apart. An app sets it once at its root (`RootEnv::values`). #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, crate::contract::MemoProps)] #[env(style)] #[non_exhaustive] pub enum IconGroupSeparator { - /// Each group's grip strip shows the dock's grip marks (`shape.grip`, in `line.grip`). + /// Each group has a grip strip above its first icon, which shows the dock's grip marks (`shape.grip`, in + /// `line.grip`) and drags the group. #[default] Grip, - /// The grip strips are bare, and an edge rule (`line.border`) lies level across the room between two groups, + /// No grip strips: a group's first icon drags the group, its first icon stands right under the column's bar, and an + /// edge rule (`line.border`) lies level in the middle of the `space.gap.stack` between two groups, /// `space.gap.inline` short of the column's sides: VectorCraft's icon groups, as production drew them. Rule, } @@ -436,7 +437,9 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> { } y += sizes.cell; } - grips.push((at, grip)); + if grip.height() > 0.0 { + grips.push((at, grip)); + } groups.push((at, Rect::from_min_max(Pos2::new(body.left(), top), Pos2::new(body.right(), y)))); } Plan { bar, cells, names, grips, groups, body } @@ -576,22 +579,30 @@ impl Component for IconicColumn<'_, P> { let dragging = |phase: PressPhase| matches!(phase, PressPhase::DragStart { start, .. } if start.button == craft_behavior::PointerButton::Primary); let mut began = false; - for (group, extent) in &plan.groups { - if dragging(cx.part(GRIP.at(*group as u64)).press.phase) - && let Some(lead) = self.column.groups.get(*group) - && let Some(anchor) = lead.panels.first() - { - let shown = lead.active_panel().unwrap_or(anchor); - let label = Label::from((self.spec)(shown).label.as_str().to_owned()); - start_icon_drag(cx, DragUnit::Group(anchor.clone()), PanelKey::of(shown), extent.size(), label); - began = true; + // A group drags by its grip strip, or without one by its first icon. + let group_drag = |cx: &mut Cx<'_, Self>, group: usize| { + let lead = self.column.groups.get(group)?; + let anchor = lead.panels.first()?; + let extent = plan.groups.iter().find(|(at, _)| *at == group)?.1; + let shown = lead.active_panel().unwrap_or(anchor); + let label = Label::from((self.spec)(shown).label.as_str().to_owned()); + start_icon_drag(cx, DragUnit::Group(anchor.clone()), PanelKey::of(shown), extent.size(), label); + Some(()) + }; + for (group, _) in &plan.grips { + if cx.part_if_declared(GRIP.at(*group as u64)).is_some_and(|grip| dragging(grip.press.phase)) { + began |= group_drag(cx, *group).is_some(); } } + let gripless = plan.grips.is_empty(); for (at, (group, panel, cell)) in plan.cells.iter().enumerate() { let named = cx.part_if_declared(NAME.at(at as u64)).is_some_and(|name| dragging(name.press.phase)); - if (dragging(cx.part(CELL.at(at as u64)).press.phase) || named) - && let Some(panel) = self.panel(*group, *panel) - { + if !(dragging(cx.part(CELL.at(at as u64)).press.phase) || named) { + continue; + } + if gripless && *panel == 0 { + began |= group_drag(cx, *group).is_some(); + } else if let Some(panel) = self.panel(*group, *panel) { let label = Label::from((self.spec)(panel).label.as_str().to_owned()); start_icon_drag(cx, DragUnit::Panel(panel.clone()), PanelKey::of(panel), cell.size(), label); began = true; @@ -692,8 +703,8 @@ impl Component for IconicColumn<'_, P> { IconGroupSeparator::Rule => { let xs = plan.body.x_range().shrink(style.rule_inset); // In the middle of the room from a group's last icon to the next group's first. - for ((_, above), (_, strip)) in plan.groups.iter().zip(plan.grips.iter().skip(1)) { - let y = (above.bottom() + strip.bottom()) / 2.0; + for pair in plan.groups.windows(2) { + let y = (pair[0].1.bottom() + pair[1].1.top()) / 2.0; ui.draw().rule(RuleKind::Edge, Pos2::new(xs.min, y), Pos2::new(xs.max, y)); } } diff --git a/crates/ui-panels/src/docking/iconic/stories.rs b/crates/ui-panels/src/docking/iconic/stories.rs index 29171652a8..5b8330b325 100644 --- a/crates/ui-panels/src/docking/iconic/stories.rs +++ b/crates/ui-panels/src/docking/iconic/stories.rs @@ -114,7 +114,7 @@ fn icons_as_a_card(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { .into() } -/// The icon groups of an app that sets `IconGroupSeparator::Rule` at its root (VectorCraft's): bare grip strips, and an +/// The icon groups of an app that sets `IconGroupSeparator::Rule` at its root (VectorCraft's): no grip strips, and an /// edge rule across the room between two groups. #[story(IconicColumn<'static, u8>, covers = [], drive = Drive::Never, title = "Icon groups apart by a rule")] fn icon_groups_apart_by_a_rule(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index b3d65d6652..ce509305da 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -24,7 +24,7 @@ use crate::testing::{Fixture, trial}; use craft_behavior::DockSide; use craft_behavior::dock::{Action, Column, DockEdge, Group, Layout, Node}; use craft_behavior::overlay::Side; -use egui::{Key, Modifiers, Pos2, Rect, UiBuilder, Vec2}; +use egui::{Id, Key, Modifiers, Pos2, Rect, UiBuilder, Vec2}; use std::cell::{Cell, RefCell}; use std::rc::Rc; @@ -662,19 +662,17 @@ fn a_themes_bar_grip_is_one_level_bar() { assert!((bar.center().x - strip.center().x).abs() <= 0.5, "centred across the strip: {bar:?} in {strip:?}"); } -/// An app's `IconGroupSeparator::Rule` (VectorCraft's): the grip strips show no marks, and one level edge rule lies in -/// the room between the two groups, under the first group's last icon and over the second group's first, short of the -/// column's sides; none lies over the first group. -#[trial] -fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { - let mut fixture = Fixture::hosted(|ui| { +/// The icons of the two groups of a collapsed column whose groups stand apart by `separator`: the column's id and the +/// fixture. +fn separated(separator: IconGroupSeparator) -> (Fixture, Id) { + let mut fixture = Fixture::hosted(move |ui| { let mut column = Column::new(vec![Group::new(vec![1, 2], 0), Group::new(vec![3], 0)]); column.iconic = true; let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y)); with_env( ui, |overrides| { - overrides.values.set(IconGroupSeparator::Rule); + overrides.values.set(separator); }, |ui| { let output = IconicColumn::new("Panels", global("iconic column", "rule"), &column, Bind::kept(), &named) @@ -686,6 +684,17 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { }); fixture.room(SCREEN).settle(); let id = fixture.root_id().expect("the column shows"); + (fixture, id) +} + +/// An app's `IconGroupSeparator::Rule` (VectorCraft's): no grip strips, so the first icon stands higher than under grip +/// strips; one level edge rule lies in the middle of the room between the two groups, short of the column's sides, and +/// none over the first group; a drag on a group's first icon moves the group, on its next icon only that panel. +#[trial] +fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { + let (gripped, gripped_id) = separated(IconGroupSeparator::Grip); + let gripped_first = gripped.part_rect(gripped_id, CELL.at(0)).expect("the first icon under grips"); + let (mut fixture, id) = separated(IconGroupSeparator::Rule); let border = StyleCx::with_root(fixture.ctx(), |cx| cx.tokens.color.line.border); let shapes = fixture.frame_shapes(); let level: Vec<(Pos2, Pos2, egui::Color32)> = shapes @@ -696,20 +705,25 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { }) .collect(); for group in [0, 1] { - let strip = fixture.part_rect(id, GRIP.at(group)).expect("each group keeps its grip"); - assert!(grip_ticks(&shapes, strip).is_none(), "group {group}: the strip shows no marks"); + assert!(fixture.part_rect(id, GRIP.at(group)).is_none(), "group {group} has no grip strip"); } - let first = fixture.part_rect(id, GRIP.at(0)).expect("the first group's grip"); - assert!(!level.iter().any(|(a, _, _)| first.y_range().contains(a.y)), "no rule over the first group: {level:?}"); - let (last, next) = ( - fixture.part_rect(id, CELL.at(1)).expect("the first group's last icon"), - fixture.part_rect(id, CELL.at(2)).expect("the second group's icon"), - ); + let cell = |at: u64| fixture.part_rect(id, CELL.at(at)).expect("the icon shows"); + let (first, last, next) = (cell(0), cell(1), cell(2)); + assert!(first.top() < gripped_first.top() - 0.5, "the first icon {first:?} stands higher than under a grip strip {gripped_first:?}"); + assert!(!level.iter().any(|(a, _, _)| a.y < first.bottom()), "no rule over the first group: {level:?}"); let between: Vec<_> = level.iter().filter(|(a, _, _)| a.y > last.bottom() && a.y < next.top()).collect(); let [(a, b, ink)] = between.as_slice() else { panic!("one rule between the groups: {level:?}") }; + let middle = (last.bottom() + next.top()) / 2.0; + assert!((a.y - middle).abs() <= 0.5, "the rule {a:?} lies in the middle of the room from {last:?} to {next:?}"); let (left, right) = (a.x.min(b.x), a.x.max(b.x)); let span = right - left; assert!(left > 0.0 && right < RAIL && span > RAIL - span, "the rule reaches across the column, short of its sides: {a:?} to {b:?}"); let [r, g, bl, al] = border.0; assert_eq!(*ink, egui::Color32::from_rgba_unmultiplied(r, g, bl, al), "the rule is in line.border"); + for (icon, unit) in [(first, DragUnit::Group(1)), (last, DragUnit::Panel(2)), (next, DragUnit::Group(3))] { + fixture.drag_hold_at(icon.center(), Vec2::new(RAIL * 2.0, 0.0)); + let dragged = drag::active::>(fixture.ctx()).map(|drag| drag.unit.clone()); + assert_eq!(dragged, Some(unit.clone()), "a drag on the icon {icon:?} moves {unit:?}"); + fixture.release_at(icon.center() + Vec2::new(RAIL * 2.0, 0.0)).settle(); + } }