From 6d972e35ed16d4b114e333fa3a7cf08c554afe1e Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 03:59:55 +0000 Subject: [PATCH] Rails: ToolRail lays out the columns its width holds with a measure and dock grid; PanelRail and the CanvasPanel rail removed --- .../ui-contract/src/contract/level_table.rs | 1 - crates/ui-contract/src/style/cx.rs | 2 +- crates/ui-contract/src/testing/mod.rs | 2 +- crates/ui-contract/src/testing/stage.rs | 16 - crates/ui-panels/src/rails/drawer.rs | 17 +- crates/ui-panels/src/rails/mod.rs | 6 +- crates/ui-panels/src/rails/panel_rail.rs | 156 --------- .../ui-panels/src/rails/panel_rail/stories.rs | 14 - .../ui-panels/src/rails/panel_rail/trials.rs | 142 --------- crates/ui-panels/src/rails/tool.rs | 295 +++++++++--------- crates/ui-panels/src/rails/tool/stories.rs | 22 +- crates/ui-panels/src/rails/tool/trials.rs | 149 +++++++++ crates/ui-panels/src/rails/words.rs | 1 - crates/ui-panels/tests/it/rails/drawer.rs | 16 +- crates/ui-shell/src/shell/canvas_shell.rs | 49 +-- .../src/shell/canvas_shell/stories.rs | 8 +- .../ui-shell/tests/it/shell/canvas_panel.rs | 25 +- design-lint.toml | 2 +- design/exceptions/craft-ui-panels/rails.toml | 4 +- docs/components-index.md | 5 +- docs/contract-api.md | 1 - docs/craft-framework.md | 4 +- .../api-map/app-shell-and-title-bar.toml | 6 +- migration/api-map/rails.toml | 60 ++-- 24 files changed, 380 insertions(+), 623 deletions(-) delete mode 100644 crates/ui-panels/src/rails/panel_rail.rs delete mode 100644 crates/ui-panels/src/rails/panel_rail/stories.rs delete mode 100644 crates/ui-panels/src/rails/panel_rail/trials.rs create mode 100644 crates/ui-panels/src/rails/tool/trials.rs diff --git a/crates/ui-contract/src/contract/level_table.rs b/crates/ui-contract/src/contract/level_table.rs index 67e3be6a9..937ddf1d8 100644 --- a/crates/ui-contract/src/contract/level_table.rs +++ b/crates/ui-contract/src/contract/level_table.rs @@ -126,7 +126,6 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[ ("craft_ui", "PaneArea", Own), ("craft_ui", "PaneFrame", Own), ("craft_ui", "Panel", Own), - ("craft_ui", "PanelRail", Chrome), ("craft_ui", "ParamDialog", Own), ("craft_ui", "ParamRows", Own), ("craft_ui", "PasswordDialog", Own), diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index 6de3b7df7..31e4cb647 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -33,7 +33,7 @@ pub enum GlyphRole { Tool, /// A tool rail: `size.icon.lg`, resting in `text.muted` and in the variant's ink under the pointer. ToolRail, - /// A panel rail, or a list row's trailing icon button: the control glyph, resting in `text.faint` and in the variant's ink under the pointer. + /// A list row's trailing icon button: the control glyph, resting in `text.faint` and in the variant's ink under the pointer. PanelRail, } diff --git a/crates/ui-contract/src/testing/mod.rs b/crates/ui-contract/src/testing/mod.rs index 9568a7694..0d4d152ef 100644 --- a/crates/ui-contract/src/testing/mod.rs +++ b/crates/ui-contract/src/testing/mod.rs @@ -46,7 +46,7 @@ pub use crate::runtime::measure::{ pub use craft_ui_macros::{story, trial}; pub use fixture::{Fixture, Impure, Room, Target}; pub use frames::Frames; -pub use stage::{in_edge_pane, room_height, stage, stage_fitting, stage_width}; +pub use stage::{room_height, stage, stage_fitting, stage_width}; #[doc(hidden)] pub use story::{ CollectionKind, Drive, EditKind, Grip, Required, Story, StoryData, StoryOutput, StoryRegistration, StorySnapshot, show_as_only_item, stories, diff --git a/crates/ui-contract/src/testing/stage.rs b/crates/ui-contract/src/testing/stage.rs index 3366309db..89759f814 100644 --- a/crates/ui-contract/src/testing/stage.rs +++ b/crates/ui-contract/src/testing/stage.rs @@ -1,10 +1,7 @@ //! The room a story that fills both axes is shown in. -use crate::contract::PaneEdge; use crate::layout::flow_room; -use crate::primitives::{RectSide, Rule}; use crate::runtime::env::Env; -use crate::style::{RuleKind, rule_look}; use egui::{Rect, Ui}; /// Allocates the stage of a story of a canvas control or a root that fills both axes, and returns its rect: the width @@ -37,16 +34,3 @@ pub fn stage_width(ui: &Ui) -> f32 { let room = if room.is_finite() { room } else { ui.available_width() }; room.clamp(story.width_min, story.width_max) } - -/// Runs `story` as the content of an edge pane at `edge`, as a rail or panel docked at that edge of an app window -/// shows: with the divider the pane draws along its inner edge (`ContainerProps::edge_rule`), here along the edge of -/// what the story drew. -pub fn in_edge_pane(ui: &mut Ui, edge: PaneEdge, story: impl FnOnce(&mut Ui) -> R) -> R { - let shown = ui.scope(story); - let env = Env::of(ui); - if let Some(side) = RectSide::toward_centre(edge, env.direction.is_rtl()) { - let rule = rule_look(&env.tokens, RuleKind::Divider); - ui.painter().extend(Rule::edge(&rule, shown.response.rect, side, ui.ctx().pixels_per_point())); - } - shown.inner -} diff --git a/crates/ui-panels/src/rails/drawer.rs b/crates/ui-panels/src/rails/drawer.rs index cbbdbe695..833ba59a8 100644 --- a/crates/ui-panels/src/rails/drawer.rs +++ b/crates/ui-panels/src/rails/drawer.rs @@ -1,13 +1,13 @@ //! `ToolbarDrawer`: Edit Toolbar's All Tools drawer beside the tool rail, where tools move between the toolbar and the //! drawer. -use super::tool::{DropAt, RailTool, SlotId, ToolDrag, ToolDropped, ToolSlot, canvas_side}; +use super::tool::{DropAt, RailTool, SlotId, ToolDrag, ToolDropped, ToolSlot}; use super::words::RailWords; use crate::buttons::{Button, IconButton}; use crate::contract::overlay::{Anchor, Dismiss, Overlay, Place}; use crate::contract::{ - ActivateOn, Bind, CollectionEvent, Gap, ListDrag, NoValue, Outcome, PaneEdge, Props as _, SelectMode, Show as _, ShowCollection as _, - ShowContainer as _, Sizing, clicked, + ActivateOn, Bind, CollectionEvent, Gap, ListDrag, NoValue, Outcome, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, + Sizing, clicked, }; use crate::display::{Shade, Text}; use crate::layout_components::{Row, Stack}; @@ -19,7 +19,7 @@ use crate::runtime::env::{Env, Label}; use crate::runtime::windows::os_of; use crate::sections::DropAction; use crate::style::TypeRole; -use craft_behavior::overlay::Align; +use craft_behavior::overlay::{Align, Side}; use craft_behavior::{DisplayOrder, IconId, ItemSource, Value}; use egui::{Rect, Response, Ui}; use std::borrow::Cow; @@ -132,9 +132,9 @@ pub struct ToolbarDrawer<'a, T: Value + 'static> { rail: Rect, groups: &'a [DrawerGroup], toolbar: &'a [ToolSlot], - /// The window edge the rail sits at, as given to `ToolRail::edge`: the drawer opens on the rail's canvas side. + /// The side of the rail the drawer opens on, as given to `ToolRail::opens`: the side of the canvas. #[prop] - edge: PaneEdge, + opens: Side, dropped: Option, opener: Option, } @@ -143,7 +143,7 @@ impl<'a, T: Value + 'static> ToolbarDrawer<'a, T> { /// A drawer beside `rail` (the rail's rect), listing `groups`, over a toolbar of `toolbar` slots. `dropped` is the /// drag the rail took in this pass (`ToolRailOutput::dropped`); the drawer turns it into an edit. pub fn new(rail: Rect, groups: &'a [DrawerGroup], toolbar: &'a [ToolSlot], dropped: Option) -> Self { - ToolbarDrawer { rail, groups, toolbar, edge: PaneEdge::Start, dropped, opener: None } + ToolbarDrawer { rail, groups, toolbar, opens: Side::End, dropped, opener: None } } /// The control that opened the drawer, the rail's Edit Toolbar button (`ToolRailOutput::edit_toolbar`): the focus @@ -216,8 +216,7 @@ fn on_toolbar(toolbar: &[ToolSlot], id: &T) -> bool { impl ToolbarDrawer<'_, T> { /// Shows the drawer and reports what the user changed. pub fn show(self, ui: &mut Ui) -> ToolbarDrawerOutput { - let ToolbarDrawer { rail, groups, toolbar, edge, dropped, opener } = self; - let opens = canvas_side(edge); + let ToolbarDrawer { rail, groups, toolbar, opens, dropped, opener } = self; let env = Env::of(ui); let words = env.words::(); let os = os_of(ui.ctx()); diff --git a/crates/ui-panels/src/rails/mod.rs b/crates/ui-panels/src/rails/mod.rs index 680ba8226..ec22c322f 100644 --- a/crates/ui-panels/src/rails/mod.rs +++ b/crates/ui-panels/src/rails/mod.rs @@ -1,10 +1,9 @@ -//! `PanelRail`, `ToolRail`, `FlyoutButton` and `ToolbarDrawer`. +//! `ToolRail`, `FlyoutButton` and `ToolbarDrawer`. mod words; -// The panel rail and the Edit Toolbar drawer. +// The Edit Toolbar drawer. mod drawer; -mod panel_rail; // The tool rail and its flyout button. mod flyout; @@ -12,7 +11,6 @@ mod tool; pub use drawer::{DrawerGroup, ToolbarDrawer, ToolbarDrawerOutput, ToolbarEdit, apply_toolbar_edit, drop_edit}; pub use flyout::{FlyoutButton, FlyoutButtonStyle, FlyoutOutput, SlotEdit}; -pub use panel_rail::{PanelRail, PanelRailOutput, PanelRailRequest, PanelRailStyle}; pub use tool::{ DropAt, LastUsed, RailFooter, RailTool, SlotId, ToolDrag, ToolDropped, ToolRail, ToolRailOutput, ToolRailStyle, ToolSlot, drop_in_slot, remembered, shown_tool, visible_slots, diff --git a/crates/ui-panels/src/rails/panel_rail.rs b/crates/ui-panels/src/rails/panel_rail.rs deleted file mode 100644 index 389be9714..000000000 --- a/crates/ui-panels/src/rails/panel_rail.rs +++ /dev/null @@ -1,156 +0,0 @@ -//! `PanelRail`: the rail of icons that open panels. - -use super::flyout::FlyoutButton; -use super::tool::RailTool; -use super::words::RailWords; -use crate::contract::{ - Access, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, NoValue, Outcome, Pad, Props as _, Role, Scroll, - Show as _, ShowContainer as _, Sizing, WordSetCx as _, -}; -use crate::runtime::access::Name; -use crate::runtime::commands; -use crate::runtime::env::Label; -use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind}; -use craft_behavior::{Metrics, NavShape, Roving, Sense, Value}; -use craft_theme::ControlSize; -use egui::{Response, Ui}; - -#[cfg(feature = "testing")] -pub(super) mod stories; -#[cfg(feature = "testing")] -mod trials; - -/// The style of a panel rail: it paints its chrome surface and takes its spacing from the body gap its props name. -#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] -#[non_exhaustive] -pub struct PanelRailStyle { - #[style(metrics)] - metrics: Metrics, -} - -/// What a click on a panel's icon asks the host to do. -#[derive(Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub enum PanelRailRequest

{ - /// Open the panel: its icon was clicked while the panel was closed. - Open(P), - /// Close the panel: its icon was clicked while the panel was open. - Close(P), -} - -/// What a panel rail reports. -#[derive(Debug)] -#[non_exhaustive] -pub struct PanelRailOutput

{ - /// The rail's response. - pub response: Response, - /// The panel the user asked to open or close this pass. Its command has run. - pub request: Option>, - /// Each icon's response, in order, so the host can hang a context menu on an icon or start a dock drag from it. - /// The rail does neither. - pub items: Vec<(P, Response)>, -} - -impl Outcome for PanelRailOutput

{ - type Value = NoValue; - - fn response(&self) -> &Response { - &self.response - } -} - -type FooterFn<'a> = Box; - -/// The rail of icons that open panels, as a side panel at one edge of the window; the pane it sits in draws the rule -/// along the edge that faces the canvas. A panel is a toggle command: its -/// label, icon, chord and enabled state come from the command, the icon shows the on look while the command is -/// checked (the panel is open), and the command's `marked` state and `hint` mark a closed panel that has content -/// to show. A click runs the command and reports the request that matches the panel's state. The icons are one -/// roving group: Up and Down move between them, Enter and Space toggle. The host's footer stays in view under the -/// icons, which scroll when the window is short. -#[derive(crate::contract::Component, crate::contract::Props)] -#[component(container, probe(PanelRail<'static, u8>))] -pub struct PanelRail<'a, P: Value + 'static> { - #[common] - common: Common, - #[container] - props: ContainerProps, - panels: &'a [RailTool

], - footer: Option>, -} - -impl<'a, P: Value + 'static> PanelRail<'a, P> { - /// A rail named `label` of `panels`, each a panel key with the toggle command that opens and closes it. - pub fn new(label: impl Into

]) -> Self { - let props = ContainerProps::new() - .surface(SurfaceKind::Chrome) - .pad(Pad::Control) - .sizing(Sizing::Content) - .layout(BodyLayout::stack()) - .body_gap(Gap::Tight) - .child_size(ControlSize::Md) - .child_glyphs(GlyphRole::PanelRail) - .roving(Roving::new(NavShape::Flat)) - .scroll(Scroll::vertical()) - .footer(FooterRegion::new()); - PanelRail { common: Common::new(), props, panels, footer: None }.label(label) - } - - /// Shows the rail. `footer` draws under the last icon; it stays in view when the window is short. - pub fn show_rail(mut self, ui: &mut Ui, footer: impl FnMut(&mut Ui) + 'a) -> PanelRailOutput

