Merge pull request #3105 from davidmann4/fix/16461-toolbar-background

WIP: docked toolbar background fills its column, thinner divider, grip grab cursor (photocraft#16461, #16467)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-23 00:58:28 +01:00
commit a4e08cdaf2
7 files changed
+70 -22

No files matched your search

+12 -2
View File
@@ -20,7 +20,7 @@ use crate::runtime::focus::{self, FocusTarget};
use crate::runtime::memory::sub;
use crate::style::{ComponentStyle, Corners, RuleLook, RuleWidth, StyleColor, StyleCx, SurfaceKind};
use crate::tabs::{Tab, TabKind, TabStrip, TornOff};
use craft_behavior::{DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed};
use craft_behavior::{CursorIcon, CursorPriority, DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed};
use craft_theme::{ControlSize, GripMark, GripShape, Tokens};
use egui::{Id, Pos2, Rect, Response, Ui, Vec2};
use std::borrow::Cow;
@@ -164,10 +164,20 @@ impl<P: Clone + Send + Sync + 'static> Component for GroupGrip<P> {
fn update(&mut self, cx: &mut Cx<'_, Self>) {
self.double = cx.press().double_pressed();
if self.movable && matches!(cx.press().phase, PressPhase::DragStart { .. }) {
let phase = cx.press().phase;
if self.movable && matches!(phase, PressPhase::DragStart { .. }) {
start_group_drag(cx, self.unit.clone(), self.active, None, self.ghost.clone());
self.started = true;
}
// A marked grip is a handle: the grab cursor over it and grabbing while it is held or dragged, as the grips of
// a collapsed column declare (photocraft#16467). A drop target's cursor during the drag still wins.
if self.ticks && self.movable {
if phase.button_down() {
cx.cursor(CursorIcon::Grabbing, CursorPriority::Part);
} else if cx.hit() {
cx.cursor(CursorIcon::Grab, CursorPriority::Part);
}
}
}
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
+3 -2
View File
@@ -40,7 +40,8 @@ pub struct DockSizes {
pub cascade_inset: f32,
/// The size a command floats a panel at when the panel gives none (the float window size).
pub float_size: Vec2,
/// The divider between two docked groups or between a dock and its neighbour (the inline gap).
/// The divider between two docked groups or between a dock and its neighbour (the tight gap: the references'
/// dock dividers are 3 px at 100%).
pub gap: f32,
/// How far a band (edge, seam, column edge, new dock) reaches into a tab strip from its drop line (the least hit
/// size): the rest of the strip joins the group.
@@ -111,7 +112,7 @@ impl DockSizes {
new_dock_band: size.control.md,
cascade_inset: size.window.cascade,
float_size: Vec2::new(size.float.width, size.float.height),
gap: cx.tokens.space.gap.inline,
gap: cx.tokens.space.gap.tight,
strip_reach: size.hit.target,
least_pane: size.pane.least,
strip: size.panel_header,
+27 -2
View File
@@ -2,8 +2,8 @@
use craft_ui::buttons::Button;
use craft_ui::contract::{Show as _, ShowContainer as _};
use craft_ui::docking::{DockGroup, PanelKey, PanelTitle, Titles};
use craft_ui::testing::{Fixture, trial};
use craft_ui::docking::{DockGroup, DragUnit, GroupGrip, PanelKey, PanelTitle, Titles};
use craft_ui::testing::{Fixture, Frames, pointer, trial};
use egui::{Pos2, Rect, Vec2};
use std::cell::Cell;
use std::rc::Rc;
@@ -33,3 +33,28 @@ fn a_minimized_group_runs_no_body() {
assert!(runs > 0 && found, "an expanded group shows its body: {runs} runs, node {found}");
assert_eq!(body(true), (0, false), "a minimized group runs no body and leaves no node");
}
// A toolbar's marked grip is a handle (photocraft#16467): the grab cursor over it and grabbing while it is held, as
// the grips of a collapsed column show. An unmarked band and a grip that does not move keep the plain arrow.
#[trial]
fn a_marked_grip_shows_the_grab_cursor() {
let strip = Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(60.0, 16.0));
for (ticks, movable) in [(true, true), (false, true), (true, false)] {
let mut frames = Frames::new();
let mut show = |ui: &mut egui::Ui| {
GroupGrip::new(DragUnit::Group(1usize), PanelKey::new(1)).ticks(ticks).movable(movable).show_at(ui, strip);
};
frames.frame(vec![], &mut show);
frames.frame(vec![pointer::moved(strip.center())], &mut show);
frames.frame(vec![], &mut show);
let (over, held) = if ticks && movable {
(egui::CursorIcon::Grab, egui::CursorIcon::Grabbing)
} else {
(egui::CursorIcon::Default, egui::CursorIcon::Default)
};
assert_eq!(frames.cursor_icon(), over, "over the grip (ticks {ticks}, movable {movable})");
frames.frame(vec![pointer::press(strip.center())], &mut show);
frames.frame(vec![], &mut show);
assert_eq!(frames.cursor_icon(), held, "the grip held (ticks {ticks}, movable {movable})");
}
}
+5 -6
View File
@@ -1115,13 +1115,12 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
let scene = self.scene;
let spec = |panel: &P| scene.spec(panel);
let cells = column_cells(plan.columns, plan.rect, plan.edge, plan.flow, &scene.sizes, &spec);
for (column, mut cell) in plan.columns.iter().zip(cells) {
for (column, cell) in plan.columns.iter().zip(cells) {
let Some(first) = column.groups.first().and_then(|group| group.panels.first()) else { continue };
// A stepped column is as tall as its bar and content, from the top of the dock; content taller than the
// dock gets the dock's height and scrolls inside. The rest of its slot is the dock's empty room.
if let Some(content) = self.stepped_height(ui, body, column, cell.width(), false) {
cell.max.y = (cell.top() + scene.sizes.bar + content).min(cell.bottom());
}
// A docked column takes the dock's height, a stepped one (a tool rail) too: the references' docked
// toolbar keeps its column's surface down to the dock's foot, with the tools at the top
// (photocraft#16461). Content taller than the dock scrolls inside. Only a floating stepped window is as
// tall as its content.
self.report.placed.push((first.clone(), cell));
let at = ColumnAt { cell, edge: plan.edge, bar: ColumnBar::Own, within: body.rect, open: plan.open.clone() };
self.column(ui, body, column, at);
+16 -6
View File
@@ -4,7 +4,7 @@ use craft_behavior::Axis;
use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace, node_at};
use craft_ui::contract::{Bind, BodyCx, PlainData, Role, Show as _, SizeLimits, Tracked};
use craft_ui::display::Text;
use craft_ui::docking::{DockConfig, DockGrid, DockHeights, DockPanels, GroupSize, PanelSpec, PanelSpecs, group_heights};
use craft_ui::docking::{DockConfig, DockGrid, DockHeights, DockPanels, DockSizes, GroupSize, PanelSpec, PanelSpecs, group_heights};
use craft_ui::patterns::dock::DockArea;
use craft_ui::testing::{Fixture, trial};
use egui::{Pos2, Rect, Ui, Vec2};
@@ -184,16 +184,21 @@ impl DockPanels<u32> for Tools {
}
}
/// A docked stepped column is only as tall as its content, not the dock's height; the double arrow of a column that
/// does not collapse switches it between one and two steps, and is named for the steps it switches to.
/// A docked stepped column takes the dock's height, as the references' docked toolbar keeps its surface down to the
/// dock's foot (photocraft#16461), and the dock's divider beside it is the tight gap, as thin as the references'; the
/// double arrow of a column that does not collapse switches it between one and two steps, and is named for the steps
/// it switches to.
#[trial]
fn a_docked_stepped_column_fits_its_content_and_its_double_arrow_switches_one_and_two_steps() {
fn a_docked_stepped_column_takes_the_docks_height_and_its_double_arrow_switches_one_and_two_steps() {
let dock = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![TOOLS], 0)]).with_steps(1)]);
let root = Node::split(Axis::X, SplitSize::FixedFirst(120.0), dock, Node::tabs(vec![1], 0));
let workspace = Rc::new(RefCell::new(Arc::new(Workspace::new(Layout::new(Some(root), Vec::new())))));
let placed: Rc<RefCell<Vec<(u32, Rect)>>> = Rc::default();
let (held, seen, specs) = (Rc::clone(&workspace), Rc::clone(&placed), Tracked::new(Tools));
let gaps: Rc<RefCell<Option<(f32, f32)>>> = Rc::default();
let (held, seen, specs, gaps_seen) = (Rc::clone(&workspace), Rc::clone(&placed), Tracked::new(Tools), Rc::clone(&gaps));
let mut fixture = Fixture::new(move |ui| {
let tight = craft_ui::runtime::env::Env::of(ui).tokens.space.gap.tight;
*gaps_seen.borrow_mut() = Some((DockSizes::of_scope(ui).gap, tight));
let mut workspace = held.borrow().clone();
let out = DockArea::new("Stepped dock", Bind::bound(&mut workspace), &specs, &mut Tools, DockConfig::default()).show(ui);
*held.borrow_mut() = workspace;
@@ -203,7 +208,12 @@ fn a_docked_stepped_column_fits_its_content_and_its_double_arrow_switches_one_an
let tools = placed.borrow().iter().find(|(panel, _)| *panel == TOOLS).map(|(_, rect)| *rect).expect("the stepped column shows");
let canvas =
fixture.by_role(Role::TAB_PANEL).into_iter().map(|group| group.rect).find(|rect| !tools.contains_rect(*rect)).expect("the canvas shows");
assert!(tools.bottom() < canvas.bottom() - 10.0, "the column ends below its content, above the dock's foot: {tools:?}, canvas {canvas:?}");
assert!(
(tools.bottom() - canvas.bottom()).abs() <= 1.0,
"the column reaches the dock's foot, as the canvas beside it: {tools:?}, canvas {canvas:?}"
);
let (gap, tight) = gaps.borrow().expect("the dock showed");
assert_eq!(gap, tight, "the dock's dividers are the tight gap");
let steps = |workspace: &Workspace<u32>| match &workspace.layout().root {
Some(Node::Split { first, .. }) => match first.as_ref() {
@@ -101,8 +101,8 @@ impl DockPanels<usize> for RailPanels {
}
/// A tool rail the host shows itself has the dock's grip under its column bar, as the references' toolbar: a strip of
/// the theme's upright ticks in its grip ink, above the host's view, which keeps the height it measured at; a
/// drag on the strip moves the rail's group.
/// the theme's upright ticks in its grip ink, above the host's view, which takes the docked column's room down to its
/// foot as the references' docked toolbar does; a drag on the strip moves the rail's group.
#[trial]
fn a_tool_rail_shown_by_its_host_has_a_grip_strip_that_drags_it() {
let seen = Rc::new(Cell::new(None));
@@ -122,7 +122,10 @@ fn a_tool_rail_shown_by_its_host_has_a_grip_strip_that_drags_it() {
let column = columns.borrow().iter().find(|(panel, _)| *panel == RAIL).map(|(_, rect)| *rect).expect("the rail's column shows");
let strip = Rect::from_min_max(egui::pos2(view.left(), view.top() - sizes.grip), egui::pos2(view.right(), view.top()));
assert!(sizes.grip > 0.0 && column.top() < strip.top(), "the strip lies under the column bar: {strip:?} in {column:?}");
assert!((view.height() - RAIL_HEIGHT).abs() < 0.5, "the host's view keeps the height it measured at: {view:?}");
assert!(
(view.bottom() - column.bottom()).abs() < 0.5 && view.height() > RAIL_HEIGHT,
"the host's view reaches the docked column's foot (photocraft#16461): {view:?} in {column:?}"
);
// The strip's ticks: one mesh inside it of the theme's upright marks.
let shapes = fixture.frame_shapes();
+1 -1
View File
@@ -112,7 +112,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
- A column collapsed to icons takes drops as an expanded column does: its edges (a new column beside it, docked only), the seams between its icon groups, the top of the first group and the bottom of the last (a new group above or below), and each icon group's cells (join its tabs). The column's state wins: a panel dropped into a collapsed column shows as an icon, one dropped into an expanded column shows expanded.
- Nothing goes beside a floating window: its column registers no edge bands, and its groups (`DockGroup::in_window`) take no drop on their start and end sides.
- A collapsed column's flyouts open on the side `IconicColumn::opens` names: away from a dock's window edge, and towards the room of the float area for a floating window. A floating window keeps to its edge of the float area: `Floating::edge`, else the one nearer its rect. A move keeps the edge it began with. A collapsed window's move ends at the edge nearer its strip where it was dropped, with the rect that shows the strip there (`WindowColumn::dropped`), and the area records that edge (`Action::MoveFloating`'s `edge`); a unit dragged out of a collapsed column (`start_icon_drag`) floats collapsed the same way, its strip under the pointer (`Target::Float`'s `edge`). Collapsing a floating column and moving an expanded window clear the edge. A column that neither collapses nor has steps shows no double arrow and offers no collapse in its menu (`ColumnArrow::Fixed`).
- A panel that lays its content in a grid (a toolbar) declares it with `PanelSpec::grid` (`DockGrid`: the width at one content column, the width each further column adds, and the most columns; `DockGrid::rail` for a tool rail, sized by the dock). Its column, given steps (`Column::steps`), is a whole number of content columns wide and as tall as the content measures at that width: docked from the top of the dock, content taller than the dock scrolls inside; floating under the title row, at the window's place. A drag of the column's edge, or of a floating window's side, sets the most steps that fit, and a drag of a floating window's left side keeps its right edge, one of its top its bottom edge; a drag of a floating window's top or bottom sets the fewest whose content fits. When the column's panels do not collapse, its double arrow switches between one and two steps (`ColumnArrow::Steps`), named for the count it switches to and pointing the way the column grows or shrinks. A dock side's total width (`DockSizes::resize_side`) leaves a stepped column's width alone.
- A panel that lays its content in a grid (a toolbar) declares it with `PanelSpec::grid` (`DockGrid`: the width at one content column, the width each further column adds, and the most columns; `DockGrid::rail` for a tool rail, sized by the dock). Its column, given steps (`Column::steps`), is a whole number of content columns wide. Docked, it takes the dock's height like any column, its content at the top (the references' docked toolbar keeps its surface down to the dock's foot), and content taller than the dock scrolls inside; floating, it is as tall as the content measures at that width, under the title row, at the window's place. A drag of the column's edge, or of a floating window's side, sets the most steps that fit, and a drag of a floating window's left side keeps its right edge, one of its top its bottom edge; a drag of a floating window's top or bottom sets the fewest whose content fits. When the column's panels do not collapse, its double arrow switches between one and two steps (`ColumnArrow::Steps`), named for the count it switches to and pointing the way the column grows or shrinks. A dock side's total width (`DockSizes::resize_side`) leaves a stepped column's width alone.
- A floating window whose every group is minimized shows its title row and their tab strips, at its rect's place and width (`WindowColumn::minimized`). Its sides resize its width, never its height, and its rect, in the app window and in an OS window's recorded placement, keeps the expanded height, which the window takes back when a group is restored. A window with some groups open keeps its size, and its open groups share the room the strips leave.
- Ctrl or Cmd held at the release floats the drop. A release over the dragged unit's own group leaves it where it is.
- A drag ends without a change when another arrangement replaces the workspace it started on: it records the workspace's generation, which `Workspace::replace` and the `WorkspaceSet` switch and reset change. The dock's own edits keep the generation, so they keep the drag. Every write moves the workspace's revision (`Workspace::revision`), which keys what the area derives.