mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 23:50:13 +00:00
Merge main into #8383
This commit is contained in:
@@ -687,6 +687,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"{pinned?: bool} keep the Contextual Task Bar where it is instead of following the selection (true), let it follow the selection again from where it is (false) or toggle (omitted), as the bar's More Options menu does; returns the new state",
|
||||
),
|
||||
("window.taskBar.reset", "Reset Bar Position", "", "{} unpin the Contextual Task Bar and put it back under the selection"),
|
||||
(
|
||||
"window.taskBar.actions",
|
||||
"Bar Actions",
|
||||
"",
|
||||
"{action: \"imageTrace\"|\"cropImage\"|\"removeBackground\"|\"removeAnchorPoints\"|\"join\"|\"cutPath\"|\"convertToCorner\"|\"convertToSmooth\"|\"group\"|\"makeClippingMask\"|\"unite\"|\"expand\"|\"editClippingPath\"|\"releaseClippingMask\"|\"ungroup\"|\"isolate\"|\"editPath\"|\"releaseCompoundPath\"|\"createOutlines\"|\"convertToPointType\"|\"convertToAreaType\"|\"typeOnPathOptions\"|\"centerOnTop\"|\"centerOnBottom\"|\"dynamicText\"|\"offsetPath\"|\"simplify\"|\"smooth\"|\"duplicate\"|\"drawPencil\"|\"placeImage\"|\"fidelity\"|\"smoothToolOptions\"|\"resizeArtboard\"|\"duplicateArtboards\"|\"rearrangeArtboards\"|\"exportArtboards\"|\"fill\"|\"stroke\"|\"recolor\"|\"lock\"|\"shapeProperties\", visible?: bool} show (true), hide (false) or toggle (omitted or null) one of the Contextual Task Bar's actions or chips, as the bar's More Options › Bar Actions does; an action that is off stays out of the bar and out of More Options, and turning one off changes only the bar; `join` is both Connect and Join; every action starts on; kept with the preferences and with the workspace; another action, or a `visible` that is not true, false or null, is an error and changes nothing; returns {action, visible}",
|
||||
),
|
||||
(
|
||||
"window.taskBar.resetActions",
|
||||
"Reset Bar Actions",
|
||||
"",
|
||||
"{} show every Contextual Task Bar action and chip that Bar Actions turned off, as the bar's More Options › Reset Bar Actions does; returns the ids shown again",
|
||||
),
|
||||
(
|
||||
"window.dock",
|
||||
"Panels",
|
||||
|
||||
@@ -72,8 +72,9 @@ pub(crate) use raster::{KeptFrame, color_image, color_image_owned, render_job};
|
||||
use raster::{changed_pixels, frame_ppp, pixel_region, upload};
|
||||
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::{chip_paints, images_with_other_art};
|
||||
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};
|
||||
|
||||
@@ -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::<bool>(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 {
|
||||
@@ -182,7 +190,10 @@ pub(crate) fn task_bar_shows_type(app: &VectorcraftApp) -> bool {
|
||||
/// On a blank canvas, a document with no artwork and a selection tool in use, it sits under the
|
||||
/// active artboard and offers Draw (Pencil) and Place Image.
|
||||
/// Its handle drags it anywhere on the canvas; unpinned it keeps that offset as it follows the
|
||||
/// selection, pinned it stays put ([`crate::state::TaskBarPlace`]).
|
||||
/// selection, pinned it stays put ([`crate::state::TaskBarPlace`]). More Options › Bar Actions
|
||||
/// turns each action and chip the bar offers on or off ([`TASK_BAR_ACTIONS`], [`TASK_BAR_CHIPS`]);
|
||||
/// the bar leaves out the ones that are off, and Reset Bar Actions shows them all again. With every
|
||||
/// one of them off, the bar still shows its handle and More Options, where they turn back on.
|
||||
pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let on_artboards = app.session.tool_id() == "artboard";
|
||||
@@ -351,6 +362,13 @@ 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 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;
|
||||
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.
|
||||
let room = bounds.width() - BAR_FRAME;
|
||||
@@ -371,6 +389,13 @@ 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()), Some(c.id(shape.is_some())))));
|
||||
let chips: Vec<Chip> = chips.into_iter().filter(|c| !hidden.contains(c.id(shape.is_some()))).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<f32> = items.iter().map(|(label, _, cmd, _)| item_width(ui, label, cmd)).collect();
|
||||
let fidelity = app.session.tool_options()["fidelity"].as_f64();
|
||||
let font_w = fonts.then(|| {
|
||||
@@ -498,6 +523,21 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
|
||||
run = Some((cmd, json!({})));
|
||||
}
|
||||
}
|
||||
// The actions and chips the bar offers for this selection or tool, each
|
||||
// checked while it shows, which turns it on or off; then Reset Bar
|
||||
// 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 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 })));
|
||||
}
|
||||
}
|
||||
});
|
||||
if widgets::menu_item(ui, tl!("Reset Bar Actions"), any_hidden, false) {
|
||||
run = Some(("window.taskBar.resetActions", json!({})));
|
||||
}
|
||||
ui.separator();
|
||||
if widgets::menu_item(ui, tl!("Show Properties Panel"), true, false) {
|
||||
run = Some(("window.panel", json!({"panel": "properties"})));
|
||||
@@ -579,6 +619,112 @@ impl Chip {
|
||||
Chip::Recolor | Chip::Lock => 30.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// The chip's id in [`TASK_BAR_CHIPS`]; Lock is `shapeProperties` while it shows a basic
|
||||
/// `shape`'s properties.
|
||||
fn id(self, shape: bool) -> &'static str {
|
||||
match self {
|
||||
Chip::Fill => "fill",
|
||||
Chip::Stroke => "stroke",
|
||||
Chip::Recolor => "recolor",
|
||||
Chip::Lock if shape => "shapeProperties",
|
||||
Chip::Lock => "lock",
|
||||
}
|
||||
}
|
||||
|
||||
/// The chip's name in More Options › Bar Actions, translated.
|
||||
fn label(self, shape: bool) -> &'static str {
|
||||
match self {
|
||||
Chip::Fill => tl!("Fill"),
|
||||
Chip::Stroke => tl!("Stroke"),
|
||||
Chip::Recolor => tl!("Recolor Artwork"),
|
||||
Chip::Lock if shape => tl!("Shape Properties"),
|
||||
Chip::Lock => tl!("Lock"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Contextual Task Bar's actions that More Options › Bar Actions turns on or off
|
||||
/// (`window.taskBar.actions {action, visible?}`): each action's id, the command its button runs and
|
||||
/// the `tool` that command names, if any. An action that is off stays out of the bar, and More
|
||||
/// Options does not list it either; turning one off changes only the bar. Every action starts on.
|
||||
pub(crate) const TASK_BAR_ACTIONS: [(&str, &str, Option<&str>); 37] = [
|
||||
("imageTrace", TASK_BAR_IMAGE_TRACE, None),
|
||||
("cropImage", "ui.cropImage", None),
|
||||
("removeBackground", crate::addons::image::REMOVE_BACKGROUND, None),
|
||||
("removeAnchorPoints", "path.removeAnchors", None),
|
||||
("join", "path.join", None),
|
||||
("cutPath", "path.cutAtAnchors", None),
|
||||
("convertToCorner", TASK_BAR_TO_CORNER, None),
|
||||
("convertToSmooth", TASK_BAR_TO_SMOOTH, None),
|
||||
("group", "object.group", None),
|
||||
("makeClippingMask", "object.clippingMask.make", None),
|
||||
("unite", "object.pathfinder.unite", None),
|
||||
("expand", "imageTrace.expand", None),
|
||||
("editClippingPath", "object.clippingMask.editMask", None),
|
||||
("releaseClippingMask", "object.clippingMask.release", None),
|
||||
("ungroup", "object.ungroup", None),
|
||||
("isolate", "object.isolate", None),
|
||||
("editPath", "tool.select", Some("directSelection")),
|
||||
("releaseCompoundPath", "object.compoundPath.release", None),
|
||||
("createOutlines", "type.createOutlines", None),
|
||||
("convertToPointType", "type.convertToPointType", None),
|
||||
("convertToAreaType", "type.convertToAreaType", None),
|
||||
("typeOnPathOptions", "type.pathOptions", None),
|
||||
("centerOnTop", "type.pathCenter.top", None),
|
||||
("centerOnBottom", "type.pathCenter.bottom", None),
|
||||
("dynamicText", "type.dynamicText", None),
|
||||
("offsetPath", "object.path.offsetPath", None),
|
||||
("simplify", "object.path.simplify", None),
|
||||
("smooth", "object.path.smooth", None),
|
||||
("duplicate", "edit.duplicate", None),
|
||||
("drawPencil", "tool.select", Some("pencil")),
|
||||
("placeImage", "file.place", None),
|
||||
("fidelity", TASK_BAR_FIDELITY, None),
|
||||
("smoothToolOptions", "tool.options", Some("smooth")),
|
||||
("resizeArtboard", TASK_BAR_ARTBOARD_OPTIONS, None),
|
||||
("duplicateArtboards", TASK_BAR_DUPLICATE_ARTBOARDS, None),
|
||||
("rearrangeArtboards", TASK_BAR_REARRANGE_ARTBOARDS, None),
|
||||
("exportArtboards", "file.exportForScreens", None),
|
||||
];
|
||||
|
||||
/// The ids of the Contextual Task Bar's chips that More Options › Bar Actions turns on or off,
|
||||
/// as [`TASK_BAR_ACTIONS`] are.
|
||||
pub(crate) const TASK_BAR_CHIPS: [&str; 5] = ["fill", "stroke", "recolor", "lock", "shapeProperties"];
|
||||
|
||||
/// Whether `id` names one of the Contextual Task Bar's actions or chips.
|
||||
pub(crate) fn is_task_bar_action(id: &str) -> bool {
|
||||
TASK_BAR_ACTIONS.iter().any(|a| a.0 == id) || TASK_BAR_CHIPS.contains(&id)
|
||||
}
|
||||
|
||||
/// The id in [`TASK_BAR_ACTIONS`] of the bar's item that runs `cmd` with `params`.
|
||||
fn action_id(cmd: &str, params: &serde_json::Value) -> Option<&'static str> {
|
||||
let tool = params.get("tool").and_then(serde_json::Value::as_str);
|
||||
TASK_BAR_ACTIONS.iter().find(|(_, c, t)| *c == cmd && *t == tool).map(|a| a.0)
|
||||
}
|
||||
|
||||
/// The name More Options › Bar Actions lists for the bar's item `label`: without a field's colon
|
||||
/// (a full-width one too), the space some languages put before it, or a final ellipsis (`…` or
|
||||
/// `...`), in whichever order they come.
|
||||
pub(crate) fn bar_action_name(label: &str) -> &str {
|
||||
let mut name = label.trim_end();
|
||||
loop {
|
||||
let rest = name.trim_end_matches([':', ':', '…']);
|
||||
let rest = rest.strip_suffix("...").unwrap_or(rest).trim_end();
|
||||
if rest == name {
|
||||
return name;
|
||||
}
|
||||
name = rest;
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the Contextual Task Bar's actions and chips that are off, as kept in the preferences. Ids
|
||||
/// the bar does not have are dropped, and a value that is not a list of strings reads as none off,
|
||||
/// so the bar shows every action.
|
||||
pub(crate) fn read_hidden_task_bar_actions<'de, D: serde::Deserializer<'de>>(d: D) -> Result<std::collections::BTreeSet<String>, D::Error> {
|
||||
let value = <serde_json::Value as serde::Deserialize>::deserialize(d)?;
|
||||
let ids = value.as_array().into_iter().flatten().filter_map(serde_json::Value::as_str);
|
||||
Ok(ids.filter(|id| is_task_bar_action(id)).map(str::to_string).collect())
|
||||
}
|
||||
|
||||
/// What a click on one of the bar's [`Chip`]s does: make the Fill (`true`) or the Stroke active and
|
||||
|
||||
@@ -259,11 +259,12 @@ fn the_format_list_shows_its_scroll_bar_at_rest_and_opens_with_the_chosen_format
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let labels: Vec<&str> = export_as::formats().iter().map(|f| f.label).collect();
|
||||
// A built-in format six from the end of the built-in ones: out of view when the list opens at
|
||||
// its top, and far enough from the end that a plug-in format another test adds after the
|
||||
// built-in ones does not move the rows shown around it.
|
||||
// built-in ones does not move the rows shown around it. The window is short enough that the
|
||||
// list centered on it stops short of its end.
|
||||
let built_in: Vec<_> = fileio::FORMATS.iter().filter(|f| f.write && !matches!(f.id, "vectorcraft" | "ai")).collect();
|
||||
let labels: Vec<&str> = built_in.iter().map(|f| f.label).collect();
|
||||
let chosen = built_in.len().checked_sub(6).and_then(|i| built_in.get(i)).copied().expect("Export As lists formats");
|
||||
let (mut app, _) = app(1);
|
||||
app.run("file.exportAs", json!({"format": chosen.id})).unwrap();
|
||||
@@ -272,31 +273,38 @@ fn the_format_list_shows_its_scroll_bar_at_rest_and_opens_with_the_chosen_format
|
||||
theme::apply(&ctx, Default::default());
|
||||
// Every scroll area takes the bar at rest from the theme, whatever style the list sets itself.
|
||||
assert_eq!(ctx.global_style().spacing.scroll, crate::widgets::list_scroll_style());
|
||||
let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1024.0, 480.0)));
|
||||
let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1024.0, 280.0)));
|
||||
let mut time = 0.0;
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
// The texts and bars painted on the open list (without the dialog under it), and every text.
|
||||
let mut run = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
time += 0.25;
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect, events, time: Some(time), ..Default::default() }, |ui| show(app, ui.ctx()));
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect, events, time: Some(time), ..Default::default() }, |ui| {
|
||||
show(app, ui.ctx());
|
||||
popup.replace(crate::widgets::top_popup_shapes(ui.ctx()));
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
let (mut texts, mut bars) = (vec![], vec![]);
|
||||
out.shapes.iter().for_each(|c| walk(&c.shape, c.clip_rect, &mut texts, &mut bars));
|
||||
(texts, bars)
|
||||
let (mut texts, mut bars, mut all) = (vec![], vec![], vec![]);
|
||||
popup.take().iter().for_each(|c| walk(&c.shape, c.clip_rect, &mut texts, &mut bars));
|
||||
out.shapes.iter().for_each(|c| walk(&c.shape, c.clip_rect, &mut all, &mut vec![]));
|
||||
(texts, bars, all)
|
||||
};
|
||||
let away = egui::Event::PointerMoved(egui::pos2(1.0, 1.0));
|
||||
run(&mut app, vec![away.clone()]);
|
||||
let (texts, _) = run(&mut app, vec![]);
|
||||
let (_, _, texts) = run(&mut app, vec![]);
|
||||
let field = texts.iter().find(|(s, ..)| s == chosen.label).map(|(_, r, _)| r.center()).expect("the Format field shows the chosen format");
|
||||
let click_at = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
// Opens the list, moves the pointer away and returns the list's rect, the format names drawn in
|
||||
// it with their clip rects, and the bars drawn.
|
||||
type Run<'r> = dyn FnMut(&mut VectorcraftApp, Vec<egui::Event>) -> (Vec<(String, egui::Rect, egui::Rect)>, Vec<egui::Rect>) + 'r;
|
||||
type Texts = Vec<(String, egui::Rect, egui::Rect)>;
|
||||
type Run<'r> = dyn FnMut(&mut VectorcraftApp, Vec<egui::Event>) -> (Texts, Vec<egui::Rect>, Texts) + 'r;
|
||||
let open = |run: &mut Run<'_>, app: &mut VectorcraftApp| {
|
||||
run(app, vec![egui::Event::PointerMoved(field), click_at(field, true)]);
|
||||
run(app, vec![click_at(field, false)]);
|
||||
run(app, vec![away.clone()]);
|
||||
let (mut texts, mut bars) = (vec![], vec![]);
|
||||
for _ in 0..4 {
|
||||
(texts, bars) = run(app, vec![]);
|
||||
(texts, bars, _) = run(app, vec![]);
|
||||
}
|
||||
let list = ctx
|
||||
.memory(|m| {
|
||||
@@ -334,11 +342,13 @@ fn the_format_list_shows_its_scroll_bar_at_rest_and_opens_with_the_chosen_format
|
||||
run(&mut app, vec![wheel]);
|
||||
let mut scrolled = vec![];
|
||||
for _ in 0..4 {
|
||||
(scrolled, _) = run(&mut app, vec![]);
|
||||
(scrolled, ..) = run(&mut app, vec![]);
|
||||
}
|
||||
let scrolled: Vec<_> = scrolled.into_iter().filter(|(s, r, _)| labels.contains(&s.as_str()) && list.contains_rect(*r)).collect();
|
||||
run(&mut app, vec![egui::Event::PointerMoved(field), click_at(field, true)]);
|
||||
run(&mut app, vec![click_at(field, false)]);
|
||||
// Escape closes it: a list taller than the room beside its field covers the field.
|
||||
let escape = |pressed| egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
run(&mut app, vec![escape(true)]);
|
||||
run(&mut app, vec![escape(false)]);
|
||||
let (_, reopened, _) = open(&mut run, &mut app);
|
||||
if rows.len() < labels.len() {
|
||||
assert_ne!(tops(&scrolled), tops(&rows), "the wheel scrolled the list");
|
||||
@@ -347,6 +357,83 @@ fn the_format_list_shows_its_scroll_bar_at_rest_and_opens_with_the_chosen_format
|
||||
assert!(whole(&reopened, chosen.label), "the chosen format shows whole: {:?}", tops(&reopened));
|
||||
}
|
||||
|
||||
/// #5941: the Format list stopped at the room on one side of its field, so a window with room for
|
||||
/// every format still cut the list short. In windows of 1280×900 and 1000×856 the list shows every
|
||||
/// built-in format whole, the grayed-out DWG row after them included, inside the window, without a
|
||||
/// scroll bar. A plug-in format that another test adds or removes meanwhile is not counted.
|
||||
#[test]
|
||||
fn the_format_list_shows_every_format_when_the_window_has_room() {
|
||||
fn walk(shape: &egui::Shape, clip: egui::Rect, texts: &mut Vec<(String, egui::Rect, egui::Rect)>, bars: &mut Vec<egui::Rect>) {
|
||||
match shape {
|
||||
egui::Shape::Text(t) => texts.push((t.galley.text().into(), t.visual_bounding_rect(), clip)),
|
||||
egui::Shape::Rect(r) if r.fill.a() > 0 && r.rect.width() <= 8.0 && r.rect.height() > 40.0 => bars.push(r.rect),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, clip, texts, bars)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let labels: Vec<&str> =
|
||||
fileio::FORMATS.iter().filter(|f| f.write && !matches!(f.id, "vectorcraft" | "ai")).map(|f| f.label).chain(["DWG (use DXF)"]).collect();
|
||||
for (width, height) in [(1280.0, 900.0), (1000.0, 856.0)] {
|
||||
let case = format!("{width}×{height}");
|
||||
let (mut app, _) = app(1);
|
||||
app.run("file.exportAs", json!({"format": "png"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
theme::install_fonts(&ctx);
|
||||
theme::apply(&ctx, Default::default());
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(width, height));
|
||||
let mut time = 0.0;
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
// The texts and bars painted on the open list (without the dialog under it), and every text.
|
||||
let mut run = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
time += 0.25;
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, time: Some(time), ..Default::default() }, |ui| {
|
||||
show(app, ui.ctx());
|
||||
popup.replace(crate::widgets::top_popup_shapes(ui.ctx()));
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
let (mut texts, mut bars, mut all) = (vec![], vec![], vec![]);
|
||||
popup.take().iter().for_each(|c| walk(&c.shape, c.clip_rect, &mut texts, &mut bars));
|
||||
out.shapes.iter().for_each(|c| walk(&c.shape, c.clip_rect, &mut all, &mut vec![]));
|
||||
(texts, bars, all)
|
||||
};
|
||||
let away = egui::Event::PointerMoved(egui::pos2(1.0, 1.0));
|
||||
run(&mut app, vec![away.clone()]);
|
||||
let (_, _, all) = run(&mut app, vec![]);
|
||||
let field = all.iter().find(|(s, ..)| s == "PNG").map(|(_, r, _)| r.center()).expect("the Format field shows PNG");
|
||||
let click = |pressed| egui::Event::PointerButton { pos: field, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(&mut app, vec![egui::Event::PointerMoved(field), click(true)]);
|
||||
run(&mut app, vec![click(false)]);
|
||||
run(&mut app, vec![away.clone()]);
|
||||
let list_rect = || {
|
||||
ctx.memory(|m| {
|
||||
m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id))
|
||||
})
|
||||
};
|
||||
// A plug-in format that another test installs or removes changes the list's height, and the
|
||||
// list is placed for its new height on the pass after. Read it once it keeps its rect.
|
||||
let (mut texts, mut bars, mut list) = (vec![], vec![], None);
|
||||
for _ in 0..12 {
|
||||
(texts, bars, _) = run(&mut app, vec![]);
|
||||
let now = list_rect();
|
||||
if now.is_some() && now == list {
|
||||
break;
|
||||
}
|
||||
list = now;
|
||||
}
|
||||
let list = list.expect("the Format list is open");
|
||||
assert!(screen.contains_rect(list), "{case}: the list {list:?} is inside the window");
|
||||
let whole: Vec<&str> = labels
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|name| {
|
||||
texts.iter().any(|(s, r, clip)| s == name && list.contains_rect(*r) && r.top() >= clip.top() && r.bottom() <= clip.bottom())
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(whole, labels, "{case}: every format shows whole in {list:?}");
|
||||
assert!(bars.is_empty(), "{case}: a list that shows every format draws no scroll bar: {bars:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_continues_in_svg_options() {
|
||||
let (mut app, written) = app(2);
|
||||
|
||||
@@ -632,6 +632,8 @@ font-technology Variable Променливи
|
||||
Contextual Task Bar Контекстна лента със задачи
|
||||
Pin Bar Position Закачане на позицията на лентата
|
||||
Reset Bar Position Нулиране на позицията на лентата
|
||||
Bar Actions Действия на лентата
|
||||
Reset Bar Actions Нулиране на действията на лентата
|
||||
Resize Преоразмеряване
|
||||
Contrast Контраст
|
||||
Control Контрол
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -797,6 +797,8 @@
|
||||
Contextual Task Bar Kontekstna traka zadataka
|
||||
Pin Bar Position Položaj prikvačene trake
|
||||
Reset Bar Position Vrati položaj trake na početno
|
||||
Bar Actions Radnje trake
|
||||
Reset Bar Actions Vrati radnje trake na početno
|
||||
Resize Promijeni veličinu
|
||||
Tools Alati
|
||||
Toolbars Trake s alatima
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -3949,6 +3949,8 @@ digits Malayalam Malaiàlam
|
||||
Reset all Revolve settings to their defaults. Restableix tots els paràmetres de revolució als valors predeterminats.
|
||||
Reset Automation Restableix Automation
|
||||
Reset Bar Position Restableix la posició de la barra
|
||||
Bar Actions Accions de la barra
|
||||
Reset Bar Actions Restableix les accions de la barra
|
||||
Reset Bounding Box Restableix el quadre delimitador
|
||||
Rotate Bounding Box Gira el quadre delimitador
|
||||
Rotate Bounding Box… Gira el quadre delimitador…
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -809,6 +809,8 @@
|
||||
Contextual Task Bar Kontextový panel úloh
|
||||
Pin Bar Position Připnout polohu panelu
|
||||
Reset Bar Position Obnovit polohu panelu
|
||||
Bar Actions Akce panelu
|
||||
Reset Bar Actions Obnovit akce panelu
|
||||
Resize Změnit velikost
|
||||
Tools Nástroje
|
||||
Toolbars Panely nástrojů
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3507,6 +3507,8 @@ liquify-list-end {0}, {1} {0} og {1}
|
||||
Contextual Task Bar Kontekstuel opgavelinje
|
||||
Pin Bar Position Fastgør linjens placering
|
||||
Reset Bar Position Nulstil linjens placering
|
||||
Bar Actions Linjens handlinger
|
||||
Reset Bar Actions Nulstil linjens handlinger
|
||||
Tools Værktøjer
|
||||
Toolbars Værktøjslinjer
|
||||
Advanced Avanceret
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -636,6 +636,8 @@ font-technology Variable Variabel
|
||||
Contextual Task Bar Kontextbezogene Taskleiste
|
||||
Pin Bar Position Position der Leiste fixieren
|
||||
Reset Bar Position Position der Leiste zurücksetzen
|
||||
Bar Actions Aktionen der Leiste
|
||||
Reset Bar Actions Aktionen der Leiste zurücksetzen
|
||||
Resize Größe ändern
|
||||
Contrast Kontrast
|
||||
Control Steuerung
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -610,6 +610,8 @@ font-technology Variable Μεταβλητές
|
||||
Contextual Task Bar Γραμμή εργασιών βάσει περιβάλλοντος
|
||||
Pin Bar Position Σταθεροποίηση θέσης γραμμής
|
||||
Reset Bar Position Επαναφορά θέσης γραμμής
|
||||
Bar Actions Ενέργειες γραμμής
|
||||
Reset Bar Actions Επαναφορά ενεργειών γραμμής
|
||||
Resize Αλλαγή μεγέθους
|
||||
Contrast Αντίθεση
|
||||
Control Έλεγχος
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -656,6 +656,8 @@ font-technology Variable Variables
|
||||
Contextual Task Bar Barra de tareas contextual
|
||||
Pin Bar Position Fijar posición de la barra
|
||||
Reset Bar Position Restablecer posición de la barra
|
||||
Bar Actions Acciones de la barra
|
||||
Reset Bar Actions Restablecer acciones de la barra
|
||||
Resize Cambiar tamaño
|
||||
Contrast Contraste
|
||||
Control Control
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -795,6 +795,8 @@
|
||||
Contextual Task Bar Kontekstuaalinen tehtäväpalkki
|
||||
Pin Bar Position Kiinnitä palkin sijainti
|
||||
Reset Bar Position Palauta palkin sijainti
|
||||
Bar Actions Palkin toiminnot
|
||||
Reset Bar Actions Palauta palkin toiminnot
|
||||
Resize Muuta kokoa
|
||||
Tools Työkalut
|
||||
Toolbars Työkalurivit
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -657,6 +657,8 @@ font-technology Variable Variables
|
||||
Contextual Task Bar Barre des tâches contextuelle
|
||||
Pin Bar Position Épingler la position de la barre
|
||||
Reset Bar Position Réinitialiser la position de la barre
|
||||
Bar Actions Actions de la barre
|
||||
Reset Bar Actions Réinitialiser les actions de la barre
|
||||
Resize Redimensionner
|
||||
Contrast Contraste
|
||||
Control Contrôle
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3284,6 +3284,8 @@ arrowhead Feather પીંછું
|
||||
Reselect ફરી પસંદ કરો
|
||||
Reset રીસેટ કરો
|
||||
Reset Bar Position બાર સ્થિતિ રીસેટ કરો
|
||||
Bar Actions બાર ક્રિયાઓ
|
||||
Reset Bar Actions બાર ક્રિયાઓ રીસેટ કરો
|
||||
Reset Bounding Box બાઉન્ડિંગ બોક્સ રીસેટ કરો
|
||||
Rotate Bounding Box બાઉન્ડિંગ બોક્સ ફેરવો
|
||||
Rotate Bounding Box… બાઉન્ડિંગ બોક્સ ફેરવો…
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 72 and column 5.
|
@@ -4575,6 +4575,8 @@ arrowhead Feather पंख
|
||||
Reset all Revolve settings to their defaults. सभी रिवॉल्व सेटिंग्स डिफ़ॉल्ट पर रीसेट करें।
|
||||
Reset Automation स्वचालन रीसेट करें
|
||||
Reset Bar Position बार स्थिति रीसेट करें
|
||||
Bar Actions बार क्रियाएँ
|
||||
Reset Bar Actions बार क्रियाएँ रीसेट करें
|
||||
Reset Bounding Box बाउंडिंग बॉक्स रीसेट करें
|
||||
Rotate Bounding Box बाउंडिंग बॉक्स घुमाएँ
|
||||
Rotate Bounding Box… बाउंडिंग बॉक्स घुमाएँ…
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3788,6 +3788,8 @@ mark-style Japanese Japán
|
||||
Reset all Revolve settings to their defaults. A tengely körüli forgatás minden beállítását visszaállítja az alapértékre.
|
||||
Reset Automation Automation visszaállítása
|
||||
Reset Bar Position Sáv helyének visszaállítása
|
||||
Bar Actions Sáv műveletei
|
||||
Reset Bar Actions Sáv műveleteinek visszaállítása
|
||||
Reset Bounding Box Befoglaló keret visszaállítása
|
||||
Rotate Bounding Box Befoglaló keret elforgatása
|
||||
Rotate Bounding Box… Befoglaló keret elforgatása…
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1384,6 +1384,8 @@
|
||||
Contextual Task Bar Bilah tugas kontekstual
|
||||
Pin Bar Position Sematkan posisi bilah
|
||||
Reset Bar Position Atur ulang posisi bilah
|
||||
Bar Actions Tindakan bilah
|
||||
Reset Bar Actions Atur ulang tindakan bilah
|
||||
Tools Alat
|
||||
Toolbars Bilah alat
|
||||
Advanced Lanjutan
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -658,6 +658,8 @@ font-technology Variable Variabili
|
||||
Contextual Task Bar Barra attività contestuale
|
||||
Pin Bar Position Fissa posizione barra
|
||||
Reset Bar Position Ripristina posizione barra
|
||||
Bar Actions Azioni barra
|
||||
Reset Bar Actions Ripristina azioni barra
|
||||
Resize Ridimensiona
|
||||
Contrast Contrasto
|
||||
Control Controllo
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -846,6 +846,8 @@ digits Malayalam マラヤーラム数字
|
||||
Contextual Task Bar コンテキストタスクバー
|
||||
Pin Bar Position バーの位置を固定
|
||||
Reset Bar Position バーの位置をリセット
|
||||
Bar Actions バーのアクション
|
||||
Reset Bar Actions バーのアクションをリセット
|
||||
Resize サイズを変更
|
||||
Tools ツール
|
||||
Toolbars ツールバー
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2920,6 +2920,8 @@
|
||||
Contextual Task Bar კონტექსტური ამოცანების ზოლი
|
||||
Pin Bar Position ზოლის პოზიციის ჩამაგრება
|
||||
Reset Bar Position ზოლის პოზიციის ჩამოყრა
|
||||
Bar Actions ზოლის მოქმედებები
|
||||
Reset Bar Actions ზოლის მოქმედებების ჩამოყრა
|
||||
Tools ხელსაწყოები
|
||||
Toolbars ხელსაწყოთა ზოლები
|
||||
Advanced დამატებითი
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -839,6 +839,8 @@ digits Malayalam 말라얄람어
|
||||
Contextual Task Bar 상황별 작업 표시줄
|
||||
Pin Bar Position 표시줄 위치 고정
|
||||
Reset Bar Position 표시줄 위치 재설정
|
||||
Bar Actions 표시줄 동작
|
||||
Reset Bar Actions 표시줄 동작 재설정
|
||||
Resize 크기 조절
|
||||
Tools 도구
|
||||
Toolbars 도구 모음
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1376,6 +1376,8 @@ liquify-list-end {0}, {1} {0} en {1}
|
||||
Contextual Task Bar Contextuele taakbalk
|
||||
Pin Bar Position Balkpositie vastzetten
|
||||
Reset Bar Position Balkpositie herstellen
|
||||
Bar Actions Balkacties
|
||||
Reset Bar Actions Balkacties herstellen
|
||||
Tools Gereedschappen
|
||||
Toolbars Werkbalken
|
||||
Advanced Geavanceerd
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -758,6 +758,8 @@
|
||||
Contextual Task Bar Kontekstowy pasek zadań
|
||||
Pin Bar Position Przypnij położenie paska
|
||||
Reset Bar Position Resetuj położenie paska
|
||||
Bar Actions Akcje paska
|
||||
Reset Bar Actions Resetuj akcje paska
|
||||
Resize Zmień rozmiar
|
||||
Tools Narzędzia
|
||||
Toolbars Paski narzędzi
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -601,6 +601,8 @@ antiAlias Sharp Nítido
|
||||
Contextual Task Bar Barra de Tarefas Contextual
|
||||
Pin Bar Position Fixar Posição da Barra
|
||||
Reset Bar Position Redefinir Posição da Barra
|
||||
Bar Actions Ações da Barra
|
||||
Reset Bar Actions Redefinir Ações da Barra
|
||||
Resize Redimensionar
|
||||
Control Controle
|
||||
Convert Converter
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -654,6 +654,8 @@ font-technology Variable Вариативные
|
||||
Contextual Task Bar Контекстная панель задач
|
||||
Pin Bar Position Закрепить положение панели
|
||||
Reset Bar Position Сбросить положение панели
|
||||
Bar Actions Действия панели
|
||||
Reset Bar Actions Сбросить действия панели
|
||||
Resize Изменить размер
|
||||
Contrast Контраст
|
||||
Control Control
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -639,6 +639,8 @@ font-technology Variable Variabla
|
||||
Contextual Task Bar Kontextuellt aktivitetsfält
|
||||
Pin Bar Position Fäst fältets position
|
||||
Reset Bar Position Återställ fältets position
|
||||
Bar Actions Fältets åtgärder
|
||||
Reset Bar Actions Återställ fältets åtgärder
|
||||
Resize Ändra storlek
|
||||
Contrast Kontrast
|
||||
Control Kontroll
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -636,6 +636,8 @@ font-technology Variable Değişken
|
||||
Contextual Task Bar Bağlamsal Görev Çubuğu
|
||||
Pin Bar Position Pim Çubuğu Konumu
|
||||
Reset Bar Position Çubuk Konumunu Sıfırla
|
||||
Bar Actions Çubuk Eylemleri
|
||||
Reset Bar Actions Çubuk Eylemlerini Sıfırla
|
||||
Contrast Kontrast
|
||||
Control Kontrol
|
||||
Convert Dönüştür
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -652,6 +652,8 @@ font-technology Variable Варіативні
|
||||
Contextual Task Bar Контекстна панель завдань
|
||||
Pin Bar Position Закріпити положення панелі
|
||||
Reset Bar Position Скинути положення панелі
|
||||
Bar Actions Дії панелі
|
||||
Reset Bar Actions Скинути дії панелі
|
||||
Resize Змінити розмір
|
||||
Contrast Контраст
|
||||
Control Панель керування
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3566,6 +3566,8 @@ mark-style Japanese Kiểu Nhật
|
||||
Reset all 3D settings to their defaults. Đặt lại tất cả cài đặt 3D về mặc định.
|
||||
Reset all Revolve settings to their defaults. Đặt lại tất cả cài đặt Revolve về mặc định.
|
||||
Reset Bar Position Đặt lại vị trí thanh
|
||||
Bar Actions Thao tác của thanh
|
||||
Reset Bar Actions Đặt lại thao tác của thanh
|
||||
Reset Bounding Box Đặt lại hộp bao
|
||||
Rotate Bounding Box Xoay hộp bao
|
||||
Rotate Bounding Box… Xoay hộp bao…
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -603,6 +603,8 @@ antiAlias Sharp 锐利
|
||||
Contextual Task Bar 上下文任务栏
|
||||
Pin Bar Position 固定任务栏位置
|
||||
Reset Bar Position 重置任务栏位置
|
||||
Bar Actions 任务栏操作
|
||||
Reset Bar Actions 重置任务栏操作
|
||||
Resize 调整大小
|
||||
Contrast 对比
|
||||
Control 控制栏
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -620,6 +620,8 @@ font-technology Variable 可變
|
||||
Contextual Task Bar 快捷工作列
|
||||
Pin Bar Position 釘選工作列位置
|
||||
Reset Bar Position 重設工作列位置
|
||||
Bar Actions 工作列動作
|
||||
Reset Bar Actions 重設工作列動作
|
||||
Resize 調整大小
|
||||
Contrast 對比
|
||||
Control 控制
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -652,6 +652,26 @@ fn run_ui_part6(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
app.ui.task_bar_place = Default::default();
|
||||
Ok(Value::Null)
|
||||
}
|
||||
// More Options › Bar Actions: one of the bar's actions or chips on or off.
|
||||
"window.taskBar.actions" => match (s("action").filter(|a| crate::canvas::is_task_bar_action(a)), opt_bool(p, "visible")) {
|
||||
(None, _) => {
|
||||
let ids = crate::canvas::TASK_BAR_ACTIONS.iter().map(|a| a.0).chain(crate::canvas::TASK_BAR_CHIPS);
|
||||
Err(format!("`action` must be one of {}", ids.collect::<Vec<_>>().join(", ")))
|
||||
}
|
||||
(_, Err(e)) => Err(e),
|
||||
(Some(action), Ok(visible)) => {
|
||||
let hidden = &mut app.ui.task_bar_hidden_actions;
|
||||
let visible = visible.unwrap_or_else(|| hidden.contains(&action));
|
||||
if visible {
|
||||
hidden.remove(&action);
|
||||
} else {
|
||||
hidden.insert(action.clone());
|
||||
}
|
||||
Ok(json!({ "action": action, "visible": visible }))
|
||||
}
|
||||
},
|
||||
// More Options › Reset Bar Actions: every action and chip shows again.
|
||||
"window.taskBar.resetActions" => Ok(json!(std::mem::take(&mut app.ui.task_bar_hidden_actions))),
|
||||
"window.dock" => {
|
||||
let ui = &mut app.ui;
|
||||
// The bars the last Tab hid show again, unless the toolbar or the Control bar was shown
|
||||
|
||||
@@ -95,6 +95,10 @@ pub fn checked(app: &VectorcraftApp, id: &str, p: &Value) -> Option<bool> {
|
||||
"window.taskBar" => app.ui.task_bar,
|
||||
"window.pathfinder.compoundShapes" => app.ui.shape_modes_compound,
|
||||
"window.taskBar.pin" => app.ui.task_bar_place.pinned,
|
||||
"window.taskBar.actions" => p
|
||||
.get("action")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|a| crate::canvas::is_task_bar_action(a) && !app.ui.task_bar_hidden_actions.contains(a)),
|
||||
"window.learn" => crate::panels::learn::visible(&app.ui),
|
||||
"window.panel" => {
|
||||
let panel = p.get("panel").and_then(Value::as_str).unwrap_or("");
|
||||
|
||||
@@ -688,6 +688,18 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"{pinned?: bool} keep the Contextual Task Bar where it is instead of following the selection (true), let it follow the selection again from where it is (false) or toggle (omitted), as the bar's More Options menu does; returns the new state",
|
||||
),
|
||||
("window.taskBar.reset", "Reset Bar Position", "", "{} unpin the Contextual Task Bar and put it back under the selection"),
|
||||
(
|
||||
"window.taskBar.actions",
|
||||
"Bar Actions",
|
||||
"",
|
||||
"{action: \"imageTrace\"|\"cropImage\"|\"removeBackground\"|\"removeAnchorPoints\"|\"join\"|\"cutPath\"|\"convertToCorner\"|\"convertToSmooth\"|\"group\"|\"makeClippingMask\"|\"unite\"|\"expand\"|\"editClippingPath\"|\"releaseClippingMask\"|\"ungroup\"|\"isolate\"|\"editPath\"|\"releaseCompoundPath\"|\"createOutlines\"|\"convertToPointType\"|\"convertToAreaType\"|\"typeOnPathOptions\"|\"centerOnTop\"|\"centerOnBottom\"|\"dynamicText\"|\"offsetPath\"|\"simplify\"|\"smooth\"|\"duplicate\"|\"drawPencil\"|\"placeImage\"|\"fidelity\"|\"smoothToolOptions\"|\"resizeArtboard\"|\"duplicateArtboards\"|\"rearrangeArtboards\"|\"exportArtboards\"|\"fill\"|\"stroke\"|\"recolor\"|\"lock\"|\"shapeProperties\", visible?: bool} show (true), hide (false) or toggle (omitted or null) one of the Contextual Task Bar's actions or chips, as the bar's More Options › Bar Actions does; an action that is off stays out of the bar and out of More Options, and turning one off changes only the bar; `join` is both Connect and Join; every action starts on; kept with the preferences and with the workspace; another action, or a `visible` that is not true, false or null, is an error and changes nothing; returns {action, visible}",
|
||||
),
|
||||
(
|
||||
"window.taskBar.resetActions",
|
||||
"Reset Bar Actions",
|
||||
"",
|
||||
"{} show every Contextual Task Bar action and chip that Bar Actions turned off, as the bar's More Options › Reset Bar Actions does; returns the ids shown again",
|
||||
),
|
||||
(
|
||||
"window.dock",
|
||||
"Panels",
|
||||
|
||||
@@ -502,6 +502,10 @@ pub struct UiState {
|
||||
/// starts under the selection at every launch.
|
||||
#[serde(skip)]
|
||||
pub task_bar_place: TaskBarPlace,
|
||||
/// The Contextual Task Bar's actions (`canvas::TASK_BAR_ACTIONS`) that More Options › Bar
|
||||
/// Actions has off (`window.taskBar.actions`); none: the bar shows every action it offers.
|
||||
#[serde(deserialize_with = "crate::canvas::read_hidden_task_bar_actions")]
|
||||
pub task_bar_hidden_actions: std::collections::BTreeSet<String>,
|
||||
/// The Pathfinder panel's Shape Mode buttons make a compound shape on a click, and give the
|
||||
/// permanent Pathfinder result on Alt-click (off, the default: the other way round).
|
||||
#[serde(default)]
|
||||
@@ -1270,6 +1274,7 @@ impl Default for UiState {
|
||||
toolbar_advanced: false,
|
||||
task_bar: true,
|
||||
task_bar_place: TaskBarPlace::default(),
|
||||
task_bar_hidden_actions: Default::default(),
|
||||
shape_modes_compound: false,
|
||||
context_locked: None,
|
||||
context_intertwine: None,
|
||||
|
||||
@@ -1573,3 +1573,469 @@ fn the_task_bar_follows_edits_and_undo() {
|
||||
assert!(has(&texts, "10 pt") && !has(&texts, "20 pt"), "{texts:?}");
|
||||
assert!(!locked(&app, rect), "the button doesn't lock the shape");
|
||||
}
|
||||
|
||||
/// Turns the bar's action or chip `action` on or off (`window.taskBar.actions`).
|
||||
fn show_action(app: &mut VectorcraftApp, action: &str, visible: bool) {
|
||||
let r = app.run("window.taskBar.actions", json!({"action": action, "visible": visible})).unwrap();
|
||||
assert_eq!(r, json!({"action": action, "visible": visible}));
|
||||
}
|
||||
|
||||
/// An action turned off in Bar Actions leaves the bar for every selection that offers it, and its
|
||||
/// Object menu command stays enabled. Toggled, it comes back.
|
||||
#[test]
|
||||
fn an_action_turned_off_leaves_the_bar_and_stays_in_its_menu() {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let line = id(app.run("shape.line", json!({"x1": 50, "y1": 50, "x2": 200, "y2": 120})).unwrap());
|
||||
select(&mut app, &[line]);
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(has(&texts, "Offset Path") && has(&texts, "Join"), "{texts:?}");
|
||||
show_action(&mut app, "offsetPath", false);
|
||||
assert_eq!(crate::menus::checked(&app, "window.taskBar.actions", &json!({"action": "offsetPath"})), Some(false));
|
||||
assert_eq!(crate::menus::checked(&app, "window.taskBar.actions", &json!({"action": "join"})), Some(true));
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(!has(&texts, "Offset Path"), "{texts:?}");
|
||||
assert!(has(&texts, "Join") && has(&texts, "Simplify") && has(&texts, "Edit Path"), "the other actions stay: {texts:?}");
|
||||
assert!(crate::menus::enabled(&app, "object.path.offsetPath"), "Object › Path › Offset Path… still runs");
|
||||
|
||||
// Another selection that offers the same action leaves it out too: a rectangle.
|
||||
let rect = id(app.run("shape.rectangle", json!({"x": 220, "y": 40, "width": 80, "height": 60})).unwrap());
|
||||
select(&mut app, &[rect]);
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(!has(&texts, "Offset Path") && has(&texts, "Edit Path"), "{texts:?}");
|
||||
|
||||
// Toggled (no `visible`), it shows again.
|
||||
assert_eq!(app.run("window.taskBar.actions", json!({"action": "offsetPath"})).unwrap(), json!({"action": "offsetPath", "visible": true}));
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(has(&texts, "Offset Path"), "{texts:?}");
|
||||
// A `visible` of null counts as omitted and toggles too.
|
||||
let r = app.run("window.taskBar.actions", json!({"action": "offsetPath", "visible": null})).unwrap();
|
||||
assert_eq!(r, json!({"action": "offsetPath", "visible": false}));
|
||||
}
|
||||
|
||||
/// The Fill, Stroke, Recolor Artwork, Lock and Shape Properties chips each turn off on their own:
|
||||
/// Lock off leaves a basic shape's Shape Properties, and Shape Properties off leaves Lock.
|
||||
#[test]
|
||||
fn a_chip_turned_off_leaves_the_bar() {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let rect = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 80, "height": 60})).unwrap());
|
||||
let line = id(app.run("shape.line", json!({"x1": 50, "y1": 150, "x2": 200, "y2": 220})).unwrap());
|
||||
select(&mut app, &[rect]);
|
||||
let names = |app: &mut VectorcraftApp| buttons(app).1.into_iter().map(|(n, _)| n).collect::<Vec<_>>();
|
||||
let shown = names(&mut app);
|
||||
for name in ["Fill", "Stroke", "Shape Properties"] {
|
||||
assert!(shown.iter().any(|n| n == name), "{name}: {shown:?}");
|
||||
}
|
||||
show_action(&mut app, "fill", false);
|
||||
show_action(&mut app, "lock", false);
|
||||
let shown = names(&mut app);
|
||||
assert!(!shown.iter().any(|n| n == "Fill"), "{shown:?}");
|
||||
assert!(shown.iter().any(|n| n == "Stroke") && shown.iter().any(|n| n == "Shape Properties"), "{shown:?}");
|
||||
select(&mut app, &[line]);
|
||||
let shown = names(&mut app);
|
||||
assert!(!shown.iter().any(|n| n.starts_with("Lock")), "Lock is off: {shown:?}");
|
||||
show_action(&mut app, "lock", true);
|
||||
show_action(&mut app, "shapeProperties", false);
|
||||
let shown = names(&mut app);
|
||||
assert!(shown.iter().any(|n| n.starts_with("Lock")), "Lock is on again: {shown:?}");
|
||||
select(&mut app, &[rect]);
|
||||
let shown = names(&mut app);
|
||||
assert!(!shown.iter().any(|n| n == "Shape Properties"), "{shown:?}");
|
||||
}
|
||||
|
||||
/// Reset Bar Actions shows every action and chip again and returns the ids it showed.
|
||||
#[test]
|
||||
fn reset_bar_actions_shows_every_action_again() {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let line = id(app.run("shape.line", json!({"x1": 50, "y1": 50, "x2": 200, "y2": 120})).unwrap());
|
||||
select(&mut app, &[line]);
|
||||
show_action(&mut app, "simplify", false);
|
||||
show_action(&mut app, "duplicate", false);
|
||||
show_action(&mut app, "stroke", false);
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(!has(&texts, "Simplify") && !has(&texts, "Duplicate"), "{texts:?}");
|
||||
assert_eq!(app.run("window.taskBar.resetActions", json!({})).unwrap(), json!(["duplicate", "simplify", "stroke"]));
|
||||
assert!(app.ui.task_bar_hidden_actions.is_empty());
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(has(&texts, "Simplify") && has(&texts, "Duplicate"), "{texts:?}");
|
||||
assert_eq!(app.run("window.taskBar.resetActions", json!({})).unwrap(), json!([]), "nothing left to show");
|
||||
}
|
||||
|
||||
/// Each of the bar's actions and chips has its own id, and no two actions run the same command
|
||||
/// with the same tool.
|
||||
#[test]
|
||||
fn bar_action_ids_are_distinct() {
|
||||
let ids: Vec<&str> = canvas::TASK_BAR_ACTIONS.iter().map(|a| a.0).chain(canvas::TASK_BAR_CHIPS).collect();
|
||||
let set: std::collections::BTreeSet<&str> = ids.iter().copied().collect();
|
||||
assert_eq!(set.len(), ids.len(), "{ids:?}");
|
||||
let runs: std::collections::BTreeSet<(&str, Option<&str>)> = canvas::TASK_BAR_ACTIONS.iter().map(|a| (a.1, a.2)).collect();
|
||||
assert_eq!(runs.len(), canvas::TASK_BAR_ACTIONS.len());
|
||||
}
|
||||
|
||||
/// An action the bar does not have, a missing one, or a `visible` that is not true, false or null is
|
||||
/// an error and changes nothing.
|
||||
#[test]
|
||||
fn bar_actions_refuse_bad_params() {
|
||||
let mut app = app();
|
||||
show_action(&mut app, "group", false);
|
||||
for p in [json!({"action": "teleport"}), json!({}), json!({"action": 3}), json!({"action": "unite", "visible": "yes"})] {
|
||||
assert!(app.run("window.taskBar.actions", p.clone()).is_err(), "{p}");
|
||||
}
|
||||
let err = app.run("window.taskBar.actions", json!({"action": "teleport"})).unwrap_err();
|
||||
assert!(err.contains("imageTrace") && err.contains("shapeProperties"), "{err}");
|
||||
assert_eq!(app.ui.task_bar_hidden_actions.iter().map(String::as_str).collect::<Vec<_>>(), ["group"]);
|
||||
assert_eq!(crate::menus::checked(&app, "window.taskBar.actions", &json!({"action": "teleport"})), Some(false));
|
||||
}
|
||||
|
||||
/// The actions that are off are kept with the preferences. Ids the bar does not have are dropped,
|
||||
/// a value that is not a list turns none off, and older preferences without it show every action.
|
||||
#[test]
|
||||
fn bar_actions_are_kept_with_the_preferences() {
|
||||
let mut app = app();
|
||||
show_action(&mut app, "unite", false);
|
||||
show_action(&mut app, "recolor", false);
|
||||
let mut prefs = serde_json::to_value(&app.ui).unwrap();
|
||||
let back: crate::state::UiState = serde_json::from_value(prefs.clone()).unwrap();
|
||||
let ids = |ui: &crate::state::UiState| ui.task_bar_hidden_actions.iter().cloned().collect::<Vec<_>>();
|
||||
assert_eq!(ids(&back), ["recolor", "unite"]);
|
||||
prefs["task_bar_hidden_actions"] = json!(["unite", "teleport", 7, "fill"]);
|
||||
assert_eq!(ids(&serde_json::from_value(prefs.clone()).unwrap()), ["fill", "unite"], "ids the bar does not have are dropped");
|
||||
prefs["task_bar_hidden_actions"] = json!("unite");
|
||||
assert!(ids(&serde_json::from_value(prefs.clone()).unwrap()).is_empty(), "a value that is not a list turns none off");
|
||||
prefs.as_object_mut().unwrap().remove("task_bar_hidden_actions");
|
||||
assert!(ids(&serde_json::from_value(prefs).unwrap()).is_empty(), "older preferences show every action");
|
||||
app.run("window.taskBar.resetActions", json!({})).unwrap();
|
||||
assert_eq!(serde_json::to_value(&app.ui).unwrap()["task_bar_hidden_actions"], json!([]), "none off");
|
||||
}
|
||||
|
||||
/// More Options › Bar Actions lists the actions and chips the bar offers for the selection, each
|
||||
/// checked while it shows; a click turns one off, it is listed unchecked after that, and a click on
|
||||
/// Reset Bar Actions shows it again.
|
||||
#[test]
|
||||
fn more_options_bar_actions_turns_an_action_off_and_on() {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let line = id(app.run("shape.line", json!({"x1": 50, "y1": 50, "x2": 200, "y2": 120})).unwrap());
|
||||
select(&mut app, &[line]);
|
||||
let more = buttons(&mut app).1.into_iter().find(|(n, _)| n == "More Options").expect("More Options").1.center();
|
||||
let (ctx, _) = bar(&mut app);
|
||||
let click_at = |app: &mut VectorcraftApp, p: Pos2| {
|
||||
let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
frame(app, &ctx, vec![Event::PointerMoved(p)]);
|
||||
frame(app, &ctx, vec![press(true)]);
|
||||
frame(app, &ctx, vec![press(false)]);
|
||||
frame(app, &ctx, vec![])
|
||||
};
|
||||
let texts = click_at(&mut app, more);
|
||||
let item = at(&texts, " Bar Actions");
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(item)]);
|
||||
let texts = frame(&mut app, &ctx, vec![]);
|
||||
for name in ["✓ Join", "✓ Edit Path", "✓ Offset Path", "✓ Simplify", "✓ Duplicate", "✓ Fill", "✓ Stroke", "✓ Lock"] {
|
||||
assert!(has(&texts, name), "{name}: {texts:?}");
|
||||
}
|
||||
assert!(has(&texts, " Reset Bar Actions"), "{texts:?}");
|
||||
let offset = at(&texts, "✓ Offset Path");
|
||||
// Along the submenu's row first, so the pointer stays over the menu on its way.
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(Pos2::new(offset.x, item.y))]);
|
||||
click_at(&mut app, offset);
|
||||
assert!(app.ui.task_bar_hidden_actions.contains("offsetPath"), "{:?}", app.ui.task_bar_hidden_actions);
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(!has(&texts, "Offset Path") && has(&texts, "Simplify"), "{texts:?}");
|
||||
|
||||
// Opened again, Bar Actions lists it unchecked; Reset Bar Actions turns it on.
|
||||
let more = buttons(&mut app).1.into_iter().find(|(n, _)| n == "More Options").expect("More Options").1.center();
|
||||
let (ctx, _) = bar(&mut app);
|
||||
let click_at = |app: &mut VectorcraftApp, p: Pos2| {
|
||||
let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
frame(app, &ctx, vec![Event::PointerMoved(p)]);
|
||||
frame(app, &ctx, vec![press(true)]);
|
||||
frame(app, &ctx, vec![press(false)]);
|
||||
frame(app, &ctx, vec![])
|
||||
};
|
||||
let texts = click_at(&mut app, more);
|
||||
let item = at(&texts, " Bar Actions");
|
||||
let reset = at(&texts, " Reset Bar Actions");
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(item)]);
|
||||
let texts = frame(&mut app, &ctx, vec![]);
|
||||
assert!(has(&texts, " Offset Path") && has(&texts, "✓ Simplify"), "{texts:?}");
|
||||
// Back along the menu's column to Reset Bar Actions, closing the submenu on the way.
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(Pos2::new(item.x, reset.y))]);
|
||||
click_at(&mut app, reset);
|
||||
assert!(app.ui.task_bar_hidden_actions.is_empty(), "{:?}", app.ui.task_bar_hidden_actions);
|
||||
let (_, texts) = bar(&mut app);
|
||||
assert!(has(&texts, "Offset Path"), "{texts:?}");
|
||||
}
|
||||
|
||||
/// On a canvas too short for every action, More Options lists the ones that don't fit; an action
|
||||
/// turned off in Bar Actions is listed neither there nor on the bar, and the others still are.
|
||||
#[test]
|
||||
fn an_action_turned_off_is_not_listed_in_more_options() {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let a = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 120, "height": 100})).unwrap());
|
||||
let b = id(app.run("shape.ellipse", json!({"x": 70, "y": 60, "width": 50, "height": 50})).unwrap());
|
||||
select(&mut app, &[a, b]);
|
||||
let size = vec2(160.0, 150.0);
|
||||
// More Options' list, opened on a new context, and what the bar itself shows.
|
||||
let listed = |app: &mut VectorcraftApp| {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let (on_bar, r, _) = bar_texts_on_screen(app, &ctx, size, 3);
|
||||
let more = r.min + vec2(9.0 + 4.0 + 6.0 + 15.0, 7.0 + 15.0);
|
||||
let press = |pressed| Event::PointerButton { pos: more, button: PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, size);
|
||||
let mut texts = vec![];
|
||||
for events in [vec![Event::PointerMoved(more)], vec![press(true)], vec![press(false)], vec![]] {
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| canvas::show(app, ui));
|
||||
out.textures_delta.clear();
|
||||
texts = shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::<Vec<_>>());
|
||||
}
|
||||
assert!(texts.iter().any(|(t, _)| t.trim() == "Hide Bar"), "More Options opens: {texts:?}");
|
||||
let names = |t: &[(String, Rect)]| t.iter().map(|(t, _)| t.trim().to_string()).collect::<Vec<_>>();
|
||||
(names(&on_bar), names(&texts))
|
||||
};
|
||||
let (on_bar, menu) = listed(&mut app);
|
||||
for label in ["Unite", "Duplicate"] {
|
||||
assert!(!on_bar.iter().any(|t| t == label) && menu.iter().any(|t| t == label), "{label} in More Options: {menu:?}");
|
||||
}
|
||||
show_action(&mut app, "unite", false);
|
||||
let (on_bar, menu) = listed(&mut app);
|
||||
assert!(!on_bar.iter().any(|t| t == "Unite") && !menu.iter().any(|t| t == "Unite"), "{on_bar:?} {menu:?}");
|
||||
assert!(on_bar.iter().chain(&menu).any(|t| t == "Duplicate"), "Duplicate is still offered: {on_bar:?} {menu:?}");
|
||||
}
|
||||
|
||||
/// Every action and chip the bar offers, for every kind of selection and tool, has an id in Bar
|
||||
/// 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 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");
|
||||
let line = |app: &mut VectorcraftApp| {
|
||||
id(app.run("path.create", json!({"anchors": [{"x": 50, "y": 200}, {"x": 150, "y": 80}, {"x": 250, "y": 200}]})).unwrap())
|
||||
};
|
||||
let two = |app: &mut VectorcraftApp| {
|
||||
let a = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 120, "height": 100})).unwrap());
|
||||
let b = id(app.run("shape.ellipse", json!({"x": 70, "y": 60, "width": 50, "height": 50})).unwrap());
|
||||
select(app, &[a, b]);
|
||||
};
|
||||
type Setup<'a> = Box<dyn Fn(&mut VectorcraftApp) + 'a>;
|
||||
let cases: Vec<(&str, Setup, &[&str])> = vec![
|
||||
(
|
||||
"an open path",
|
||||
Box::new(|app| {
|
||||
let l = line(app);
|
||||
select(app, &[l]);
|
||||
}),
|
||||
&["join", "editPath", "offsetPath", "simplify", "duplicate"],
|
||||
),
|
||||
(
|
||||
"a path the Direct Selection tool selects whole",
|
||||
Box::new(|app| {
|
||||
let l = line(app);
|
||||
select(app, &[l]);
|
||||
app.run("tool.select", json!({"tool": "directSelection"})).unwrap();
|
||||
}),
|
||||
&["join", "convertToCorner", "convertToSmooth", "simplify", "smooth", "duplicate"],
|
||||
),
|
||||
(
|
||||
"anchors picked out",
|
||||
Box::new(|app| {
|
||||
let l = line(app);
|
||||
app.run("tool.select", json!({"tool": "directSelection"})).unwrap();
|
||||
app.run("select.anchors", json!({"id": l, "anchors": [[0, 1]]})).unwrap();
|
||||
}),
|
||||
&["removeAnchorPoints", "join", "cutPath", "convertToCorner", "convertToSmooth"],
|
||||
),
|
||||
("two paths", Box::new(|app| two(app)), &["group", "unite", "duplicate"]),
|
||||
(
|
||||
"a group",
|
||||
Box::new(|app| {
|
||||
two(app);
|
||||
app.run("object.group", json!({})).unwrap();
|
||||
}),
|
||||
&["ungroup", "isolate", "duplicate"],
|
||||
),
|
||||
(
|
||||
"a compound path",
|
||||
Box::new(|app| {
|
||||
two(app);
|
||||
app.run("object.compoundPath.make", json!({})).unwrap();
|
||||
}),
|
||||
&["editPath", "releaseCompoundPath", "duplicate"],
|
||||
),
|
||||
(
|
||||
"a clipping group",
|
||||
Box::new(|app| {
|
||||
two(app);
|
||||
let g = id(app.run("object.clippingMask.make", json!({})).unwrap());
|
||||
select(app, &[g]);
|
||||
}),
|
||||
&["editClippingPath", "releaseClippingMask", "duplicate"],
|
||||
),
|
||||
(
|
||||
"point type",
|
||||
Box::new(|app| {
|
||||
let t = id(app.run("text.create", json!({"x": 60, "y": 80, "text": "Hello"})).unwrap());
|
||||
select(app, &[t]);
|
||||
}),
|
||||
&["createOutlines", "convertToAreaType", "dynamicText", "fill", "stroke", "lock"],
|
||||
),
|
||||
(
|
||||
"the Type tool with type selected",
|
||||
Box::new(|app| {
|
||||
let t = id(app.run("text.create", json!({"x": 60, "y": 80, "text": "Hello"})).unwrap());
|
||||
select(app, &[t]);
|
||||
app.run("tool.select", json!({"tool": "type"})).unwrap();
|
||||
}),
|
||||
&["fill"],
|
||||
),
|
||||
(
|
||||
"the Type tool editing type",
|
||||
Box::new(|app| {
|
||||
edited_type(app, "type");
|
||||
}),
|
||||
&["fill"],
|
||||
),
|
||||
(
|
||||
"area type",
|
||||
Box::new(|app| {
|
||||
let t = id(app.run("text.create", json!({"x": 60, "y": 80, "text": "Hello"})).unwrap());
|
||||
select(app, &[t]);
|
||||
app.run("type.convertToAreaType", json!({})).unwrap();
|
||||
select(app, &[t]);
|
||||
}),
|
||||
&["createOutlines", "convertToPointType", "dynamicText"],
|
||||
),
|
||||
(
|
||||
"type on a closed path",
|
||||
Box::new(|app| {
|
||||
let circle = id(app.run("path.create", json!({"d": "M100 300 A100 100 0 1 1 300 300 A100 100 0 1 1 100 300 Z"})).unwrap());
|
||||
let t = id(app.run("text.createInPath", json!({"path": circle, "mode": "onPath", "text": "Round", "at": [90, 300]})).unwrap());
|
||||
select(app, &[t]);
|
||||
}),
|
||||
&["createOutlines", "typeOnPathOptions", "centerOnTop", "centerOnBottom", "dynamicText"],
|
||||
),
|
||||
(
|
||||
"an Image Trace object",
|
||||
Box::new(|app| {
|
||||
place_image(app, &dir);
|
||||
app.run("imageTrace.make", json!({"params": {}})).unwrap();
|
||||
}),
|
||||
&["expand", "duplicate"],
|
||||
),
|
||||
(
|
||||
"an image",
|
||||
Box::new(|app| {
|
||||
place_image(app, &dir);
|
||||
}),
|
||||
&["imageTrace", "cropImage", "removeBackground", "duplicate"],
|
||||
),
|
||||
(
|
||||
"an image with a path",
|
||||
Box::new(|app| {
|
||||
let img = place_image(app, &dir);
|
||||
let r = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 80, "height": 60})).unwrap());
|
||||
select(app, &[img, r]);
|
||||
}),
|
||||
&["group", "makeClippingMask", "duplicate"],
|
||||
),
|
||||
(
|
||||
"a blank canvas",
|
||||
Box::new(|app| {
|
||||
let board = app.session.active().unwrap().doc.artboards[0].rect;
|
||||
bar(app);
|
||||
let view = app.view_mut().unwrap();
|
||||
(view.center, view.zoom) = (board.center(), 0.5);
|
||||
}),
|
||||
&["drawPencil", "placeImage"],
|
||||
),
|
||||
(
|
||||
"a shape tool after drawing",
|
||||
Box::new(|app| {
|
||||
drag_with(app, "rectangle", (60.0, 60.0), (120.0, 120.0));
|
||||
}),
|
||||
&["editPath"],
|
||||
),
|
||||
(
|
||||
"the Smooth tool",
|
||||
Box::new(|app| {
|
||||
let e = id(app.run("shape.ellipse", json!({"x": 60, "y": 60, "width": 120, "height": 80})).unwrap());
|
||||
select(app, &[e]);
|
||||
app.run("tool.select", json!({"tool": "smooth"})).unwrap();
|
||||
}),
|
||||
&["fidelity", "smoothToolOptions"],
|
||||
),
|
||||
(
|
||||
"the Artboard tool",
|
||||
Box::new(|app| {
|
||||
app.run("artboard.new", json!({"x": 420, "y": 0, "width": 200, "height": 200})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "artboard"})).unwrap();
|
||||
}),
|
||||
&["resizeArtboard", "duplicateArtboards", "rearrangeArtboards", "exportArtboards"],
|
||||
),
|
||||
];
|
||||
for (case, setup, expected) in cases {
|
||||
let mut app = app();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
setup(&mut app);
|
||||
let (ctx, _) = bar(&mut app);
|
||||
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");
|
||||
}
|
||||
let ids: Vec<&str> = offered.iter().filter_map(|(_, a)| *a).collect();
|
||||
for action in expected.iter() {
|
||||
assert!(ids.contains(action), "{case}: {action} in {ids:?}");
|
||||
}
|
||||
for action in &ids {
|
||||
show_action(&mut app, action, false);
|
||||
}
|
||||
let (ctx, texts) = bar_texts(&mut app);
|
||||
for (label, _) in &offered {
|
||||
assert!(!has(&texts, label), "{case}: {label} is off: {texts:?}");
|
||||
}
|
||||
// The bar still shows, with More Options, where Bar Actions turns them back on.
|
||||
assert!(canvas::task_bar_rect(&ctx).is_some(), "{case}: the bar still shows");
|
||||
let names: Vec<String> = buttons(&mut app).1.into_iter().map(|(n, _)| n).collect();
|
||||
assert!(names.iter().any(|n| n == "More Options"), "{case}: {names:?}");
|
||||
for (label, _) in &offered {
|
||||
assert!(!names.iter().any(|n| n == label), "{case}: {label} is off: {names:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bar Actions lists a field's name without its colon, as each language writes it, and an item
|
||||
/// that opens a dialog without its ellipsis.
|
||||
#[test]
|
||||
fn bar_actions_list_names_without_a_colon_or_an_ellipsis() {
|
||||
let lang = |code| crate::i18n::Lang::from_code(code).unwrap();
|
||||
for (code, label, name) in
|
||||
[("en", "Fidelity:", "Fidelity"), ("en", "Tool Options…", "Tool Options"), ("fr", "Fidelity:", "Fidélité"), ("ja", "Fidelity:", "精度")]
|
||||
.into_iter()
|
||||
.chain([("zh-hans", "Fidelity:", "精确度"), ("zh-hant", "Fidelity:", "精確度"), ("zh-hans", "Tool Options…", "工具选项")])
|
||||
{
|
||||
let label = crate::i18n::tr(lang(code), label);
|
||||
assert_eq!(canvas::bar_action_name(label), name, "{code}: {label:?}");
|
||||
}
|
||||
assert_eq!(canvas::bar_action_name("Duplicate"), "Duplicate");
|
||||
assert_eq!(canvas::bar_action_name("Tool Options..."), "Tool Options");
|
||||
assert_eq!(canvas::bar_action_name("Offset Path."), "Offset Path.");
|
||||
// The colon and the ellipsis go in either order, with or without a space between them.
|
||||
for label in [
|
||||
"Tool Options...:",
|
||||
"Tool Options... :",
|
||||
"Tool Options: ...",
|
||||
"Tool Options …:",
|
||||
"Tool Options… :",
|
||||
"Tool Options…\u{a0}:",
|
||||
"Tool Options...\u{202f}:",
|
||||
] {
|
||||
assert_eq!(canvas::bar_action_name(label), "Tool Options", "{label:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ pub use drag::{
|
||||
};
|
||||
#[cfg(test)]
|
||||
use dropdowns::combo_button_id;
|
||||
#[cfg(test)]
|
||||
pub(crate) use dropdowns::top_popup_shapes;
|
||||
pub(crate) use dropdowns::{combo, combo_menu, combo_menu_field_named, combo_named, field_focused_in, menu_min_width, popover_is_open};
|
||||
pub use dropdowns::{
|
||||
dropdown, dropdown_icon_names, dropdown_icon_names_sized, dropdown_named, dropdown_names, dropdown_names_named, dropdown_with,
|
||||
|
||||
@@ -149,9 +149,10 @@ fn option_row<'a>(ui: &mut Ui, enabled: bool, selected: bool, atoms: impl egui::
|
||||
response
|
||||
}
|
||||
|
||||
/// The id [`craft_ui::ComboBox::from_id_salt`] gives its button in this `Ui`: `from_id_salt`
|
||||
/// stores `IdSalt::new(salt)` and hashes it once more with the scope, so the app must hash `id`
|
||||
/// the same way to read the button's focus and open state before it is drawn.
|
||||
/// The id of the button of [`combo_atoms_named`] in this `Ui`, the one
|
||||
/// [`craft_ui::ComboBox::from_id_salt`] gives its button: `from_id_salt` stores
|
||||
/// `IdSalt::new(salt)` and hashes it once more with the scope. The app reads the button's focus and
|
||||
/// open state with it before the button is drawn.
|
||||
pub(super) fn combo_button_id(ui: &Ui, id: &impl std::hash::Hash) -> egui::Id {
|
||||
ui.make_persistent_id(egui::IdSalt::new(HashOnly(id)))
|
||||
}
|
||||
@@ -206,9 +207,8 @@ fn combo_atoms_named<'a, R>(
|
||||
if opening {
|
||||
ui.data_mut(|d| d.insert_temp(opened_key, pass));
|
||||
}
|
||||
// The menu measures itself against the whole screen on the pass it opens and takes
|
||||
// the room beside its field on the next one, so the current option is scrolled into
|
||||
// view on both.
|
||||
// The list is laid out unseen to measure it on the pass it opens and placed on the
|
||||
// next one, so the current option is scrolled into view on both.
|
||||
let settling = ui.data(|d| d.get_temp::<u64>(opened_key)).is_some_and(|p| pass <= p + 1);
|
||||
// A list drawn inside this one's rows finds its own record, and this one's comes back after it.
|
||||
let outer = if settling { OPENING.replace(Some(Opening::default())) } else { OPENING.take() };
|
||||
@@ -238,17 +238,14 @@ fn combo_atoms_named<'a, R>(
|
||||
chosen
|
||||
};
|
||||
let enter_for_combo = ui.memory(|m| m.has_focus(button_id)) || craft_ui::ComboBox::is_open(ui.ctx(), button_id);
|
||||
let response = craft_ui::ComboBox::from_id_salt(HashOnly(&id))
|
||||
.selected_text(current)
|
||||
.width(width - 4.0)
|
||||
.height(ui.spacing().combo_height)
|
||||
.show_ui(ui, list);
|
||||
let response = combo_button(ui, button_id, current, width - 4.0);
|
||||
let shown = combo_list(ui, &response, list);
|
||||
// The button or open list handles Enter before the modal can accept it.
|
||||
if enter_for_combo {
|
||||
ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter));
|
||||
}
|
||||
let _ = name_field(label_field(response.response.clone(), label), name);
|
||||
let chosen = response.inner.flatten();
|
||||
let _ = name_field(label_field(response, label), name);
|
||||
let chosen = shown.flatten();
|
||||
// egui closes the list on a click of the pointer only: an option picked with Space or
|
||||
// Enter closes it here, and the combo gives the keyboard back, so that Enter reaches the
|
||||
// dialog's OK (#2789).
|
||||
@@ -261,6 +258,178 @@ fn combo_atoms_named<'a, R>(
|
||||
.inner
|
||||
}
|
||||
|
||||
/// The button of [`combo_atoms_named`] with the id `button_id`, at least `width` wide, showing
|
||||
/// `current`: [`craft_ui::ComboBox`]'s button, with its look, its tooltip for a value cut short and
|
||||
/// its role for screen readers. It is drawn here so that its list opens in [`combo_list`].
|
||||
fn combo_button<'a>(ui: &mut Ui, button_id: egui::Id, current: impl egui::IntoAtoms<'a>, width: f32) -> Response {
|
||||
use egui::class::HasClasses as _;
|
||||
use egui::{AtomExt as _, NumExt as _};
|
||||
let open = egui::Popup::is_id_open(ui.ctx(), button_id.with("popup"));
|
||||
let mut classes = egui::class::Classes::default();
|
||||
classes.add_class(craft_ui::ComboBox::CLASS);
|
||||
classes.set_class(craft_ui::ComboBox::CLASS_OPEN, open);
|
||||
let egui::widget_style::ButtonStyle { atom_layout } = ui.widget_style(button_id, &classes);
|
||||
let visuals = if open {
|
||||
ui.visuals().widgets.open
|
||||
} else if let Some(response) = ui.ctx().read_response(button_id) {
|
||||
*ui.style().interact(&response)
|
||||
} else {
|
||||
ui.visuals().widgets.inactive
|
||||
};
|
||||
let min_size = vec2(width, 0.0).at_least(atom_layout.min_size);
|
||||
let current = current.into_atoms();
|
||||
let text = current.text().map(String::from).unwrap_or_default();
|
||||
let rtl = ui.style().right_to_left;
|
||||
// The combo box's arrow: a downward triangle.
|
||||
let arrow = egui::Atom::paint(Vec2::splat(ui.spacing().icon_width), move |ui, args| {
|
||||
let rect = args.rect.expand(visuals.expansion);
|
||||
let rect = Rect::from_center_size(rect.center(), vec2(rect.width() * 0.7, rect.height() * 0.45));
|
||||
ui.painter().add(egui::Shape::rotated_triangle(rect, 0.0, visuals.fg_stroke.color));
|
||||
})
|
||||
.atom_grow(true)
|
||||
.atom_align(if rtl { egui::Align2::LEFT_CENTER } else { egui::Align2::RIGHT_CENTER });
|
||||
let button = atom_layout
|
||||
.apply(
|
||||
egui::WidgetAtom::new((current, arrow))
|
||||
.id(button_id)
|
||||
.sense(Sense::click())
|
||||
.fallback_font(egui::TextStyle::Button)
|
||||
.wrap_mode(ui.wrap_mode())
|
||||
.direction(if rtl { egui::Direction::RightToLeft } else { egui::Direction::LeftToRight }),
|
||||
)
|
||||
.min_size(min_size)
|
||||
.measure(ui, ui.available_size());
|
||||
let elided = button.container.iter_texts().any(|galley| galley.elided);
|
||||
let response = button.allocate(ui).paint(ui).response;
|
||||
// A value cut short shows in full on hover, as a truncated `Label`'s does.
|
||||
let response = if elided {
|
||||
response.on_hover_ui(|ui| {
|
||||
ui.set_max_width(ui.spacing().tooltip_width);
|
||||
ui.add(egui::Label::new(text.as_str()).wrap());
|
||||
})
|
||||
} else {
|
||||
response
|
||||
};
|
||||
response.widget_info(|| egui::WidgetInfo {
|
||||
enabled: ui.is_enabled(),
|
||||
current_text_value: Some(text.clone()),
|
||||
..egui::WidgetInfo::new(egui::Role::ComboBox)
|
||||
});
|
||||
response
|
||||
}
|
||||
|
||||
/// The list of [`combo_atoms_named`] while it is open, drawn by `list` in a popup of its own that
|
||||
/// opens from `button` and takes the whole list whenever the window has room for it (#5941): below
|
||||
/// the button when it fits there, above it when it fits there instead, and otherwise moved up from
|
||||
/// below, over the button, until it ends at the bottom bars. It stays above the bottom bars
|
||||
/// ([`menu_floor`]), and a list taller than the room above them scrolls. A click closes
|
||||
/// the list, except a click on its scroll bar, which scrolls it. Returns what `list` returned, or
|
||||
/// `None` while the list is closed.
|
||||
fn combo_list<R>(ui: &Ui, button: &Response, list: impl FnOnce(&mut Ui) -> R) -> Option<R> {
|
||||
let ctx = ui.ctx();
|
||||
let id = button.id.with("popup");
|
||||
let style = egui::style::StyleModifier::new(|style| {
|
||||
egui::containers::menu::menu_style(style);
|
||||
style.spacing.scroll = list_scroll_style();
|
||||
});
|
||||
// The id of the list's scroll area. egui senses its vertical bar under the area's id with the
|
||||
// axis, 1, and names the widget a click went to at the start of the pass.
|
||||
let area_key = id.with("scroll-area-id");
|
||||
let on_bar =
|
||||
ctx.data(|d| d.get_temp::<egui::Id>(area_key)).is_some_and(|area| ctx.interaction_snapshot(|s| s.clicked == Some(area.with(1_usize))));
|
||||
let close = if on_bar { egui::PopupCloseBehavior::IgnoreClicks } else { egui::PopupCloseBehavior::CloseOnClick };
|
||||
let popup = egui::Popup::menu(button).id(id).width(button.rect.width()).style(style.clone()).close_behavior(close);
|
||||
let screen = ctx.content_rect();
|
||||
// The list stops above the bottom bars, as other menus do (#2086).
|
||||
let floor = menu_floor(ctx).min(screen.bottom());
|
||||
// The room on each side of the rect the popup opens from: the part of the button in view.
|
||||
let anchor = popup.get_anchor_rect().unwrap_or(button.rect);
|
||||
let below = floor - anchor.bottom();
|
||||
let above = anchor.top() - screen.top();
|
||||
// The list's size from its last pass: egui lays a popup out unseen on the pass it opens, so the
|
||||
// list is measured before it is placed. A right-to-left layout lines the list up with the
|
||||
// button's right edge, as egui's menus do.
|
||||
let rtl = ui.style().right_to_left;
|
||||
let expected = popup.get_expected_size();
|
||||
let (align, popup) = match expected {
|
||||
Some(size) if size.y > below && size.y <= above => (if rtl { egui::RectAlign::TOP_END } else { egui::RectAlign::TOP_START }, popup),
|
||||
// A list too tall for either side moves up from below until it ends at the floor.
|
||||
Some(size) if size.y > below => {
|
||||
let top = (floor - size.y).max(screen.top());
|
||||
let from = Rect::from_min_max(egui::pos2(anchor.left(), top), egui::pos2(anchor.right(), top));
|
||||
(if rtl { egui::RectAlign::BOTTOM_END } else { egui::RectAlign::BOTTOM_START }, popup.anchor(from))
|
||||
}
|
||||
_ => (if rtl { egui::RectAlign::BOTTOM_END } else { egui::RectAlign::BOTTOM_START }, popup),
|
||||
};
|
||||
let mut popup_style = (*ctx.global_style()).clone();
|
||||
style.apply(&mut popup_style);
|
||||
let margins = egui::Frame::popup(&popup_style).total_margin().sum();
|
||||
let height = (floor - screen.top() - margins.y).max(ui.spacing().interact_size.y);
|
||||
// A list that was wider than the window keeps its scroll bar in view: until it closes, it is no
|
||||
// wider than it measured or than the window, its names cut short and shown in full on hover.
|
||||
// Only a size measured while the list is open counts: egui keeps the last one after it closes.
|
||||
// The width it needs is its rows' width on the last pass before it was narrowed, with its
|
||||
// margins, and the bar's column while the rows scroll.
|
||||
let too_wide_key = id.with("too-wide");
|
||||
let natural_key = id.with("natural-width");
|
||||
let scrolls_key = id.with("scrolls");
|
||||
let open_last_pass = ctx.read_response(id).is_some();
|
||||
if popup.get_expected_size().is_some_and(|size| open_last_pass && size.x > screen.width()) {
|
||||
// The first measurement is kept: later ones are of the list already narrowed.
|
||||
ctx.data_mut(|d| {
|
||||
if d.get_temp::<f32>(too_wide_key).is_none() {
|
||||
let rows = d.get_temp::<f32>(natural_key).unwrap_or(screen.width());
|
||||
d.insert_temp(too_wide_key, rows);
|
||||
}
|
||||
});
|
||||
}
|
||||
let (measured, scrolls) = ctx.data(|d| (d.get_temp::<f32>(too_wide_key), d.get_temp::<bool>(scrolls_key).unwrap_or(false)));
|
||||
let too_wide = measured.is_some();
|
||||
let shown = popup.align(align).align_alternatives(&[]).show(|ui| {
|
||||
if let Some(rows) = measured {
|
||||
let bar = if scrolls { list_scroll_style().allocated_width() } else { 0.0 };
|
||||
ui.set_max_width((rows + bar).min(screen.width() - margins.x).max(0.0));
|
||||
}
|
||||
ui.set_min_width(ui.available_width());
|
||||
// A popup offers its contents the height it had on its last pass; the list is offered the
|
||||
// window's instead.
|
||||
ui.set_max_height(height);
|
||||
// Labels widen a narrow list rather than wrap, as in egui's combo box.
|
||||
ui.style_mut().wrap_mode = Some(if too_wide { egui::TextWrapMode::Truncate } else { egui::TextWrapMode::Extend });
|
||||
let painted = ui.ctx().graphics(|g| g.get(ui.layer_id()).map_or(0, |shapes| shapes.all_entries().len()));
|
||||
let shown = egui::ScrollArea::vertical().max_height(height).show(ui, list);
|
||||
if too_wide {
|
||||
show_shortened_rows(ui, painted);
|
||||
}
|
||||
ui.data_mut(|d| {
|
||||
if !too_wide {
|
||||
d.insert_temp(natural_key, shown.content_size.x);
|
||||
}
|
||||
d.insert_temp(scrolls_key, shown.content_size.y > shown.inner_rect.height());
|
||||
d.insert_temp(area_key, shown.id);
|
||||
});
|
||||
shown.inner
|
||||
});
|
||||
if shown.is_some() {
|
||||
ctx.accesskit_node_builder(id, |node| node.set_role(egui::Role::ListBox));
|
||||
} else {
|
||||
ctx.data_mut(|d| {
|
||||
d.remove::<f32>(too_wide_key);
|
||||
d.remove::<f32>(natural_key);
|
||||
d.remove::<bool>(scrolls_key);
|
||||
});
|
||||
}
|
||||
shown.map(|r| r.inner)
|
||||
}
|
||||
|
||||
/// The shapes painted so far in this pass on the topmost popup that was shown in the last one, such
|
||||
/// as an open dropdown list, without what lies under it. Read at the end of a test's UI.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn top_popup_shapes(ctx: &egui::Context) -> Vec<egui::epaint::ClippedShape> {
|
||||
let top = ctx.memory(|m| m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last());
|
||||
top.map_or_else(Vec::new, |layer| ctx.graphics(|g| g.get(layer).map(|p| p.all_entries().cloned().collect()).unwrap_or_default()))
|
||||
}
|
||||
|
||||
/// The recessed combo box of [`dropdown`] showing `current`, whose menu keeps a search field and
|
||||
/// filters in place over a list that scrolls (the font menu and the shortcut import's target
|
||||
/// picker, #555). `menu` shows the menu with one of [`craft_ui::combo::Menu`]'s header forms and
|
||||
|
||||
@@ -133,10 +133,13 @@ fn a_dropdown_in_a_short_window_opens_with_its_current_option_in_view() {
|
||||
for (height, above, current) in [(260.0, 117.0, 19), (260.0, 117.0, 10), (180.0, 77.0, 10), (180.0, 77.0, 3)] {
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(above);
|
||||
field.set(ui.horizontal(|ui| dropdown_names(ui, "short-list", labels[current], &labels, 160.0)).response.rect);
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
// The shapes of the open list, without the field under it.
|
||||
let mut run = |time: f64, events: Vec<egui::Event>| {
|
||||
let raw = egui::RawInput {
|
||||
time: Some(time),
|
||||
@@ -146,7 +149,7 @@ fn a_dropdown_in_a_short_window_opens_with_its_current_option_in_view() {
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, &mut add);
|
||||
out.textures_delta.clear();
|
||||
out.shapes
|
||||
popup.take()
|
||||
};
|
||||
run(0.0, vec![]);
|
||||
let at = field.get().center();
|
||||
@@ -206,6 +209,7 @@ fn own_rows_reopen(height: f32, above: f32, wheel: f32, row: &str) {
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let current = std::cell::RefCell::new(String::from("Row 00"));
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(above);
|
||||
let shown = current.borrow().clone();
|
||||
@@ -224,8 +228,10 @@ fn own_rows_reopen(height: f32, above: f32, wheel: f32, row: &str) {
|
||||
current.replace(items[i].clone());
|
||||
}
|
||||
field.set(r.response.rect);
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
let mut time = 0.0;
|
||||
// The shapes of the open list, without the field under it.
|
||||
let mut run = |events: Vec<egui::Event>| {
|
||||
time += 0.1;
|
||||
let raw = egui::RawInput {
|
||||
@@ -236,7 +242,7 @@ fn own_rows_reopen(height: f32, above: f32, wheel: f32, row: &str) {
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, &mut add);
|
||||
out.textures_delta.clear();
|
||||
out.shapes
|
||||
popup.take()
|
||||
};
|
||||
// The rows that show whole, with their tops: inside the open list and the clip they are painted
|
||||
// in.
|
||||
@@ -298,10 +304,12 @@ fn own_rows_reopen(height: f32, above: f32, wheel: f32, row: &str) {
|
||||
}
|
||||
let scrolled = rows(clipped);
|
||||
assert!(has(&scrolled, row), "{case}: the wheel scrolls {row} into view: {scrolled:?}");
|
||||
// Closed and opened again twice: each time its rows are where they were when it closed.
|
||||
// Closed and opened again twice: each time its rows are where they were when it closed. Escape
|
||||
// closes it: a list taller than the room beside its field covers the field.
|
||||
let escape = |pressed| egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
for time in ["first", "second"] {
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![escape(true)]);
|
||||
run(vec![escape(false)]);
|
||||
run(vec![]);
|
||||
let reopened = rows(open(&mut run));
|
||||
assert_eq!(reopened, scrolled, "{case}: the list opens again where it was scrolled, the {time} time");
|
||||
@@ -804,6 +812,517 @@ fn kerning_reads_parentheses_around_its_text_with_a_manual_value_too() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Long dropdown lists use the window's room instead of stopping at `combo_height` (200 pt), and
|
||||
/// show a solid scroll bar without hovering when the list still overflows.
|
||||
#[test]
|
||||
fn a_long_dropdown_uses_window_room_and_shows_its_scroll_bar_when_clipped() {
|
||||
let items: Vec<String> = (0..20).map(|i| format!("Format {i:02}")).collect();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let run = |win_h: f32| {
|
||||
let ctx = themed(Default::default());
|
||||
let button_rect = std::cell::Cell::new(Rect::NOTHING);
|
||||
let mut draw = |ui: &mut Ui| {
|
||||
ui.add_space(16.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(16.0);
|
||||
let before = ui.next_widget_position();
|
||||
let _ = dropdown_names(ui, "long-formats", labels[0], &labels, 160.0);
|
||||
button_rect.set(Rect::from_min_size(before, vec2(160.0, 26.0)));
|
||||
});
|
||||
};
|
||||
let mut step = |time: f64, events: Vec<egui::Event>| {
|
||||
let raw = egui::RawInput {
|
||||
time: Some(time),
|
||||
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, win_h))),
|
||||
events,
|
||||
..Default::default()
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, &mut draw);
|
||||
out.textures_delta.clear();
|
||||
out.shapes
|
||||
};
|
||||
step(0.0, vec![]);
|
||||
let at = button_rect.get().center();
|
||||
let click = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
step(0.1, vec![egui::Event::PointerMoved(at), click(true)]);
|
||||
step(0.2, vec![click(false)]);
|
||||
// Move the pointer away so the scroll bar is dormant, not hovered, and let the popup settle.
|
||||
step(0.3, vec![egui::Event::PointerMoved(pos2(350.0, 10.0))]);
|
||||
let mut clipped = vec![];
|
||||
for i in 4..10 {
|
||||
clipped = step(f64::from(i) * 0.1, vec![]);
|
||||
}
|
||||
(ctx, clipped)
|
||||
};
|
||||
|
||||
// In a tall window, all 20 items show without stopping at the 200 pt cap.
|
||||
let (_tall_ctx, tall_shapes) = run(720.0);
|
||||
let mut texts = vec![];
|
||||
fn collect_text(s: &egui::Shape, out: &mut Vec<String>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| collect_text(s, out)),
|
||||
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for c in &tall_shapes {
|
||||
collect_text(&c.shape, &mut texts);
|
||||
}
|
||||
assert!(texts.iter().any(|t| t == "Format 19"), "the 20th option is shown without scrolling: {texts:?}");
|
||||
|
||||
// In a short window where the list overflows, a solid scroll bar is drawn even while dormant.
|
||||
let (short_ctx, short_shapes) = run(220.0);
|
||||
let mut short_texts = vec![];
|
||||
for c in &short_shapes {
|
||||
collect_text(&c.shape, &mut short_texts);
|
||||
}
|
||||
assert!(!short_texts.iter().any(|t| t == "Format 19"), "the list overflows the 220 pt window");
|
||||
let popup = short_ctx
|
||||
.memory(|m| m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id)))
|
||||
.expect("the popup is open");
|
||||
let mut bar_rects = vec![];
|
||||
fn collect_rects(s: &egui::Shape, out: &mut Vec<egui::epaint::RectShape>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| collect_rects(s, out)),
|
||||
egui::Shape::Rect(r) => out.push(r.clone()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for c in &short_shapes {
|
||||
collect_rects(&c.shape, &mut bar_rects);
|
||||
}
|
||||
let has_scroll_bar = bar_rects.iter().any(|r| {
|
||||
r.fill != Color32::TRANSPARENT
|
||||
&& r.rect.width() <= list_scroll_style().bar_width + 1.0
|
||||
&& r.rect.height() >= 12.0
|
||||
&& r.rect.height() < popup.height()
|
||||
&& r.rect.right() <= popup.right()
|
||||
&& r.rect.left() >= popup.right() - list_scroll_style().allocated_width() - 8.0
|
||||
});
|
||||
assert!(has_scroll_bar, "the overflowing dropdown draws its scroll bar without hover in {popup:?}");
|
||||
}
|
||||
|
||||
// #5941: a drop-down list stopped at the room on one side of its field, so a window with room for
|
||||
// the whole list still cut it short. The list opens below its field when it fits there, above it
|
||||
// when it fits there instead, and otherwise moves up from below into the window over its field;
|
||||
// each time every option shows whole, inside the window.
|
||||
#[test]
|
||||
fn a_dropdown_list_shows_every_option_when_the_window_has_room() {
|
||||
let items: Vec<String> = (0..20).map(|i| format!("Option {i:02}")).collect();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
// (window height, space above the field, where the list goes)
|
||||
for (height, above, side) in [(700.0, 16.0, "below"), (700.0, 650.0, "above"), (640.0, 300.0, "over")] {
|
||||
let case = format!("{height} pt window, field {above} pt down");
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(above);
|
||||
field.set(ui.horizontal(|ui| dropdown_names(ui, "fit-list", labels[0], &labels, 160.0)).response.rect);
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, vec2(400.0, height));
|
||||
// The shapes of the open list, without the field under it.
|
||||
let mut run = |time: f64, events: Vec<egui::Event>| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect: Some(screen), events, ..Default::default() }, &mut add);
|
||||
out.textures_delta.clear();
|
||||
popup.take()
|
||||
};
|
||||
run(0.0, vec![]);
|
||||
let at = field.get().center();
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(0.1, vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(0.2, vec![press(false)]);
|
||||
run(0.3, vec![egui::Event::PointerMoved(pos2(390.0, 2.0))]);
|
||||
let mut clipped = vec![];
|
||||
for i in 4..10 {
|
||||
clipped = run(f64::from(i) * 0.1, vec![]);
|
||||
}
|
||||
let list = ctx
|
||||
.memory(|m| {
|
||||
m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id))
|
||||
})
|
||||
.expect("the list is open");
|
||||
assert!(screen.contains_rect(list), "{case}: the list {list:?} is inside the window");
|
||||
let field = field.get();
|
||||
// The list opens from the button, 1 pt inside the field's border.
|
||||
match side {
|
||||
"below" => assert!(list.top() >= field.bottom() - 1.5, "{case}: the list {list:?} opens below the field {field:?}"),
|
||||
"above" => assert!(list.bottom() <= field.top() + 1.5, "{case}: the list {list:?} opens above the field {field:?}"),
|
||||
_ => assert!(list.top() < field.bottom() && list.bottom() > field.top(), "{case}: the list {list:?} covers the field {field:?}"),
|
||||
}
|
||||
let mut texts = vec![];
|
||||
fn flat(s: &egui::Shape, clip: Rect, out: &mut Vec<(String, Rect, Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| flat(s, clip, out)),
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().to_owned(), t.visual_bounding_rect(), clip)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
clipped.iter().for_each(|c| flat(&c.shape, c.clip_rect, &mut texts));
|
||||
let whole: Vec<&str> = labels
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|name| {
|
||||
texts.iter().any(|(s, r, clip)| s == name && list.contains_rect(*r) && r.top() >= clip.top() && r.bottom() <= clip.bottom())
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(whole, labels, "{case}: every option shows whole in {list:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// #5941: a drop-down list stops above the bottom bars, as other menus do (#2086). In a 700 pt window
|
||||
// whose bars start at 640 pt, the list opens below a field near the top, and from a field in the
|
||||
// middle it moves up over the field until it ends at the bars; each time every option shows whole.
|
||||
#[test]
|
||||
fn a_dropdown_list_stops_above_the_bottom_bars() {
|
||||
let items: Vec<String> = (0..20).map(|i| format!("Option {i:02}")).collect();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let floor = 640.0;
|
||||
for above in [16.0, 300.0] {
|
||||
let case = format!("field {above} pt down");
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
set_menu_floor(ui.ctx(), floor);
|
||||
ui.add_space(above);
|
||||
field.set(ui.horizontal(|ui| dropdown_names(ui, "floor-list", labels[0], &labels, 160.0)).response.rect);
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, vec2(400.0, 700.0));
|
||||
let mut run = |time: f64, events: Vec<egui::Event>| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect: Some(screen), events, ..Default::default() }, &mut add);
|
||||
out.textures_delta.clear();
|
||||
popup.take()
|
||||
};
|
||||
run(0.0, vec![]);
|
||||
let at = field.get().center();
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(0.1, vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(0.2, vec![press(false)]);
|
||||
run(0.3, vec![egui::Event::PointerMoved(pos2(390.0, 2.0))]);
|
||||
let mut clipped = vec![];
|
||||
for i in 4..10 {
|
||||
clipped = run(f64::from(i) * 0.1, vec![]);
|
||||
}
|
||||
let list = ctx
|
||||
.memory(|m| {
|
||||
m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id))
|
||||
})
|
||||
.expect("the list is open");
|
||||
assert!(list.top() >= 0.0 && list.bottom() <= floor + 0.5, "{case}: the list {list:?} ends above the bars at {floor}");
|
||||
let mut texts = vec![];
|
||||
fn flat(s: &egui::Shape, clip: Rect, out: &mut Vec<(String, Rect, Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| flat(s, clip, out)),
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().to_owned(), t.visual_bounding_rect(), clip)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
clipped.iter().for_each(|c| flat(&c.shape, c.clip_rect, &mut texts));
|
||||
let whole: Vec<&str> = labels
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|name| {
|
||||
texts.iter().any(|(s, r, clip)| s == name && list.contains_rect(*r) && r.top() >= clip.top() && r.bottom() <= clip.bottom())
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(whole, labels, "{case}: every option shows whole in {list:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// #5941: a click on the scroll bar's track of an open drop-down list scrolls it and leaves it open,
|
||||
// so an option it scrolled into view can be picked. A list closed by that click would open again
|
||||
// with its current option in view.
|
||||
#[test]
|
||||
fn a_click_on_a_dropdown_lists_scroll_bar_scrolls_it_and_leaves_it_open() {
|
||||
let items: Vec<String> = (0..40).map(|i| format!("Option {i:02}")).collect();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let picked = std::cell::Cell::new(None);
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(16.0);
|
||||
let r = ui.horizontal(|ui| dropdown_names(ui, "bar-click", labels[0], &labels, 160.0));
|
||||
field.set(r.response.rect);
|
||||
if let Some(i) = r.inner {
|
||||
picked.set(Some(i));
|
||||
}
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0));
|
||||
let mut time = 0.0;
|
||||
// The options that show whole on the open list, with their rects, and the scroll bar's rects.
|
||||
let mut run = |events: Vec<egui::Event>| {
|
||||
time += 0.1;
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect: Some(screen), events, ..Default::default() }, &mut add);
|
||||
out.textures_delta.clear();
|
||||
let (mut texts, mut bars) = (vec![], vec![]);
|
||||
fn flat(s: &egui::Shape, clip: Rect, out: &mut Vec<(String, Rect)>, bars: &mut Vec<Rect>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| flat(s, clip, out, bars)),
|
||||
egui::Shape::Text(t) => {
|
||||
let r = t.visual_bounding_rect();
|
||||
if r.top() >= clip.top() && r.bottom() <= clip.bottom() {
|
||||
out.push((t.galley.text().to_owned(), r));
|
||||
}
|
||||
}
|
||||
egui::Shape::Rect(r) if r.fill.a() > 0 && r.rect.width() <= 8.0 && r.rect.height() > 40.0 => bars.push(r.rect),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
popup.take().iter().for_each(|c| flat(&c.shape, c.clip_rect, &mut texts, &mut bars));
|
||||
(texts, bars)
|
||||
};
|
||||
let list_rect = || {
|
||||
ctx.memory(|m| m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id)))
|
||||
};
|
||||
let click =
|
||||
|at: Pos2, pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(vec![]);
|
||||
let at = field.get().center();
|
||||
run(vec![egui::Event::PointerMoved(at), click(at, true)]);
|
||||
run(vec![click(at, false)]);
|
||||
let (mut before, mut bars) = (vec![], vec![]);
|
||||
for _ in 0..4 {
|
||||
(before, bars) = run(vec![]);
|
||||
}
|
||||
assert!(list_rect().is_some(), "the list is open");
|
||||
assert!(before.iter().any(|(s, _)| s == "Option 00"), "the list opens at its first option: {before:?}");
|
||||
// The track, below the handle: near the bottom of the tallest bar rect drawn (the track).
|
||||
let bar = bars
|
||||
.iter()
|
||||
.copied()
|
||||
.max_by(|a, b| a.height().total_cmp(&b.height()))
|
||||
.unwrap_or_else(|| panic!("the list {:?} draws its scroll bar: {before:?}", list_rect()));
|
||||
let track = pos2(bar.center().x, bar.bottom() - 6.0);
|
||||
run(vec![egui::Event::PointerMoved(track), click(track, true)]);
|
||||
run(vec![]);
|
||||
// The button is let go just past the bar's edge, closer than a drag, and the pointer then moves
|
||||
// sideways onto the rows, in the same pass.
|
||||
let let_go = pos2(bar.right() + 1.0, track.y);
|
||||
let onto_row = before.first().map(|(_, r)| pos2(r.center().x, track.y)).expect("a row shows");
|
||||
run(vec![egui::Event::PointerMoved(let_go), click(let_go, false), egui::Event::PointerMoved(onto_row)]);
|
||||
let mut after = vec![];
|
||||
for _ in 0..4 {
|
||||
(after, _) = run(vec![]);
|
||||
}
|
||||
assert!(list_rect().is_some(), "a click on the scroll bar leaves the list open");
|
||||
let new = after
|
||||
.iter()
|
||||
.find(|(s, _)| !before.iter().any(|(b, _)| b == s))
|
||||
.cloned()
|
||||
.unwrap_or_else(|| panic!("the click scrolled options into view: {after:?}"));
|
||||
let row = new.1.center();
|
||||
run(vec![egui::Event::PointerMoved(row), click(row, true)]);
|
||||
run(vec![click(row, false)]);
|
||||
run(vec![]);
|
||||
let index = labels.iter().position(|l| *l == new.0);
|
||||
assert_eq!(picked.get(), index, "the option scrolled into view is picked: {}", new.0);
|
||||
assert!(list_rect().is_none(), "picking an option closes the list");
|
||||
}
|
||||
|
||||
// #5941: a drop-down list with an option wider than the window ran past the window's right edge,
|
||||
// and its scroll bar with it. The list stays inside the window and its bar shows; the long option's
|
||||
// name is cut short.
|
||||
#[test]
|
||||
fn a_dropdown_list_wider_than_the_window_keeps_its_scroll_bar_in_view() {
|
||||
let mut items: Vec<String> = (0..40).map(|i| format!("Option {i:02}")).collect();
|
||||
items[1] = "Option 01, whose name is much wider than this window".into();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let short: Vec<&str> = labels.iter().copied().filter(|l| l.len() < 10).collect();
|
||||
let two: Vec<&str> = labels[..2].to_vec();
|
||||
// Which list the field offers: 0 all, 1 the short names, 2 the first two.
|
||||
let offered = std::cell::Cell::new(0);
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let popup = std::cell::RefCell::new(vec![]);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(16.0);
|
||||
let options = [&labels, &short, &two][offered.get()];
|
||||
field.set(ui.horizontal(|ui| dropdown_names(ui, "wide-list", options[0], options, 160.0)).response.rect);
|
||||
popup.replace(super::top_popup_shapes(ui.ctx()));
|
||||
};
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, vec2(220.0, 300.0));
|
||||
let window = std::cell::Cell::new(screen);
|
||||
let mut time = 0.0;
|
||||
// The texts painted on the open list with their clip rects, and the scroll bar's rects.
|
||||
let mut run = |events: Vec<egui::Event>| {
|
||||
time += 0.1;
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect: Some(window.get()), events, ..Default::default() }, &mut add);
|
||||
out.textures_delta.clear();
|
||||
let (mut texts, mut bars) = (vec![], vec![]);
|
||||
fn flat(s: &egui::Shape, clip: Rect, texts: &mut Vec<(String, bool)>, bars: &mut Vec<Rect>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| flat(s, clip, texts, bars)),
|
||||
egui::Shape::Text(t) => texts.push((t.galley.text().to_owned(), t.galley.elided)),
|
||||
egui::Shape::Rect(r) if r.fill.a() > 0 && r.rect.width() <= 8.0 && r.rect.height() > 40.0 => bars.push(r.rect.intersect(clip)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
popup.take().iter().for_each(|c| flat(&c.shape, c.clip_rect, &mut texts, &mut bars));
|
||||
(texts, bars)
|
||||
};
|
||||
run(vec![]);
|
||||
let at = field.get().center();
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![egui::Event::PointerMoved(pos2(210.0, 290.0))]);
|
||||
let (mut texts, mut bars) = (vec![], vec![]);
|
||||
for _ in 0..6 {
|
||||
(texts, bars) = run(vec![]);
|
||||
}
|
||||
let list_rect = || {
|
||||
ctx.memory(|m| m.layer_ids().filter(|l| l.order == egui::Order::Foreground && m.areas().is_visible(l)).last().and_then(|l| m.area_rect(l.id)))
|
||||
};
|
||||
let list = list_rect().expect("the list is open");
|
||||
assert!(screen.contains_rect(list), "the list {list:?} is inside the window");
|
||||
assert!(
|
||||
bars.iter().any(|b| b.width() > 0.0 && screen.contains_rect(*b) && list.contains_rect(*b)),
|
||||
"the bar shows in the list {list:?}: {bars:?}"
|
||||
);
|
||||
assert!(texts.iter().any(|(s, elided)| *elided && s.starts_with("Option 01")), "the long name is cut short: {texts:?}");
|
||||
// The window grows while the list is open: the list grows as wide as its names need, and no
|
||||
// wider.
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, vec2(1000.0, 300.0)));
|
||||
for _ in 0..6 {
|
||||
(texts, _) = run(vec![]);
|
||||
}
|
||||
let grown = list_rect().expect("the list is still open");
|
||||
assert!(grown.width() < 500.0, "the list {grown:?} stays as wide as its names need");
|
||||
assert!(texts.iter().any(|(s, elided)| !*elided && s == labels[1]), "the long name shows in full: {texts:?}");
|
||||
// Narrowed and widened again, it comes back to the same width.
|
||||
for size in [screen.size(), vec2(1000.0, 300.0)] {
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, size));
|
||||
for _ in 0..6 {
|
||||
run(vec![]);
|
||||
}
|
||||
}
|
||||
let again = list_rect().expect("the list is still open");
|
||||
assert!((again.width() - grown.width()).abs() < 0.5, "the list is as wide as before: {again:?}, {grown:?}");
|
||||
// Closed, the window narrowed again and the long option gone: the list opens as narrow as its
|
||||
// names, not as wide as the window.
|
||||
let escape = |pressed| egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
run(vec![escape(true)]);
|
||||
run(vec![escape(false)]);
|
||||
assert!(list_rect().is_none(), "Escape closes the list");
|
||||
window.set(screen);
|
||||
offered.set(1);
|
||||
run(vec![]);
|
||||
let at = field.get().center();
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![egui::Event::PointerMoved(pos2(210.0, 290.0))]);
|
||||
let mut widths = vec![];
|
||||
for _ in 0..4 {
|
||||
run(vec![]);
|
||||
widths.push(list_rect().expect("the list is open").width());
|
||||
}
|
||||
assert!(widths.iter().all(|w| *w < 180.0), "the list of short names stays narrow: {widths:?}");
|
||||
// Opened in a wide window, narrowed and widened again: it comes back to the width it opened at,
|
||||
// the long list that scrolls and a list of two that does not.
|
||||
for (which, count) in [(0, "40"), (2, "2")] {
|
||||
run(vec![escape(true)]);
|
||||
run(vec![escape(false)]);
|
||||
offered.set(which);
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, vec2(1000.0, 300.0)));
|
||||
run(vec![]);
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![egui::Event::PointerMoved(pos2(990.0, 290.0))]);
|
||||
for _ in 0..6 {
|
||||
run(vec![]);
|
||||
}
|
||||
let opened = list_rect().expect("the list is open");
|
||||
for size in [screen.size(), vec2(1000.0, 300.0)] {
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, size));
|
||||
for _ in 0..6 {
|
||||
run(vec![]);
|
||||
}
|
||||
}
|
||||
let restored = list_rect().expect("the list is still open");
|
||||
// Within the half point that egui rounds a popup's position to.
|
||||
assert!((restored.width() - opened.width()).abs() < 0.5, "{count} options: the list is as wide as it opened: {restored:?}, {opened:?}");
|
||||
}
|
||||
// Opened in a narrow window tall enough for every option, then made wide and short: the list
|
||||
// scrolls now, and its bar's column comes on top of the long name, which shows in full.
|
||||
run(vec![escape(true)]);
|
||||
run(vec![escape(false)]);
|
||||
offered.set(0);
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, vec2(220.0, 1400.0)));
|
||||
run(vec![]);
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![egui::Event::PointerMoved(pos2(210.0, 1390.0))]);
|
||||
for _ in 0..6 {
|
||||
run(vec![]);
|
||||
}
|
||||
window.set(Rect::from_min_size(Pos2::ZERO, vec2(1000.0, 300.0)));
|
||||
for _ in 0..6 {
|
||||
(texts, _) = run(vec![]);
|
||||
}
|
||||
assert!(texts.iter().any(|(s, elided)| !*elided && s == labels[1]), "the long name shows in full beside the bar: {texts:?}");
|
||||
}
|
||||
|
||||
// #5941: in a drop-down list narrowed to the window, an option whose name is cut short shows the
|
||||
// full name in a tooltip while the pointer rests on it.
|
||||
#[test]
|
||||
fn a_dropdown_option_cut_short_shows_its_full_name_on_hover() {
|
||||
let mut items: Vec<String> = (0..10).map(|i| format!("Option {i:02}")).collect();
|
||||
items[1] = "Option 01, whose name is much wider than this window".into();
|
||||
let labels: Vec<&str> = items.iter().map(String::as_str).collect();
|
||||
let ctx = themed(Default::default());
|
||||
let field = std::cell::Cell::new(Rect::NOTHING);
|
||||
let mut add = |ui: &mut Ui| {
|
||||
ui.add_space(16.0);
|
||||
field.set(ui.horizontal(|ui| dropdown_names(ui, "hover-list", labels[0], &labels, 160.0)).response.rect);
|
||||
};
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, vec2(220.0, 300.0));
|
||||
let mut time = 0.0;
|
||||
// Every text painted, on any layer, with its rect and whether it was cut short.
|
||||
let mut run = |events: Vec<egui::Event>| {
|
||||
time += 0.1;
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect: Some(screen), events, ..Default::default() }, &mut add);
|
||||
out.textures_delta.clear();
|
||||
let mut texts = vec![];
|
||||
fn flat(s: &egui::Shape, out: &mut Vec<(String, Rect, bool)>) {
|
||||
match s {
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| flat(s, out)),
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().to_owned(), t.visual_bounding_rect(), t.galley.elided)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
out.shapes.iter().for_each(|c| flat(&c.shape, &mut texts));
|
||||
texts
|
||||
};
|
||||
run(vec![]);
|
||||
let at = field.get().center();
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
run(vec![press(false)]);
|
||||
run(vec![egui::Event::PointerMoved(pos2(210.0, 290.0))]);
|
||||
let mut texts = vec![];
|
||||
for _ in 0..6 {
|
||||
texts = run(vec![]);
|
||||
}
|
||||
let full = |texts: &[(String, Rect, bool)]| texts.iter().any(|(s, _, elided)| !*elided && s == labels[1]);
|
||||
assert!(!full(&texts), "the long name is not shown in full before the hover: {texts:?}");
|
||||
let row = texts
|
||||
.iter()
|
||||
.find(|(s, _, elided)| *elided && s.starts_with("Option 01"))
|
||||
.map(|(_, r, _)| r.center())
|
||||
.unwrap_or_else(|| panic!("the long name is cut short: {texts:?}"));
|
||||
run(vec![egui::Event::PointerMoved(row)]);
|
||||
for _ in 0..10 {
|
||||
texts = run(vec![]);
|
||||
}
|
||||
assert!(full(&texts), "the full name shows on hover: {texts:?}");
|
||||
}
|
||||
|
||||
/// Enter on text that reads as no number in a range field refuses it as a unit field does: the
|
||||
/// field flashes and an open dialog is not confirmed with the old value.
|
||||
#[test]
|
||||
|
||||
@@ -42,6 +42,10 @@ pub struct Workspace {
|
||||
pub toolbar_compact: bool,
|
||||
pub toolbar_advanced: bool,
|
||||
pub task_bar: bool,
|
||||
/// The Contextual Task Bar's actions and chips its Bar Actions has off (built-in workspaces, and
|
||||
/// workspaces saved without this field: none).
|
||||
#[serde(skip_serializing_if = "std::collections::BTreeSet::is_empty", deserialize_with = "crate::canvas::read_hidden_task_bar_actions")]
|
||||
pub task_bar_hidden_actions: std::collections::BTreeSet<String>,
|
||||
pub dock: bool,
|
||||
pub dock_tab: DockTab,
|
||||
/// The dock's tabbed group is collapsed to icons (built-in workspaces: expanded).
|
||||
@@ -208,6 +212,7 @@ pub fn capture(ui: &UiState, name: &str) -> Workspace {
|
||||
toolbar_compact: ui.toolbar_compact,
|
||||
toolbar_advanced: ui.toolbar_advanced,
|
||||
task_bar: ui.task_bar,
|
||||
task_bar_hidden_actions: ui.task_bar_hidden_actions.clone(),
|
||||
dock: ui.dock,
|
||||
dock_tab: ui.dock_tab,
|
||||
dock_collapsed: ui.dock_collapsed,
|
||||
@@ -247,6 +252,7 @@ pub fn apply(ui: &mut UiState, w: &Workspace) {
|
||||
ui.toolbar_compact = w.toolbar_compact;
|
||||
ui.toolbar_advanced = w.toolbar_advanced;
|
||||
ui.task_bar = w.task_bar;
|
||||
ui.task_bar_hidden_actions = w.task_bar_hidden_actions.clone();
|
||||
ui.dock = w.dock;
|
||||
ui.tab_hid = None;
|
||||
ui.dock_tab = w.dock_tab;
|
||||
@@ -949,4 +955,42 @@ mod tests {
|
||||
let read: UiState = serde_json::from_value(prefs).unwrap();
|
||||
assert!(read.control_bar_hidden_groups.is_empty(), "older preferences show every group");
|
||||
}
|
||||
|
||||
/// A workspace keeps the Contextual Task Bar's actions its Bar Actions has off: switching
|
||||
/// brings each workspace's back, Reset turns a built-in workspace's on again, and they survive
|
||||
/// the preferences' JSON. A workspace saved without them, or with ids the bar does not have,
|
||||
/// shows every action, or the ones it names that the bar has.
|
||||
#[test]
|
||||
fn saved_workspaces_restore_the_task_bar_actions() {
|
||||
let hidden = |ids: &[&str]| ids.iter().map(|s| s.to_string()).collect::<std::collections::BTreeSet<String>>();
|
||||
let mut ui = UiState { task_bar_hidden_actions: hidden(&["duplicate", "fill"]), ..Default::default() };
|
||||
save_as(&mut ui, "Lean").unwrap();
|
||||
switch(&mut ui, ESSENTIALS).unwrap();
|
||||
assert!(ui.task_bar_hidden_actions.is_empty(), "Essentials shows every action");
|
||||
ui.task_bar_hidden_actions = hidden(&["simplify"]);
|
||||
switch(&mut ui, "Lean").unwrap();
|
||||
assert_eq!(ui.task_bar_hidden_actions, hidden(&["duplicate", "fill"]), "the saved workspace's actions");
|
||||
switch(&mut ui, ESSENTIALS).unwrap();
|
||||
assert_eq!(ui.task_bar_hidden_actions, hidden(&["simplify"]), "Essentials as it was left");
|
||||
reset(&mut ui);
|
||||
assert!(ui.task_bar_hidden_actions.is_empty(), "Reset Essentials shows every action again");
|
||||
switch(&mut ui, "Lean").unwrap();
|
||||
let json = serde_json::to_value(&ui).unwrap();
|
||||
assert_eq!(json["custom_workspaces"][0]["taskBarHiddenActions"], serde_json::json!(["duplicate", "fill"]));
|
||||
let back: UiState = serde_json::from_value(json).unwrap();
|
||||
assert_eq!(back.task_bar_hidden_actions, hidden(&["duplicate", "fill"]), "kept in the preferences");
|
||||
assert_eq!(back.custom_workspaces[0].task_bar_hidden_actions, hidden(&["duplicate", "fill"]), "kept with the workspace");
|
||||
let mut old = serde_json::to_value(&back.custom_workspaces[0]).unwrap();
|
||||
assert!(old.as_object_mut().unwrap().remove("taskBarHiddenActions").is_some());
|
||||
let old: Workspace = serde_json::from_value(old).unwrap();
|
||||
apply(&mut ui, &old);
|
||||
assert!(ui.task_bar_hidden_actions.is_empty(), "an older workspace shows every action");
|
||||
let mut prefs = serde_json::to_value(&back).unwrap();
|
||||
prefs["custom_workspaces"][0]["taskBarHiddenActions"] = serde_json::json!(["fill", "teleport", 3]);
|
||||
let read: UiState = serde_json::from_value(prefs.clone()).unwrap();
|
||||
assert_eq!(read.custom_workspaces[0].task_bar_hidden_actions, hidden(&["fill"]), "ids the bar does not have are dropped");
|
||||
prefs["custom_workspaces"][0]["taskBarHiddenActions"] = serde_json::json!("fill");
|
||||
let read: UiState = serde_json::from_value(prefs).unwrap();
|
||||
assert!(read.custom_workspaces[0].task_bar_hidden_actions.is_empty(), "a value that is not a list shows every action");
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -8601,6 +8601,27 @@ is kept with the preferences and with the workspace; a workspace or preferences
|
||||
and a group id the bar does not have is dropped when they are read. Another `group`, or none, fails with "`group` must
|
||||
be one of …", and a `visible` that is not true or false fails with "`visible` must be true or false"; either leaves
|
||||
every group as it is. The groups and their contents are VectorCraft's own.
|
||||
`window.taskBar.actions {action, visible?}` (desktop app) turns one of the Contextual Task Bar's actions or chips on
|
||||
(`visible: true`), off (`false`) or toggles it (omitted or null), and returns `{action, visible}`. The actions are `imageTrace`,
|
||||
`cropImage`, `removeBackground`, `removeAnchorPoints`, `join` (Connect and Join), `cutPath`, `convertToCorner`,
|
||||
`convertToSmooth`, `group`, `makeClippingMask`, `unite`, `expand`, `editClippingPath`, `releaseClippingMask`,
|
||||
`ungroup`, `isolate`, `editPath`, `releaseCompoundPath`, `createOutlines`, `convertToPointType`, `convertToAreaType`,
|
||||
`typeOnPathOptions`, `centerOnTop`, `centerOnBottom`, `dynamicText`, `offsetPath`, `simplify`, `smooth`, `duplicate`,
|
||||
`drawPencil`, `placeImage`, `fidelity` and `smoothToolOptions` (the Smooth tool's), and `resizeArtboard`,
|
||||
`duplicateArtboards`, `rearrangeArtboards` and `exportArtboards` (the Artboard tool's); the chips are `fill`, `stroke`,
|
||||
`recolor` (Recolor Artwork), `lock` and `shapeProperties` (a basic shape's Shape Properties, in Lock's place). The bar's
|
||||
More Options menu has Bar Actions, which lists the actions and chips the bar offers for the current selection or tool,
|
||||
each checked while it is on and named without a final colon or ellipsis, and runs the command for the one clicked. An
|
||||
action or chip that is off stays out of the bar and out of More Options wherever the bar would offer it; turning one off
|
||||
changes only the bar. With every action and chip it would offer off, the bar still shows its handle and More Options,
|
||||
where Bar Actions turns them on again. Every action starts
|
||||
on. The type font controls are not in Bar Actions and stay on the bar. Which actions are off is kept with the preferences
|
||||
and with the workspace; a workspace or preferences saved without them show every action, and an id the bar does not have
|
||||
is dropped when they are read. A `visible` of null toggles, as an omitted one does. Another `action`, or none, fails
|
||||
with "`action` must be one of …", and a `visible` that is not true, false or null fails with "`visible` must be true
|
||||
or false"; either leaves every action as it is.
|
||||
`window.taskBar.resetActions {}` (More Options › Reset Bar Actions) turns every action and chip on again and returns
|
||||
the ids it turned on. Choosing the bar's actions is VectorCraft's own.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"file.new","params":{"preset":"A4","orientation":"landscape","artboards":4,"artboardLayout":{"columns":2},"bleed":9}}}
|
||||
|
||||
@@ -1074,6 +1074,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- The contextual task bar offers more next steps by selection (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html>): an open path Join and Edit Path (the Direct Selection tool), a closed path Edit Path, a compound path Edit Path and Release Compound Path, a clipping group Edit Clipping Path and Release Clipping Mask instead of Ungroup and Isolate, an image selected with vector art Make Clipping Mask instead of Unite, point or area type Convert To Area Type or Convert To Point Type beside Create Outlines, and type on a path, for which the overview names an item to add an effect and rearrange the text, Type on a Path Options (`type.pathOptions`; its options: <https://helpx.adobe.com/illustrator/using/creating-type-path.html>) beside Create Outlines. Evidence: `crates/ui-egui/src/tests/taskbar.rs`.
|
||||
- While a Type tool (Type, Area Type, Type on a Path and their vertical versions) adds or edits type, the contextual task bar shows the font family menu, the font style menu, the Font Size combo and the Fill chip (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html>); the Touch Type tool shows no bar, as the same page describes. Type selected with a selection tool shows the same three font controls beside its Create Outlines, conversion and Type on a Path items (<https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html>). The controls act as the Character panel's do: on the characters a Type tool selects, else on every selected type object, with the size left blank where the sizes differ. VectorCraft's own rules: a Type tool's bar leaves out the object actions, the Stroke chip, Recolor Artwork and Lock; a Type tool shows no bar before it adds type or with other art selected; type selected with other art shows no font controls; the font controls go on a second row when one row would be wider than the canvas, and narrow to fit a canvas narrower than they are; while a Type tool edits type, the Fill chip shows the edited characters' fill ("?" where it differs). Evidence: `the_type_tools_show_font_and_fill_controls`, `the_type_tools_show_no_bar_without_type`, `selected_type_shows_font_controls_beside_its_actions`, `the_task_bars_font_size_sets_what_the_character_panel_would`, `the_type_tools_fill_chip_activates_the_fill`, `the_type_tools_bar_is_named_and_stays_on_the_canvas`, `selected_types_font_controls_take_a_second_row_on_a_narrow_canvas` and `the_type_tools_fill_chip_shows_the_edited_characters_fill` in `crates/ui-egui/src/tests/taskbar.rs`.
|
||||
- The help page describes the contextual task bar as one horizontal row (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/workspace-overview.html>) and gives no rule for a canvas narrower than that row. VectorCraft's own rule: the bar stays whole on the canvas. When its actions don't fit in one row, they wrap, in order, onto rows under the row with the handle, the chips and More Options; an action wider than any row, or one that would need a row past the canvas's height, is listed in More Options instead; when the chips don't fit beside the handle and More Options, they take rows after the actions; with no row to spare for the font controls, the bar leaves them out; a canvas too small for the handle and More Options shows no bar. Evidence: `a_task_bars_actions_wrap_on_a_narrow_canvas` and `a_task_bar_action_wider_than_the_canvas_goes_in_more_options` in `crates/ui-egui/src/tests/taskbar.rs`.
|
||||
- The contextual task bar's More Options menu has Bar Actions, which lists the actions and the Fill, Stroke, Recolor Artwork, Lock or Shape Properties chips the bar offers for the current selection or tool, each checked while it is on, and Reset Bar Actions, which turns every one on again (`window.taskBar.actions`, `window.taskBar.resetActions`). An action that is off stays out of the bar and out of More Options wherever the bar would offer it; turning one off changes only the bar. With all of them off, the bar still shows its handle and More Options. The type font controls are not in Bar Actions. Which actions are off is kept with the preferences and with the workspace. Choosing the bar's actions is VectorCraft's own. Evidence: `an_action_turned_off_leaves_the_bar_and_stays_in_its_menu`, `an_action_turned_off_is_not_listed_in_more_options`, `every_action_the_bar_offers_can_be_turned_off`, `a_chip_turned_off_leaves_the_bar`, `reset_bar_actions_shows_every_action_again`, `bar_actions_are_kept_with_the_preferences`, `bar_actions_list_names_without_a_colon_or_an_ellipsis` and `more_options_bar_actions_turns_an_action_off_and_on` in `crates/ui-egui/src/tests/taskbar.rs`, and `saved_workspaces_restore_the_task_bar_actions` in `crates/ui-egui/src/workspaces.rs`.
|
||||
- With a live rectangle, rounded rectangle, ellipse or polygon selected with the Selection tool, the contextual task bar shows a Shape Properties button in place of Lock. It opens a popup with the shape's rows from the Transform panel (corner radius, pie angles, or sides, angle, corner and radius), which edit it through `object.setLiveShape`. The overview describes this: when a shape drawn with a shape tool (Rectangle, Star) is selected, the bar offers to change its properties where Lock Object would be ([Contextual Task Bar overview](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html)). Object › Lock and ⌘2 still lock the shape. Not done: stars, which the app draws as plain paths. Evidence: `a_basic_shape_shows_its_properties_in_place_of_lock`, `the_shape_properties_popup_edits_the_shape` and `other_selections_keep_lock` in `crates/ui-egui/src/tests/taskbar.rs`.
|
||||
- Rectangle Properties and Ellipse Properties in the Transform panel, the Properties panel and the task bar's Shape Properties popup have an Angle field, as Polygon Properties does: the help page lists Rectangle Angle and Ellipse Angle as the shape's rotation on the canvas from 0° to 360° (<https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/live-shape-properties.html>). A typed angle turns the shape through `object.setLiveShape {rectangleAngle, ellipseAngle}`. VectorCraft's own rules: degrees counterclockwise, 0 for a shape drawn level; each selected shape of that kind turns about its own center and keeps its size, corners and pie; the field is blank when the selected shapes of that kind differ, as the Polygon Properties angle now is too; the shape keeps its angle after Reset Bounding Box squares the Rotate field's box to the page; the angle a shape already has records no undo step. Evidence: `a_rectangle_and_an_ellipse_take_their_angle` in `crates/engine/src/tests/livecorners.rs` and `a_rectangle_and_an_ellipse_show_their_angle` in `crates/ui-egui/src/panels/transform/tests.rs`.
|
||||
- While the Rectangle, Rounded Rectangle, Ellipse, Polygon or Star tool is in use, the contextual task bar offers Edit Path (the Direct Selection tool), the Fill and Stroke chips, and Shape Properties for the shape it draws, as the help page lists for those five tools (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html>). VectorCraft's own rules: the bar shows while one of those tools has one closed path selected whole, as right after it draws one, and not with nothing selected, several objects, a group, an open path, type or picked-out anchors; it shows nothing during the drag that draws the shape; it leaves out the selection tools' Duplicate, Offset Path, Simplify, Recolor Artwork and Lock; the Line Segment tool shows no bar. Not done: Shape Properties for a star, which the app draws as a plain path, and Gen Shape Fill and Generate Vectors, which the app doesn't have. Evidence: `shape_tools_show_edit_path_paint_and_properties_after_drawing`, `shape_tools_have_no_shape_bar_without_a_single_shape` and `shape_tool_bar_retargets_after_another_shape_and_undo` in `crates/ui-egui/src/tests/taskbar.rs`.
|
||||
|
||||
Reference in New Issue
Block a user