From fe426f9bac7d5593ec9ab56310d3de1430cd9413 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 01:13:07 -0800 Subject: [PATCH] Contextual Task Bar: Bar Actions reads the offered list, coverage test edits type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list of actions and chips the bar offers, stored on every frame, now holds whether each one shows, and More Options › Bar Actions reads it through task_bar_offered while its menu is open. The bar no longer builds a second list for the menu on every frame. The coverage test reads the same accessor, and it adds a case for the Type tool while it edits type, whose bar offers the Fill chip. --- crates/ui-egui/src/canvas.rs | 2 +- crates/ui-egui/src/canvas/task_bar.rs | 20 +++++++++++++++----- crates/ui-egui/src/tests/taskbar.rs | 12 ++++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 4dfcd0f0eb..1ae7fd0aff 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -74,7 +74,7 @@ pub use selection_marks::SelectionMarks; use task_bar::task_bar; pub(crate) use task_bar::{TASK_BAR_ACTIONS, TASK_BAR_CHIPS, is_task_bar_action, read_hidden_task_bar_actions}; #[cfg(test)] -pub(crate) use task_bar::{bar_action_name, chip_paints, images_with_other_art, task_bar_id}; +pub(crate) use task_bar::{bar_action_name, chip_paints, images_with_other_art, task_bar_offered}; pub(crate) use task_bar::{has_colors, task_bar_rect, task_bar_shows_fonts, task_bar_shows_type}; #[cfg(test)] use tool_overlays::{DIAL_RADIUS, HiddenMarks}; diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 9731d42a90..4ae3821b2c 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -3,7 +3,7 @@ use super::{ }; /// The Contextual Task Bar's area. -pub(crate) fn task_bar_id() -> egui::Id { +fn task_bar_id() -> egui::Id { egui::Id::unique("task-bar") } @@ -19,6 +19,14 @@ pub(crate) fn task_bar_shows_fonts(ctx: &egui::Context) -> bool { task_bar_rect(ctx).is_some() && ctx.data(|d| d.get_temp::(task_bar_id().with("fonts")).unwrap_or(false)) } +/// The actions and chips the Contextual Task Bar offered where it was last drawn, before Bar +/// Actions left any out, as More Options › Bar Actions lists them: each one's name, its id in +/// [`TASK_BAR_ACTIONS`] or [`TASK_BAR_CHIPS`] (none: Bar Actions cannot turn it off) and whether it +/// shows. +pub(crate) fn task_bar_offered(ctx: &egui::Context) -> Vec<(&'static str, Option<&'static str>, bool)> { + ctx.data(|d| d.get_temp(task_bar_id().with("offered")).unwrap_or_default()) +} + /// Whether the objects `ids` (or anything inside them) are painted with a colour: a solid colour, /// a gradient's stops or a mesh's points, which Recolor Artwork can change. pub(crate) fn has_colors(doc: &vectorcraft_doc::Document, ids: &[vectorcraft_doc::NodeId]) -> bool { @@ -383,8 +391,9 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) { .collect(); offered.extend(chips.iter().map(|c| (c.label(shape.is_some()), Some(c.id(shape.is_some()))))); let chips: Vec = chips.into_iter().filter(|c| !hidden.contains(c.id(shape.is_some()))).collect(); - let bar_actions: Vec<(&str, &str, bool)> = - offered.iter().filter_map(|&(label, action)| action.map(|a| (label, a, !hidden.contains(a)))).collect(); + // Bar Actions reads this list through task_bar_offered while its menu is open. + let offered: Vec<(&'static str, Option<&'static str>, bool)> = + offered.into_iter().map(|(label, action)| (label, action, action.is_none_or(|a| !hidden.contains(a)))).collect(); ui.ctx().data_mut(|d| d.insert_temp(task_bar_id().with("offered"), offered)); let any_hidden = !hidden.is_empty(); let widths: Vec = items.iter().map(|(label, _, cmd, _)| item_width(ui, label, cmd)).collect(); @@ -519,8 +528,9 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) { // Actions, which shows every action again. ui.menu_button(format!(" {}", tl!("Bar Actions")), |ui| { ui.set_min_width(170.0); - for (label, action, shown) in &bar_actions { - if widgets::menu_item_name(ui, bar_action_name(label), true, *shown) { + for (label, action, shown) in task_bar_offered(ui.ctx()) { + let Some(action) = action else { continue }; + if widgets::menu_item_name(ui, bar_action_name(label), true, shown) { run = Some(("window.taskBar.actions", json!({ "action": action }))); } } diff --git a/crates/ui-egui/src/tests/taskbar.rs b/crates/ui-egui/src/tests/taskbar.rs index 8717c5dc2b..5228831202 100644 --- a/crates/ui-egui/src/tests/taskbar.rs +++ b/crates/ui-egui/src/tests/taskbar.rs @@ -1807,7 +1807,8 @@ fn an_action_turned_off_is_not_listed_in_more_options() { /// Actions, and with all of them turned off the bar shows none of them but still shows, with More /// Options. That covers Connect and Join (both `join`), the actions matched by the tool they switch /// to (`editPath`, `drawPencil`, `smoothToolOptions`), the Smooth tool's Fidelity, Dynamic Text, -/// an Image Trace object's Expand, the Type tool's Fill and the Artboard tool's actions. +/// an Image Trace object's Expand, the Type tool's Fill with type selected and while it edits +/// type, and the Artboard tool's actions. #[test] fn every_action_the_bar_offers_can_be_turned_off() { let dir = crate::tests_folder::Folder::new("ui-taskbar-actions"); @@ -1890,6 +1891,13 @@ fn every_action_the_bar_offers_can_be_turned_off() { }), &["fill"], ), + ( + "the Type tool editing type", + Box::new(|app| { + edited_type(app, "type"); + }), + &["fill"], + ), ( "area type", Box::new(|app| { @@ -1973,7 +1981,7 @@ fn every_action_the_bar_offers_can_be_turned_off() { app.run("tool.select", json!({"tool": "selection"})).unwrap(); setup(&mut app); let (ctx, _) = bar(&mut app); - let offered: Vec<(&'static str, Option<&'static str>)> = ctx.data(|d| d.get_temp(canvas::task_bar_id().with("offered")).unwrap_or_default()); + let offered: Vec<(&str, Option<&str>)> = canvas::task_bar_offered(&ctx).into_iter().map(|(label, action, _)| (label, action)).collect(); assert!(canvas::task_bar_rect(&ctx).is_some() && !offered.is_empty(), "{case}: the bar shows actions"); for (label, action) in &offered { assert!(action.is_some(), "{case}: {label} has no id in Bar Actions");