diff --git a/crates/ui-canvas/src/canvas_controls/mod.rs b/crates/ui-canvas/src/canvas_controls/mod.rs index dcf80ef45..732817ba2 100644 --- a/crates/ui-canvas/src/canvas_controls/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/mod.rs @@ -27,7 +27,7 @@ pub use line_preview::{LineGuideStyle, StraightLinePreview}; pub use marquee::{Marquee, MarqueeLook, MarqueeShape, MarqueeStyle, Run}; pub use outline::{HoverMask, HoverOutline, HoverShape, OutlineStyle, SelectionOutline, SelectionOutlineLook, path_runs}; pub use pixel_grid::{GridSegment, PixelGrid, PixelGridStyle}; -pub use task_bar::{TaskBar, TaskBarCx, TaskBarDismiss, TaskBarGrip, TaskBarKind, TaskBarOutput, TaskBarPlace}; +pub use task_bar::{TaskBar, TaskBarCx, TaskBarDismiss, TaskBarGrip, TaskBarHang, TaskBarKind, TaskBarOutput, TaskBarPlace}; // End of canvas-controls-b. // Brush overlays. diff --git a/crates/ui-canvas/src/canvas_controls/task_bar.rs b/crates/ui-canvas/src/canvas_controls/task_bar.rs index dc2148c50..669d2136d 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar.rs @@ -68,10 +68,10 @@ impl TaskBarPlace { /// members and a More menu (Hide, Pin, Reset, then the host's rows). One place, pin and Hide setting for Crop and /// Frame. /// -/// - Place: on `side` of the anchor's bounds on screen (below, centred, by default), a section gap away, following the -/// anchor each pass; it flips to the other side when there is no room. Dragged by its grip (any free point of the -/// bar), it keeps its offset from that place while the anchor moves or the bar grows; a press with no drag changes -/// nothing. A moved bar whose offset place would cover the `keep_clear` point shows at its unmoved place and keeps +/// - Place: on `side` of the anchor's bounds on screen (below, centred, by default), a section gap away (or as far as +/// [`hang_gap`](Self::hang_gap) says), following the anchor each pass; it flips to the other side when there is no +/// room. Dragged by its grip (any free point of the bar), it keeps its offset from that place while the anchor moves +/// or the bar grows; a press with no drag changes nothing. A moved bar whose offset place would cover the `keep_clear` point shows at its unmoved place and keeps /// its offset. Pinned, it stays where it shows. /// - Area: the bar shows inside `area` (the canvas rect): a move stays inside it, and a stored place outside it comes /// back inside, its left and top edges winning where the bar does not fit. Its members continue on a new line when @@ -120,6 +120,9 @@ pub struct TaskBar<'a> { /// apart. #[prop(into)] member_gap: Option, + /// How far from its anchor's bounds a bar hung from document points hangs: a section gap by default. + #[prop] + hang_gap: TaskBarHang, } /// What a bar hangs from: the screen bounds of document points, or the canvas view's top edge, aligned in reading @@ -157,6 +160,17 @@ pub enum TaskBarGrip { Bar, } +/// How far from its anchor's bounds a [`TaskBar`] hangs. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum TaskBarHang { + /// A section gap away. + #[default] + Gap, + /// The handle ring and a section gap away: clear of a selection's handles on that side and their hit area. + ClearOfHandles, +} + /// What an outside press does to a [`TaskBar`]. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] @@ -280,6 +294,7 @@ impl<'a> TaskBar<'a> { compact: false, grip: TaskBarGrip::Icon, member_gap: None, + hang_gap: TaskBarHang::Gap, } } @@ -308,6 +323,7 @@ impl<'a> TaskBar<'a> { compact: false, grip: TaskBarGrip::Icon, member_gap: None, + hang_gap: TaskBarHang::Gap, } } @@ -336,7 +352,7 @@ impl<'a> TaskBar<'a> { /// Shows the bar inside `area`; `body` fills its members. pub fn show(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner { - let TaskBar { label, hang, mut place, rows, kind, side, align, keep_clear, dismiss, compact, grip: grip_look, member_gap } = self; + let TaskBar { label, hang, mut place, rows, kind, side, align, keep_clear, dismiss, compact, grip: grip_look, member_gap, hang_gap } = self; let side = side.unwrap_or(match kind { TaskBarKind::Task | TaskBarKind::Fixed => Side::Below, TaskBarKind::Selection => Side::Above, @@ -354,7 +370,8 @@ impl<'a> TaskBar<'a> { bounds.extend_with(at); bounds }); - let gap = env.tokens.space.gap.section; + let clear = if hang_gap == TaskBarHang::ClearOfHandles { env.tokens.size.handle.ring } else { 0.0 }; + let gap = env.tokens.space.gap.section + clear; // A fixed bar keeps the gap on both sides of its anchor: it opens above when there is no room below. let rect = if kind == TaskBarKind::Fixed { bounds.expand2(Vec2::new(0.0, gap)) } else { hang_rect(bounds, gap, side) }; (room && bounds.is_finite()).then(|| Hung { diff --git a/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs index ccf182780..0f9e0c80d 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs @@ -1,6 +1,6 @@ //! Stories of `TaskBar`. -use super::{TaskBar, TaskBarDismiss, TaskBarGrip, TaskBarPlace}; +use super::{TaskBar, TaskBarDismiss, TaskBarGrip, TaskBarHang, TaskBarPlace}; use crate::buttons::{Button, IconButton}; use crate::canvas::testing::canvas_story::{StoryDocument, on_canvas}; use crate::contract::{Gap, Props as _, Show as _}; @@ -237,3 +237,9 @@ fn bar_grip_dragged(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { fn control_gap(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { configured(ui, data, &turned_frame(), None, |bar| bar.member_gap(Gap::Item)) } + +/// A bar hung clear of the frame's handles: the handle ring and a section gap below it. +#[story(TaskBar<'static>, covers = [], drive = Drive::Never)] +fn clear_of_handles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + configured(ui, data, &turned_frame(), None, |bar| bar.hang_gap(TaskBarHang::ClearOfHandles)) +} diff --git a/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs b/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs index 8cb8ae5fa..6aa85685b 100644 --- a/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs @@ -6,7 +6,7 @@ use craft_behavior::CanvasView; use craft_behavior::kurbo::{Point, Vec2 as DocVec}; use craft_behavior::overlay::{Align, Side}; use craft_ui::buttons::Button; -use craft_ui::canvas_controls::{TaskBar, TaskBarDismiss, TaskBarGrip, TaskBarPlace}; +use craft_ui::canvas_controls::{TaskBar, TaskBarDismiss, TaskBarGrip, TaskBarHang, TaskBarPlace}; use craft_ui::contract::{Bind, Show as _}; use craft_ui::menu::PanelRow; use craft_ui::runtime::commands::{CommandRef, EditCommands}; @@ -554,3 +554,18 @@ fn the_bar_grip_lights_under_the_pointer_and_while_the_bar_moves() { let dropped = fixture.by_label("Move bar").expect("the grip is named"); assert_eq!(grip_ink(&fixture.frame_shapes(), dropped.rect), Some(rest), "the grip is back to rest once dropped and left"); } + +/// A bar hung clear of the handles hangs farther below its anchor than the default, by the handle ring at least. +#[trial] +fn a_bar_clear_of_the_handles_hangs_farther_below_its_anchor() { + let below = |configure: fn(TaskBar<'_>) -> TaskBar<'_>| { + let scene = scene(); + let mut fixture = fixture_with(&scene, configure); + fixture.settle(); + let seen = seen(&scene); + seen.rect.top() - seen.bounds.bottom() + }; + let (default, clear) = (below(|bar| bar), below(|bar| bar.hang_gap(TaskBarHang::ClearOfHandles))); + assert!(default > 0.0, "the bar hangs below its anchor: {default}"); + assert!(clear > default + 2.0 * SLACK, "the bar clear of the handles hangs farther below: {clear} against {default}"); +}