{ - self.footer = Some(Box::new(footer)); - let panels = self.panels; - let mut request = None; - let mut items = Vec::new(); - let shown = self.show(ui, |ui, _| { - items.clear(); - let ctx = ui.ctx().clone(); - for (at, panel) in panels.iter().enumerate() { - let open = commands::resolve(&ctx, panel.command.clone()).checked.unwrap_or(false); - let button = FlyoutButton::new(std::slice::from_ref(panel), &panel.id).selected(open).id_salt(("panel", at)).show(ui); - if button.select.is_some() { - request = Some(if open { PanelRailRequest::Close(panel.id.clone()) } else { PanelRailRequest::Open(panel.id.clone()) }); - } - items.push((panel.id.clone(), button.response)); - } - }); - PanelRailOutput { request, items, ..shown.output } - } -} - -impl Component for PanelRail<'_, P> { - const ROLE: Role = Role::TOOLBAR; - const PARTS: bool = false; - const STOPS: bool = false; - const OVERLAYS: bool = false; - type Style = PanelRailStyle; - type Output = PanelRailOutput

; - - fn style(_: &StyleCx<'_>, _: PanelRailStyleKey

) -> PanelRailStyle { - PanelRailStyle::default() - } - - fn sense(&self) -> Sense { - Sense::empty() - } - - /// A rail the caller did not label is named by the words of the family. - fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) { - if cx.resolved.label.is_empty() { - access.name(Name::Text(cx.words::().panels.as_str().to_owned())); - } - } - - fn finish(self, cx: Cx<'_, Self>) -> PanelRailOutput

