From 5222fd63e5255eddb6bbeb5d56d96bbeb4dfbc5b Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 22:20:46 +0000 Subject: [PATCH] Dock column and tool rail share the collapse chevrons The dock column bar's collapse control shows the icon set's double chevron, as the tool rail's column toggle does, through one function that names a direction on screen and never mirrors; the dock bar's own chevron painter goes. --- crates/ui-panels/src/collapse.rs | 10 +++++ .../ui-panels/src/docking/dock_column/bar.rs | 38 ++----------------- crates/ui-panels/src/lib.rs | 1 + crates/ui-panels/src/rails/mod.rs | 4 +- crates/ui-panels/src/rails/tool.rs | 14 +++---- 5 files changed, 22 insertions(+), 45 deletions(-) create mode 100644 crates/ui-panels/src/collapse.rs diff --git a/crates/ui-panels/src/collapse.rs b/crates/ui-panels/src/collapse.rs new file mode 100644 index 000000000..67342aa3a --- /dev/null +++ b/crates/ui-panels/src/collapse.rs @@ -0,0 +1,10 @@ +//! The glyph of the controls that collapse and expand a column of panels or tools. + +use crate::primitives::{IconSpec, Mirror}; +use craft_behavior::IconId; + +/// The double chevron of a collapse or expand control, pointing to the right of the screen or to the left. It names a +/// direction on screen, where the column goes, so it never mirrors under right-to-left. +pub(crate) fn chevrons(right: bool) -> IconSpec<'static> { + IconSpec::svg(IconId::new(if right { "chevrons_right" } else { "chevrons_left" })).mirror(Mirror::Never) +} diff --git a/crates/ui-panels/src/docking/dock_column/bar.rs b/crates/ui-panels/src/docking/dock_column/bar.rs index 4cc1f593c..5110047a2 100644 --- a/crates/ui-panels/src/docking/dock_column/bar.rs +++ b/crates/ui-panels/src/docking/dock_column/bar.rs @@ -8,13 +8,12 @@ use crate::contract::{Access, BodyCx, Name, PaintUi, Props as _, Role, Show as _ use crate::docking::group::GroupGrip; use crate::docking::{DockWords, PanelSpec}; use crate::menu::{GroupItem, Menu, MenuWords, PanelMenu, PanelRow}; -use crate::primitives::{Glyph, IconSpec}; use crate::runtime::env::Label; use craft_behavior::PartKey; use craft_behavior::dock::{Column, DockEdge}; use craft_theme::variant::Tone; use craft_theme::{ControlSize, CustomVariant, Emphasis, States, Tokens, Variant, VariantLook}; -use egui::{Color32, Pos2, Rect, Ui}; +use egui::{Rect, Ui}; /// The chevron of a column's bar: a click collapses an expanded column to icons and expands an iconic one. pub(in crate::docking) const CHEVRON: PartKey = PartKey::new("chevron"); @@ -28,14 +27,6 @@ pub(in crate::docking) struct BarRecord { pub(in crate::docking) picked: Option, } -/// A double chevron's arms, as a share of the icon box's side: the glyph the collapse control draws is small beside -/// the bar's other icons. -const ARM: f32 = 0.17; - -/// How far each chevron of the pair reaches along the arrow, and the distance between the two, as shares of an arm. -const REACH: f32 = 0.8; -const PITCH: f32 = 1.4; - /// The look of the collapse control: ghost, with the muted text until the pointer is over it, and no fill under the /// pointer. fn collapse_look(tokens: &Tokens) -> VariantLook { @@ -47,29 +38,6 @@ fn collapse_look(tokens: &Tokens) -> VariantLook { const COLLAPSE: CustomVariant = CustomVariant::new::("craft_ui.dock-collapse", collapse_look); -/// The glyph of a column's collapse control: a double chevron that points where the column goes, towards the window -/// edge when it collapses to icons and away from it when it expands. -struct DoubleChevron { - /// Whether it points to the right of the screen. - right: bool, - /// The stroke width. - width: f32, -} - -impl Glyph for DoubleChevron { - fn paint(&self, painter: &egui::Painter, _: &crate::style::UiTokens, rect: Rect, color: Color32, _: bool) { - let arm = rect.width().min(rect.height()) * ARM; - let flip = if self.right { 1.0 } else { -1.0 }; - let centre = rect.center(); - let stroke = egui::Stroke::new(self.width, color); - for step in [-0.5, 0.5] { - let x = centre.x + flip * arm * PITCH * step; - let points = [(-0.5, -1.0), (0.5, 0.0), (-0.5, 1.0)].map(|(dx, dy)| Pos2::new(x + flip * arm * REACH * dx, centre.y + arm * dy)).to_vec(); - painter.add(egui::Shape::line(points, stroke)); - } - } -} - /// Whether the column's collapse control points to the right of the screen: towards the window edge when it collapses /// to icons and away from it when it expands. fn points_right(edge: DockEdge, expanded: bool, rtl: bool) -> bool { @@ -97,8 +65,8 @@ pub(in crate::docking) fn chevron_name(words: &DockWords, expanded: bool) -> Lab /// Paints the chevron part: a small ghost button with the double chevron pointing where the column goes. pub(in crate::docking) fn paint_chevron(ui: &mut PaintUi<'_>, edge: DockEdge, expanded: bool, rtl: bool, name: Label) { - let chevron = DoubleChevron { right: points_right(edge, expanded, rtl), width: ui.env.tokens.stroke.thin }; - ui.face(CHEVRON, IconButton::new(IconSpec::glyph(&chevron)).size(ControlSize::Sm).variant(Variant::Custom(COLLAPSE)).label(name)); + let chevrons = crate::collapse::chevrons(points_right(edge, expanded, rtl)); + ui.face(CHEVRON, IconButton::new(chevrons).size(ControlSize::Sm).variant(Variant::Custom(COLLAPSE)).label(name)); } /// The chevron's node. diff --git a/crates/ui-panels/src/lib.rs b/crates/ui-panels/src/lib.rs index 519418fa9..e9ff70cc6 100644 --- a/crates/ui-panels/src/lib.rs +++ b/crates/ui-panels/src/lib.rs @@ -23,6 +23,7 @@ pub use craft_ui_widgets::{ #[doc(hidden)] pub mod canvas_data; +mod collapse; pub mod dialog; pub mod docking; pub mod rails; diff --git a/crates/ui-panels/src/rails/mod.rs b/crates/ui-panels/src/rails/mod.rs index dad367362..680ba8226 100644 --- a/crates/ui-panels/src/rails/mod.rs +++ b/crates/ui-panels/src/rails/mod.rs @@ -14,7 +14,7 @@ pub use drawer::{DrawerGroup, ToolbarDrawer, ToolbarDrawerOutput, ToolbarEdit, a 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, column_toggle_icon, - drop_in_slot, remembered, shown_tool, visible_slots, + DropAt, LastUsed, RailFooter, RailTool, SlotId, ToolDrag, ToolDropped, ToolRail, ToolRailOutput, ToolRailStyle, ToolSlot, drop_in_slot, + remembered, shown_tool, visible_slots, }; pub use words::RailWords; diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 6a5ef8d68..d4f75926f 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -36,12 +36,10 @@ pub struct RailFooter { pub columns: usize, } -/// The column toggle's icon. Widening (from one column) points away from the rail's edge, towards the canvas; -/// narrowing points back to the edge. Directional icons mirror in a right-to-left interface, so the icon that draws -/// pointing right there is the left one. -pub fn column_toggle_icon(columns: usize, at_left: bool, rtl: bool) -> &'static str { - let points_right = (columns == 1) == at_left; - if points_right != rtl { "chevrons_right" } else { "chevrons_left" } +/// 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. @@ -294,8 +292,8 @@ impl Container for ToolRail<'_, T> { fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { let Some(label) = self.column_toggle.clone() else { return }; let (columns, rtl) = (self.column_count(), Env::of(ui).direction.is_rtl()); - let icon = column_toggle_icon(columns, !self.at_end() != rtl, rtl); - let toggle = IconButton::new(IconId::new(icon)).id_salt("column-toggle").label(label).show(ui); + let icon = crate::collapse::chevrons(column_toggle_points_right(columns, !self.at_end() != rtl)); + let toggle = IconButton::new(icon).id_salt("column-toggle").label(label).show(ui); self.toggled |= clicked(&toggle); }