diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index d2bbdf1f5c..dcd87f71ee 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -12,7 +12,8 @@ use craft::ui::menu::PanelRow; use craft::ui::popover::Popover; use craft::ui::primitives::IconSpec; use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates}; -use craft::ui::runtime::env::{Label, WordRows, WordsOverride, with_env}; +use craft::ui::runtime::env::{Env, Label, WordRows, WordsOverride, with_env}; +use craft::ui::style::{UiTokens, rgba_color}; use vectorcraft_doc::NodeKind; use vectorcraft_doc::text::TextKind; use vectorcraft_geom::{Point, Rect}; @@ -488,12 +489,14 @@ fn shown_task_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> let has_shape = offer.shape.is_some(); let mut run: Option<(&'static str, serde_json::Value)> = None; let mut show_swatches = false; + let mut layer = None; let shown = TaskBar::new(tl!("Contextual Task Bar"), &offer.anchor, Bind::bound(&mut local)) .grip(TaskBarGrip::Bar) .member_gap(Gap::Item) .hang_gap(TaskBarHang::ClearOfHandles) .more_rows(more_rows(&offer)) .show(ui, space.view.rect, |ui, _| { + layer = Some((ui.layer_id(), ui.opacity())); for (label, icon, cmd, params) in &offer.actions { if *cmd == TASK_BAR_FIDELITY { // The Smooth tool's Fidelity, labeled, sets the tool's option once a typed or stepped value is @@ -567,6 +570,9 @@ fn shown_task_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> } }); let (rect, hide) = (shown.output.rect, shown.output.hide); + if let Some((layer, opacity)) = layer { + accent_outline(ui, layer, opacity, rect); + } if local != before { app.ui.task_bar_place.set(key, local); } @@ -599,6 +605,23 @@ fn shown_task_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> Some(rect) } +/// Outlines the Contextual Task Bar at `rect` on its `layer` in the accent border color, on the corners of the floating +/// surface the bar paints and at its rect rounded to pixels, at the `opacity` the bar's members paint at while the bar +/// fades in or out. +/// +/// Temporary: craft-libs#4892 adds `TaskBar::edge(BarEdge::Accent)`, which draws this outline in place of the +/// surface's own border. Delete this function and set that edge on the bar once the craft-libs pin includes it. +fn accent_outline(ui: &Ui, layer: egui::LayerId, opacity: f32, rect: egui::Rect) { + let env = Env::of(ui); + let tokens = env.tokens.tokens(); + let stroke = egui::Stroke::new(tokens.stroke.thin, rgba_color(tokens.color.accent.border)); + let corners = UiTokens::corner(tokens.shape.radius.window); + let mut painter = ui.ctx().layer_painter(layer); + painter.set_opacity(opacity); + let rect = egui::emath::GuiRounding::round_to_pixels(rect, painter.pixels_per_point()); + painter.rect_stroke(rect, corners, stroke, egui::StrokeKind::Inside); +} + /// The controls the Contextual Task Bar shows after its actions: the Fill and Stroke chips, /// Recolor Artwork, and Lock or a basic shape's Shape Properties. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/ui-egui/src/tests/taskbar.rs b/crates/ui-egui/src/tests/taskbar.rs index 42b27f59ac..da78e247f2 100644 --- a/crates/ui-egui/src/tests/taskbar.rs +++ b/crates/ui-egui/src/tests/taskbar.rs @@ -2205,3 +2205,43 @@ fn every_action_the_bar_offers_can_be_turned_off() { assert!(more, "{case}: the bar still shows its More Options"); } } + +/// The bar is outlined in the accent border color on the floating surface's corners, on the same rect where the surface +/// paints its own border. +#[test] +fn the_bar_is_outlined_in_the_accent_on_its_surface() { + use craft::theme::Tokens; + use craft::ui::runtime::env::Env; + use craft::ui::style::{UiTokens, rgba_color}; + + let mut tokens = None; + crate::testing::ui_context().run_ui(Default::default(), |ui| tokens = Some(Tokens::clone(Env::of(ui).tokens.tokens()))).textures_delta.clear(); + let tokens = tokens.expect("the frame ran"); + let accent = rgba_color(tokens.color.accent.border); + let corners = UiTokens::corner(tokens.shape.radius.window); + let mut app = app(); + app.run("tool.select", json!({"tool": "selection"})).unwrap(); + let ids = two_shapes(&mut app); + select(&mut app, &ids); + let (bar, outlines) = on_canvas(&mut app, |rig| { + let bar = rig.target(BAR).expect("the bar shows").rect; + let around = |r: Rect| r.expand(1.0).contains_rect(bar) && bar.expand(1.0).contains_rect(r); + let outlines: Vec<_> = rig + .fx + .frame_shapes() + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Rect(drawn) if drawn.stroke.width > 0.0 && around(drawn.rect) => { + Some((drawn.rect, drawn.stroke.color, drawn.corner_radius)) + } + _ => None, + }) + .collect(); + (bar, outlines) + }); + assert!(corners.nw > 0, "the floating surface has rounded corners: {corners:?}"); + let edged = outlines.iter().find(|o| o.1 == accent).unwrap_or_else(|| panic!("the bar at {bar:?} has an accent outline: {outlines:?}")); + assert_eq!(edged.2, corners, "the accent outline takes the floating surface's corners"); + let surface = outlines.iter().find(|o| o.1 != accent).unwrap_or_else(|| panic!("the surface paints its own border: {outlines:?}")); + assert_eq!(edged.0, surface.0, "the accent outline lies on the surface's own border"); +}