mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 00:54:06 +00:00
Contextual Task Bar: record the offered actions as the bar's other probes do
The bar now stores the actions and chips it offers in its egui memory on every frame, as it stores whether it shows the font controls and its size, instead of only in test builds. The list holds each name and id without copying the names, and Bar Actions reads the same list, so the bar builds it once per frame. task_bar.rs has no test-only code again; the coverage test reads the list through task_bar_id.
This commit is contained in:
@@ -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_offered};
|
||||
pub(crate) use task_bar::{bar_action_name, chip_paints, images_with_other_art, task_bar_id};
|
||||
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};
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::{
|
||||
};
|
||||
|
||||
/// The Contextual Task Bar's area.
|
||||
fn task_bar_id() -> egui::Id {
|
||||
pub(crate) fn task_bar_id() -> egui::Id {
|
||||
egui::Id::unique("task-bar")
|
||||
}
|
||||
|
||||
@@ -19,14 +19,6 @@ pub(crate) fn task_bar_shows_fonts(ctx: &egui::Context) -> bool {
|
||||
task_bar_rect(ctx).is_some() && ctx.data(|d| d.get_temp::<bool>(task_bar_id().with("fonts")).unwrap_or(false))
|
||||
}
|
||||
|
||||
/// The actions and chips the Contextual Task Bar offered when it was last drawn, before Bar Actions
|
||||
/// left any out: each one's name and its id in [`TASK_BAR_ACTIONS`] or [`TASK_BAR_CHIPS`] (none:
|
||||
/// Bar Actions cannot turn it off).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn task_bar_offered(ctx: &egui::Context) -> Vec<(String, Option<&'static str>)> {
|
||||
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 {
|
||||
@@ -362,13 +354,12 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
|
||||
let paints = chip_paints(app, ui.ctx());
|
||||
let colored = has_colors(&st.doc, &st.selection.objects);
|
||||
let doc = st.uid;
|
||||
// Every action and chip the bar offers here, with its name, for More Options › Bar Actions;
|
||||
// the ones that are off there are left out of the bar.
|
||||
// Every action and chip the bar offers here, with its name and its id in TASK_BAR_ACTIONS or
|
||||
// TASK_BAR_CHIPS (none: Bar Actions cannot turn it off), for More Options › Bar Actions; the
|
||||
// ones that are off there are left out of the bar.
|
||||
let hidden = &app.ui.task_bar_hidden_actions;
|
||||
#[cfg(test)]
|
||||
let mut probe: Vec<(String, Option<&'static str>)> =
|
||||
items.iter().map(|(label, _, cmd, params)| (label.to_string(), action_id(cmd, params))).collect();
|
||||
let mut offered: Vec<(&str, &'static str)> = items.iter().filter_map(|(label, _, cmd, params)| Some((*label, action_id(cmd, params)?))).collect();
|
||||
let mut offered: Vec<(&'static str, Option<&'static str>)> =
|
||||
items.iter().map(|(label, _, cmd, params)| (*label, action_id(cmd, params))).collect();
|
||||
items.retain(|(_, _, cmd, params)| action_id(cmd, params).is_none_or(|a| !hidden.contains(a)));
|
||||
let bounds = xf.rect.shrink(8.0);
|
||||
// The canvas's width less the frame's margins and stroke.
|
||||
@@ -390,14 +381,11 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
|
||||
.into_iter()
|
||||
.filter_map(|(shown, chip)| shown.then_some(chip))
|
||||
.collect();
|
||||
offered.extend(chips.iter().map(|c| (c.label(shape.is_some()), c.id(shape.is_some()))));
|
||||
#[cfg(test)]
|
||||
{
|
||||
probe.extend(chips.iter().map(|c| (c.label(shape.is_some()).to_string(), Some(c.id(shape.is_some())))));
|
||||
ui.ctx().data_mut(|d| d.insert_temp(task_bar_id().with("offered"), probe));
|
||||
}
|
||||
offered.extend(chips.iter().map(|c| (c.label(shape.is_some()), Some(c.id(shape.is_some())))));
|
||||
let chips: Vec<Chip> = chips.into_iter().filter(|c| !hidden.contains(c.id(shape.is_some()))).collect();
|
||||
let offered: Vec<(&str, &str, bool)> = offered.into_iter().map(|(label, action)| (label, action, !hidden.contains(action))).collect();
|
||||
let bar_actions: Vec<(&str, &str, bool)> =
|
||||
offered.iter().filter_map(|&(label, action)| action.map(|a| (label, 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<f32> = items.iter().map(|(label, _, cmd, _)| item_width(ui, label, cmd)).collect();
|
||||
let fidelity = app.session.tool_options()["fidelity"].as_f64();
|
||||
@@ -531,7 +519,7 @@ 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 &offered {
|
||||
for (label, action, shown) in &bar_actions {
|
||||
if widgets::menu_item_name(ui, bar_action_name(label), true, *shown) {
|
||||
run = Some(("window.taskBar.actions", json!({ "action": action })));
|
||||
}
|
||||
|
||||
@@ -1973,7 +1973,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 = canvas::task_bar_offered(&ctx);
|
||||
let offered: Vec<(&'static str, Option<&'static str>)> = ctx.data(|d| d.get_temp(canvas::task_bar_id().with("offered")).unwrap_or_default());
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user