diff --git a/crates/ui-canvas/src/canvas_controls/task_bar.rs b/crates/ui-canvas/src/canvas_controls/task_bar.rs index d3fa82722b..10bc17e55e 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar.rs @@ -9,8 +9,8 @@ use crate::buttons::IconButton; use crate::canvas::canvas_space; use crate::contract::overlay::{Anchor, Place, PlacementChange, PlacementKind}; use crate::contract::{ - Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, Inner, Mount, NoValue, Outcome, Overlay, Pad, - PopupKind, Props as _, Role, Show as _, ShowContainer as _, Sizing, Trigger, + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, Inner, Mount, NoValue, Outcome, Overlay, Pad, PopupKind, + Props as _, Role, Show as _, ShowContainer as _, Sizing, Trigger, }; use crate::display::Icon; use crate::menu::{Menu, MenuItem}; @@ -169,10 +169,13 @@ impl<'a> TaskBar<'a> { _ => TaskBarPlace::default(), }; let hang = shows.then(|| hang_rect(bounds, env.tokens.space.gap.section)); - let layer = TaskBarLayer::new(label, words.task_bar_move.clone(), layer_overlay(&held, hang, area), shows); + let layer = TaskBarLayer::new(label, layer_overlay(&held, hang, area), shows); let mut menu = MoreMenu { words: Arc::clone(&words), placed: false, pick: None }; + let grip = words.task_bar_move.clone(); let mut shown = layer.show(ui, |ui, _| { - Bar::new(Label::Empty, BarKind::Tool).show(ui, |ui, _| { + // The bar is the one surface: the grip is its first member, on the members' line inside its padding. + Bar::new(Label::Empty, BarKind::Tool).surface(SurfaceKind::Floating).show(ui, |ui, _| { + let _ = Icon::new(IconSpec::svg(IconId::new("grip"))).label(grip.clone()).show(ui); menu.placed = false; let inner = body(ui, &mut TaskBarCx { menu: &mut menu }); menu.place(ui); @@ -265,8 +268,9 @@ impl Outcome for TaskBarLayerOutput { } } -/// The task bar's layer: a floating surface whose line starts with the grip and holds the bar. The move band lies -/// under the whole line, so the grip and every free point between the members move the layer. +/// The task bar's layer: it holds the bar, which paints the one floating surface and starts with the grip. The layer +/// paints nothing of its own, so the bar reads as one rounded shape. Its inline header is empty: it is there for its +/// move band, which lies under the whole line, so the grip and every free point between the members move the layer. #[derive(crate::contract::Component)] #[component(container, unregistered)] struct TaskBarLayer { @@ -274,21 +278,19 @@ struct TaskBarLayer { common: Common, #[container] props: ContainerProps, - grip: Label, /// Open while the bar shows; the caller shows the bar again each pass it wants it. open: Bind<'static, bool>, moved: Option, } impl TaskBarLayer { - fn new(label: Label, grip: Label, overlay: Overlay, open: bool) -> Self { + fn new(label: Label, overlay: Overlay, open: bool) -> Self { let props = ContainerProps::new() .mount(Mount::Layer(overlay)) - .surface(SurfaceKind::Floating) .pad(Pad::None) .sizing(Sizing::Content) .header(HeaderRegion::new().band(DragBand::Move).inline(true)); - TaskBarLayer { common: Common::new(), props, grip, open: Bind::given(open), moved: None }.label(label).id_salt("task-bar") + TaskBarLayer { common: Common::new(), props, open: Bind::given(open), moved: None }.label(label).id_salt("task-bar") } } @@ -317,11 +319,6 @@ impl Container for TaskBarLayer { Some(self.open.reborrow()) } - /// The grip glyph, named for the move it offers. - fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { - let _ = Icon::new(IconSpec::svg(IconId::new("grip"))).label(self.grip.clone()).show(ui); - } - fn placement_changed(&mut self, change: &PlacementChange) { if change.kind == PlacementKind::Move { self.moved = Some(change.rect); 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 3134e526ad..3ac328fb6c 100644 --- a/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/tests/it/canvas_controls/task_bar.rs @@ -134,3 +134,34 @@ fn the_task_bar_follows_its_anchor_until_moved_and_stays_inside_the_area() { let far = seen(&scene); assert!(inside_area(&far), "a place far outside comes back inside {:?}: {:?}", far.area, far.rect); } + +/// The grip is one of the bar's members: it sits on the members' line, centred with them, inside the bar's padding, +/// and a drag on it still moves the bar. +#[trial] +fn the_grip_sits_on_the_members_line() { + let scene = Rc::new(RefCell::new(Scene { + anchor: frame(DocVec::ZERO), + place: TaskBarPlace::default(), + bounds: Rect::NOTHING, + area: Rect::NOTHING, + rect: Rect::NOTHING, + })); + let mut fixture = fixture(&scene); + fixture.settle(); + let bar = seen(&scene).rect; + let grip = fixture.by_label("Move bar").expect("the grip is named"); + let done = fixture.by_label("Done").expect("the bar shows its member"); + assert!( + (grip.center().y - done.center().y).abs() < SLACK, + "the grip is centred on the members' line: grip {:?}, member {:?}", + grip.rect, + done.rect + ); + assert!(grip.rect.top() > bar.top() + SLACK, "the grip keeps the bar's padding above it: grip {:?}, bar {bar:?}", grip.rect); + assert!(grip.rect.left() > bar.left() + SLACK, "the grip keeps the bar's padding before it: grip {:?}, bar {bar:?}", grip.rect); + + let by = Vec2::new(-80.0, 40.0); + fixture.drag(&grip, by).settle(); + let dropped = seen(&scene); + assert!((dropped.rect.min - (bar.min + by)).length() < 2.0 * SLACK, "a drag on the grip moves the bar: {:?}", dropped.rect); +} diff --git a/crates/ui-widgets/src/bars/bar.rs b/crates/ui-widgets/src/bars/bar.rs index adf21fe70e..7cecbb943b 100644 --- a/crates/ui-widgets/src/bars/bar.rs +++ b/crates/ui-widgets/src/bars/bar.rs @@ -152,6 +152,14 @@ impl<'a> Bar<'a> { self } + /// Paints `kind` behind the bar instead of the chrome: a bar that floats on its own, as a canvas's task bar does, + /// is a floating surface with its corners and shadow. + #[must_use] + pub fn surface(mut self, kind: SurfaceKind) -> Self { + self.props = self.props.surface(kind); + self + } + /// Ends the bar with a cancel and a commit button named `cancel` and `commit`. They run `BarCommands::Cancel` /// and `BarCommands::Commit`, so their tooltips carry the chords the registry binds. #[must_use]