{ - PanelRailOutput { response: cx.response.clone(), request: None, items: Vec::new() } - } -} - -impl Container for PanelRail<'_, P> { - /// The host's footer. - fn footer(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { - if let Some(footer) = &mut self.footer { - footer(ui); - } - } -} diff --git a/crates/ui-panels/src/rails/panel_rail/stories.rs b/crates/ui-panels/src/rails/panel_rail/stories.rs deleted file mode 100644 index 4b771b2d8..000000000 --- a/crates/ui-panels/src/rails/panel_rail/stories.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Stories of `PanelRail`. - -use super::PanelRail; -use crate::contract::PaneEdge; -use crate::rails::tool::stories::tools; -use crate::testing::{Drive, StoryData, StoryOutput, in_edge_pane, story}; -use egui::Ui; - -#[story(PanelRail<'static, u8>, covers = [Default], drive = Drive::Never)] -fn panel_rail(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - let panels = tools(&[0, 1, 2, 3]); - // Docked at the window's end edge, as an app shows it: its divider runs along the canvas side. - in_edge_pane(ui, PaneEdge::End, |ui| PanelRail::new("Panels", &panels).show_rail(ui, |_| {})).into() -} diff --git a/crates/ui-panels/src/rails/panel_rail/trials.rs b/crates/ui-panels/src/rails/panel_rail/trials.rs deleted file mode 100644 index a5ab95e92..000000000 --- a/crates/ui-panels/src/rails/panel_rail/trials.rs +++ /dev/null @@ -1,142 +0,0 @@ -//! Trials of `PanelRail`: a short window, the content mark and the icons' responses. -#![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")] - -use super::PanelRail; -use crate::buttons::Button; -use crate::contract::Show as _; -use crate::rails::tool::stories::{StoryTools, tools}; -use crate::runtime::commands::CommandState; -use crate::testing::pointer::{moved, wheel}; -use crate::testing::relations::{above, centred_across, grows_with, on_one_line}; -use crate::testing::{Fixture, trial}; -use egui::{Rect, Shape, Vec2}; -use std::cell::Cell; -use std::rc::Rc; - -/// The bounds of the node labelled `label`. -fn rect(fixture: &Fixture, label: &str) -> Rect { - fixture.by_label(label).unwrap_or_else(|| panic!("{label} is shown")).rect -} - -/// When the window is too short for every icon, the footer stays in view at the bottom and the icons scroll in the -/// room above it, down to a room smaller than one scroll region's usual least height. -#[trial] -fn in_a_short_window_the_icons_scroll_above_the_footer_that_stays_in_view() { - for height in [160.0, 100.0] { - let mut fixture = Fixture::new(|ui| { - let panels = tools(&[0, 1, 2, 3, 4]); - PanelRail::new("Panels", &panels).show_rail(ui, |ui| { - Button::new("Foot").show(ui); - }); - }); - fixture.room(Vec2::new(48.0, height)).settle(); - let foot = rect(&fixture, "Foot"); - assert!(foot.bottom() <= height, "{height}: the footer is in the room: {foot:?}"); - let first = rect(&fixture, "Move"); - assert!(first.top() < foot.top(), "{height}: the first icon is above the footer: {first:?}"); - assert!(rect(&fixture, "Clone Stamp").bottom() > foot.top(), "{height}: the last icon starts out of view"); - - fixture.frame(vec![moved(first.center())]); - for _ in 0..10 { - fixture.frame(vec![wheel(-120.0)]); - } - fixture.settle(); - let last = rect(&fixture, "Clone Stamp"); - assert!(grows_with(first.top(), last.top()), "{height}: the last icon is in view after scrolling: {last:?}"); - assert!(above(last, foot), "{height}: the last icon is above the footer after scrolling: {last:?}"); - assert_eq!(rect(&fixture, "Foot"), foot, "{height}: the footer stays put"); - } -} - -/// The dots painted inside the Move icon while its panel's command is marked and `open` or closed, and how many item -/// responses the rail reported. -fn marked_move(open: bool) -> (usize, usize) { - let items = Rc::new(Cell::new(0)); - let reported = Rc::clone(&items); - let mut fixture = Fixture::new(move |ui| { - let panels = tools(&[0, 1, 2]); - let out = PanelRail::new("Panels", &panels).show_rail(ui, |_| {}); - reported.set(out.items.len()); - }); - fixture.command_state(StoryTools::Move, CommandState::new().marked(true).checked(open)).room(Vec2::new(48.0, 200.0)).settle(); - let icon = rect(&fixture, "Move"); - let dots = fixture.frame_shapes().iter().filter(|shape| matches!(shape, Shape::Circle(dot) if icon.contains(dot.center))).count(); - (dots, items.get()) -} - -/// A marked panel's icon shows the mark while the panel is closed, not while it is open, and the rail reports one -/// response per icon for the host's menus and drags. -#[trial] -fn a_marked_panel_icon_shows_its_mark_only_while_the_panel_is_closed_and_each_icon_reports_its_response() { - let (closed, items) = marked_move(false); - let (open, _) = marked_move(true); - assert!(closed > open, "the mark shows while the panel is closed ({closed}) and not while open ({open})"); - assert_eq!(items, 3, "one response per icon"); -} - -/// The rails set the glyph role of their buttons: the tool rail's icons are larger than a lone icon button's and rest -/// in a quieter ink than they show under the pointer; the panel rail's keep the lone button's side and rest quieter -/// than it. -#[trial] -fn the_rails_show_their_buttons_icons_in_their_glyph_roles() { - use crate::buttons::IconButton; - use crate::contract::Props as _; - use crate::rails::{LastUsed, ToolRail, ToolSlot}; - use craft_behavior::IconId; - let glyphs = |rail: Option| { - let mut fixture = Fixture::new(move |ui| { - let panels = tools(&[0, 1]); - match rail { - Some(true) => { - let slots = vec![ToolSlot::new(0, panels.clone())]; - ToolRail::new("Tools", &slots, &0, &LastUsed::default()).show_rail(ui, |_, _| {}); - } - Some(false) => { - PanelRail::new("Panels", &panels).show_rail(ui, |_| {}); - } - None => { - IconButton::new(IconId::new("move")).label("Alone").show(ui); - } - } - }); - fixture.settle(); - let seen = fixture.styles_of(std::any::type_name::>()); - let glyph = seen.first().and_then(|seen| seen.looks.icons.first().cloned()); - glyph.unwrap_or_else(|| panic!("an icon button showed ({rail:?})")) - }; - let (alone, tool, panel) = (glyphs(None), glyphs(Some(true)), glyphs(Some(false))); - assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side); - assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer"); - assert_eq!(panel.side, alone.side, "a panel rail icon keeps the control glyph"); - assert!(panel.color.off.rest != alone.color.off.rest, "a panel rail icon rests quieter than a lone one"); -} - -/// A tool rail is as wide as its columns and centres its buttons across them, so no button reaches past the rail's -/// edge; its two header toggles share one line inside it. -#[trial] -fn a_tool_rail_centres_its_buttons_in_its_columns_and_keeps_its_toggles_on_one_line() { - use crate::rails::{LastUsed, ToolRail, ToolSlot}; - use std::num::NonZeroU8; - for columns in [1_u8, 2] { - let mut fixture = Fixture::new(move |ui| { - let slots = vec![ToolSlot::new(0, tools(&[0])), ToolSlot::new(1, tools(&[1])), ToolSlot::new(2, tools(&[3]))]; - ToolRail::new("Tools", &slots, &0, &LastUsed::default()) - .columns(NonZeroU8::new(columns).unwrap_or(NonZeroU8::MIN)) - .column_toggle("Toolbar") - .side_toggle("Move Toolbar") - .show_rail(ui, |_, _| {}); - }); - fixture.settle(); - let rail = rect(&fixture, "Tools"); - for label in ["Move", "Brush", "Eraser", "Toolbar", "Move Toolbar"] { - let shown = rect(&fixture, label); - assert!(rail.contains_rect(shown), "{columns} columns: {label} lies inside the rail: {shown:?} in {rail:?}"); - } - let (first, last) = (rect(&fixture, "Move"), rect(&fixture, if columns == 1 { "Move" } else { "Brush" })); - let grid = first.union(last); - assert!(centred_across(grid, rail), "{columns} columns: the buttons are centred: {grid:?} in {rail:?}"); - let (toggle, side) = (rect(&fixture, "Toolbar"), rect(&fixture, "Move Toolbar")); - assert!(on_one_line(toggle, side), "the toggles share a line: {toggle:?} and {side:?}"); - assert!(above(toggle, first), "the toggles are above the buttons"); - } -} diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 9ee16dba4..930031881 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -1,29 +1,32 @@ -//! `ToolRail`: the rail of tool slots, with hidden tools, the last-used tool per slot and one or two columns. +//! `ToolRail`: the rail of tool slots, with hidden tools, the last-used tool per slot and as many columns as its width +//! holds. use super::flyout::{FlyoutButton, SlotEdit}; use super::words::RailWords; use crate::buttons::IconButton; use crate::contract::{ - Access, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, HeaderRegion, LeastWidth, NoValue, Outcome, Pad, PadEdges, PaneEdge, - Props as _, Role, Scroll, Show as _, ShowContainer as _, Sizing, WordSetCx as _, clicked, + Access, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, NoValue, Outcome, Pad, Props as _, Role, Scroll, Show as _, + ShowContainer as _, Sizing, WordSetCx as _, }; use crate::contract::{BodyCx, BodyLayout}; +use crate::docking::DockGrid; use crate::layout::RowAlign; use crate::layout_components::{Row, Stack}; use crate::runtime::access::Name; use crate::runtime::commands::Commands as _; -use crate::runtime::env::{Env, Label}; +use crate::runtime::env::Label; use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind}; use craft_behavior::overlay::Side; -use craft_behavior::{IconId, Metrics, NavShape, Roving, Sense, Value}; +use craft_behavior::{IconId, Metrics, NavShape, Proposal, Roving, Sense, Value}; use craft_theme::ControlSize; -use egui::{Response, Ui}; -use std::num::NonZeroU8; +use egui::{Response, Ui, Vec2}; mod data; mod drag; #[cfg(feature = "testing")] pub(super) mod stories; +#[cfg(feature = "testing")] +mod trials; use data::row_groups; pub use data::{LastUsed, RailTool, SlotId, ToolSlot, remembered, shown_tool, visible_slots}; @@ -34,16 +37,10 @@ pub use drag::{DropAt, ToolDrag, ToolDropped, drop_in_slot}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct RailFooter { - /// The rail's columns: with two, the host lays its two mode buttons side by side. + /// The rail's columns: with more than one, the host lays its buttons side by side. pub columns: usize, } -/// Whether the column toggle points to the right of the screen: widening (from one column) points away from the -/// rail's edge, towards the canvas; narrowing points back to the edge. -fn column_toggle_points_right(columns: usize, at_left: bool) -> bool { - (columns == 1) == at_left -} - /// The style of a tool rail: it paints its chrome surface and takes its spacing from the body gap its props name. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] #[non_exhaustive] @@ -63,10 +60,6 @@ pub struct ToolRailOutput { pub select: Option, /// The shown tool of a slot that was double clicked; the host decides what that means. pub double_clicked: Option, - /// The column toggle was clicked; the host flips its column count. - pub toggle_columns: bool, - /// The side toggle was clicked; the host moves the rail to the other edge. - pub toggle_side: bool, /// The Edit Toolbar button's response while the rail shows it: a click on it opens the drawer, and the drawer /// takes it as its opener ([`ToolbarDrawer::opened_by`](crate::rails::ToolbarDrawer::opened_by)). pub edit_toolbar: Option, @@ -103,15 +96,16 @@ impl Default for Collected { type FooterFn<'a> = Box; -/// The rail of tool slots, as a side panel at one edge of the window: one `FlyoutButton` per visible slot showing the -/// slot's shown tool, the slot with the current tool toggled on. A click selects the shown tool, a row of the flyout -/// selects that tool. With two columns the slots fill rows in reading order. Each column is `size.rail.width` wide, -/// the width of the shell's tools slot per column, and the buttons sit centred across the columns with the control -/// padding above and below. A slot that ends a group leaves `space.gap.inline` after its row; slots within a group sit -/// `space.gap.tight` apart. The column toggle and the side toggle share the header's one line at the small control -/// size; the Edit Toolbar button follows the last slot; the host's footer stays in view under the slots, which scroll -/// when the window is short, and its buttons show the rail's glyphs. The buttons are one roving group: arrow keys move between them by the grid. While the toolbar is -/// edited the buttons are dragged and take drops, and report the drop in the output. +/// The rail of tool slots, laid out in a grid of columns: one `FlyoutButton` per visible slot showing the slot's shown +/// tool, the slot with the current tool toggled on. A click selects the shown tool, a row of the flyout selects that +/// tool. The rail takes as many columns as the width it gets holds, the most whole columns that fit +/// ([`dock_grid`](ToolRail::dock_grid)): it is `first` wide at one column and `step` wider for each further column, +/// and the slots fill the rows in reading order. The control padding surrounds the buttons; a slot that ends a group +/// leaves `space.gap.inline` after its row; slots within a group sit `space.gap.tight` apart. The Edit Toolbar button +/// follows the last slot; the host's footer stays in view under the slots, which scroll when the room is short, and its +/// buttons show the rail's glyphs. The rail is exactly as tall as its rows and footer at the width it gets +/// ([`measure_rail`](ToolRail::measure_rail)). The buttons are one roving group: arrow keys move between them by the +/// grid. While the toolbar is edited the buttons are dragged and take drops, and report the drop in the output. #[derive(crate::contract::Component, crate::contract::Props)] #[component(container, probe(ToolRail<'static, u8>))] pub struct ToolRail<'a, T: Value + 'static> { @@ -122,20 +116,9 @@ pub struct ToolRail<'a, T: Value + 'static> { slots: &'a [ToolSlot], current: &'a T, last_used: &'a LastUsed, - /// One or two columns of slots (more count as two); the host owns the count. + /// The side of the rail its flyouts and drawer open on: the side of the canvas. #[prop] - columns: NonZeroU8, - /// The edge the rail sits at: `PaneEdge::End` for the end edge, any other value for the start edge. The - /// flyouts open towards the canvas and the column toggle points that way. - #[prop] - edge: PaneEdge, - /// Shows the column toggle at the top, named by the label. - #[prop(into)] - column_toggle: Option