ui-canvas: TaskBar::hang_gap(TaskBarHang::ClearOfHandles) hangs the bar the handle ring and a section gap from its anchor

This commit is contained in:
bflatastic
2026-11-24 13:06:08 +07:00
parent 0d8d3f9c9a
commit 1a17a4963c
4 changed files with 47 additions and 9 deletions
+1 -1
View File
@@ -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.
@@ -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<Gap>,
/// 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<R>(self, ui: &mut Ui, area: Rect, mut body: impl FnMut(&mut Ui, &mut TaskBarCx<'_>) -> R) -> Inner<TaskBarOutput, R> {
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 {
@@ -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))
}
@@ -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}");
}