mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 14:14:50 +00:00
Fix #8041: the Swatches panel shows no Recent Colors or Swatch Tiles heading
The Swatches panel drew a "Recent Colors" heading above the recent colors row, a divider with 6 px of space on each side, and a "Swatch Tiles" heading above the list. The panel now draws the row and the list without those headings or the divider, so the list sits directly under the row, or under the fill and stroke row while Show Recent Colors is off. Screen readers still read the row as "Recent Colors" and the list as "Swatch Tiles". The Color panel keeps its Recent Colors heading.
This commit is contained in:
@@ -618,13 +618,16 @@ pub(crate) fn label_or_name(s: &str, built_in: bool) -> &str {
|
||||
crate::i18n::label_or_name(crate::i18n::current(), s, built_in)
|
||||
}
|
||||
|
||||
/// "Recent Colors" header + rows of chips (the Session's recent colours, which every paint
|
||||
/// command feeds), wrapped onto as many rows as the panel's width needs; returns the one clicked,
|
||||
/// for the caller to apply. A chip drags its color as a solid paint, which the Swatches panel
|
||||
/// Rows of chips (the Session's recent colours, which every paint command feeds), wrapped onto as
|
||||
/// many rows as the panel's width needs, under a "Recent Colors" header when `heading` is set;
|
||||
/// returns the one clicked, for the caller to apply. The chips sit in a group that, without the
|
||||
/// header, screen readers name "Recent Colors". A chip drags its color as a solid paint, which the Swatches panel
|
||||
/// makes a swatch of.
|
||||
pub(crate) fn recent_colors_row(app: &VectorcraftApp, ui: &mut Ui) -> Option<Color> {
|
||||
pub(crate) fn recent_colors_row(app: &VectorcraftApp, ui: &mut Ui, heading: bool) -> Option<Color> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
crate::widgets::subheader(ui, tl!("Recent Colors"));
|
||||
if heading {
|
||||
crate::widgets::subheader(ui, tl!("Recent Colors"));
|
||||
}
|
||||
let width = ui.available_width();
|
||||
let colors = &app.session.recent_colors;
|
||||
// Chips are 16 px on a 19 px pitch, inset 3 px, with 2 px kept clear of the right edge.
|
||||
@@ -632,11 +635,22 @@ pub(crate) fn recent_colors_row(app: &VectorcraftApp, ui: &mut Ui) -> Option<Col
|
||||
let rows = colors.len().div_ceil(per_row).max(1);
|
||||
let (r, _) = ui.allocate_exact_size(vec2(width, 3.0 + rows as f32 * 19.0), Sense::hover());
|
||||
ui.painter().rect_stroke(r, 0.0, egui::Stroke::new(1.0, t.input_border), egui::StrokeKind::Inside);
|
||||
// The chips go in a child `Ui` over the box, so screen readers find them inside its group;
|
||||
// their ids stay under the caller's scope.
|
||||
let scope = ui.scope_id();
|
||||
let mut builder = egui::UiBuilder::new().max_rect(r).accessibility_role(egui::accesskit::Role::Group);
|
||||
if !heading {
|
||||
builder = builder.accessibility_label(tl!("Recent Colors"));
|
||||
}
|
||||
let ui = &mut ui.new_child(builder);
|
||||
ui.ctx().accesskit_node_builder(ui.unique_id(), |node| {
|
||||
node.set_bounds(egui::accesskit::Rect { x0: r.min.x.into(), y0: r.min.y.into(), x1: r.max.x.into(), y1: r.max.y.into() });
|
||||
});
|
||||
let mut chosen = None;
|
||||
for (i, c) in colors.iter().enumerate() {
|
||||
let (row, col) = (i / per_row, i % per_row);
|
||||
let cell = Rect::from_min_size(r.min + vec2(3.0 + col as f32 * 19.0, 3.0 + row as f32 * 19.0), vec2(16.0, 16.0));
|
||||
let resp = ui.interact(cell, ui.scope_id().with(("recent", i)), Sense::click_and_drag());
|
||||
let resp = ui.interact(cell, scope.with(("recent", i)), Sense::click_and_drag());
|
||||
crate::widgets::drag_source(ui, &resp, || crate::widgets::PanelDrag::paint(Paint::solid(*c)));
|
||||
crate::widgets::swatch_tile(ui, cell, &Paint::solid(*c), false, resp.hovered());
|
||||
if resp.on_hover_text(c.to_hex()).clicked() {
|
||||
|
||||
@@ -712,7 +712,7 @@ pub(crate) fn show_sized(app: &mut VectorcraftApp, ui: &mut Ui, height: f32) {
|
||||
// Show Recent Colors draws the Recent Colors row; the Swatches panel's row does not read it.
|
||||
let mut recent = None;
|
||||
if app.ui.color_show_recent_colors {
|
||||
recent = super::recent_colors_row(app, ui);
|
||||
recent = super::recent_colors_row(app, ui, true);
|
||||
widgets::divider(ui);
|
||||
}
|
||||
// An edit of the active colour with its displayed components (`new`), or a colour clicked with
|
||||
|
||||
@@ -36,14 +36,14 @@ pub(super) fn body(app: &mut VectorcraftApp, ui: &mut Ui, salt: &'static str) {
|
||||
ui.add_space(4.0);
|
||||
// A recent colour paints the active proxy (Alt: the inactive one), as a swatch does, and
|
||||
// becomes the Color Guide's base color. The panel menu's Show Recent Colors hides the row.
|
||||
if app.ui.swatches_show_recent_colors {
|
||||
if let Some(c) = crate::panels::recent_colors_row(app, ui) {
|
||||
crate::panels::color_guide::choose_base(app, c);
|
||||
crate::panels::apply_click(app, ui, json!({"color": crate::panels::color_json(&c)}));
|
||||
}
|
||||
widgets::divider(ui);
|
||||
// Neither the row nor the list has a visible heading (#8041): the list sits under the row, or
|
||||
// under the proxy row while the row is hidden.
|
||||
if app.ui.swatches_show_recent_colors
|
||||
&& let Some(c) = crate::panels::recent_colors_row(app, ui, false)
|
||||
{
|
||||
crate::panels::color_guide::choose_base(app, c);
|
||||
crate::panels::apply_click(app, ui, json!({"color": crate::panels::color_json(&c)}));
|
||||
}
|
||||
widgets::subheader(ui, tl!("Swatch Tiles"));
|
||||
let query = if pstate(ui.ctx(), "swatch-show-find") { widgets::search_field(ui, find_id(), tl!("Find")) } else { String::new() };
|
||||
let items = entries(app, kind, &query);
|
||||
let active_swatch = kept_swatch(app, ui, active_swatch(app));
|
||||
@@ -60,6 +60,12 @@ pub(super) fn body(app: &mut VectorcraftApp, ui: &mut Ui, salt: &'static str) {
|
||||
let fixed = widgets::panel_footer_bottom(ui).is_some();
|
||||
let list_height = widgets::panel_list_height(ui, if view == View::LargeThumb { 200.0 } else { 150.0 }, 2.0 + ui.spacing().item_spacing.y);
|
||||
widgets::list_box(ui, |ui| {
|
||||
// Screen readers read the box that holds the tiles as the "Swatch Tiles" list, with the
|
||||
// box's bounds set below once the tiles are laid out.
|
||||
ui.ctx().accesskit_node_builder(ui.unique_id(), |node| {
|
||||
node.set_role(egui::accesskit::Role::List);
|
||||
node.set_label(tl!("Swatch Tiles"));
|
||||
});
|
||||
let scroll = egui::ScrollArea::vertical()
|
||||
.id_salt("swatch-scroll")
|
||||
.max_height(list_height)
|
||||
@@ -112,6 +118,10 @@ pub(super) fn body(app: &mut VectorcraftApp, ui: &mut Ui, salt: &'static str) {
|
||||
});
|
||||
let zone = ui.interact(out.inner_rect, ui.scope_id().with("swatch-drop"), Sense::hover());
|
||||
zone_input(ui, &zone, &mut ev);
|
||||
let r = ui.min_rect();
|
||||
ui.ctx().accesskit_node_builder(ui.unique_id(), |node| {
|
||||
node.set_bounds(egui::accesskit::Rect { x0: r.min.x.into(), y0: r.min.y.into(), x1: r.max.x.into(), y1: r.max.y.into() });
|
||||
});
|
||||
});
|
||||
match ev.edit {
|
||||
Some(Entry::Folder(g)) => edit_group(app, &g),
|
||||
|
||||
@@ -1006,6 +1006,69 @@ fn show_recent_colors_hides_and_shows_the_swatches_row() {
|
||||
assert_eq!((saved(json!(false)), saved(json!(true)), saved(json!("no"))), (false, true, true));
|
||||
}
|
||||
|
||||
/// The panel draws no "Recent Colors" or "Swatch Tiles" heading (#8041): the Recent Colors row
|
||||
/// sits under the proxy row, empty or not, the swatch list just under it, and the list moves up
|
||||
/// under the proxy row when Show Recent Colors hides the row. Screen readers still find both
|
||||
/// parts by those names.
|
||||
#[test]
|
||||
fn the_list_sits_under_the_recent_colors_row_without_headings() {
|
||||
fn texts(shapes: &[egui::Shape], out: &mut Vec<String>) {
|
||||
for s in shapes {
|
||||
match s {
|
||||
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
|
||||
egui::Shape::Vec(v) => texts(v, out),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// The visible texts, and the bounds of the parts screen readers name "Recent Colors" and
|
||||
// "Swatch Tiles", of the second of two frames.
|
||||
let look = |app: &mut VectorcraftApp| {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let ctx = context();
|
||||
ctx.enable_accesskit();
|
||||
let mut last = None;
|
||||
for time in [0.0, 0.5] {
|
||||
let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(280.0, 700.0)));
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(time), screen_rect, ..Default::default() }, |ui| show(app, ui));
|
||||
out.textures_delta.clear();
|
||||
last = Some(out);
|
||||
}
|
||||
let out = last.expect("a frame");
|
||||
let mut shown = vec![];
|
||||
texts(&out.shapes.iter().map(|c| c.shape.clone()).collect::<Vec<_>>(), &mut shown);
|
||||
let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default();
|
||||
let named =
|
||||
|label: &str| nodes.iter().find(|(_, n)| n.label() == Some(label)).and_then(|(_, n)| n.bounds()).map(|b| (b.y0 as f32, b.y1 as f32));
|
||||
// The list is the node that holds the tiles, not an empty node beside them.
|
||||
let list = nodes.iter().find(|(_, n)| n.label() == Some("Swatch Tiles"));
|
||||
assert!(list.is_some_and(|(_, n)| n.role() == egui::accesskit::Role::List && !n.children().is_empty()), "the list holds the tiles");
|
||||
// Likewise the Recent Colors group holds its chips, one child per recent color.
|
||||
let chips = nodes.iter().find(|(_, n)| n.label() == Some("Recent Colors")).map(|(_, n)| n.children().len());
|
||||
if let Some(chips) = chips {
|
||||
assert_eq!(chips, app.session.recent_colors.len(), "the group holds the chips");
|
||||
}
|
||||
(shown, named("Recent Colors"), named("Swatch Tiles"))
|
||||
};
|
||||
let mut app = app();
|
||||
for applied in [false, true] {
|
||||
if applied {
|
||||
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
}
|
||||
let (shown, recent, list) = look(&mut app);
|
||||
assert!(!shown.iter().any(|t| t == "Recent Colors" || t == "Swatch Tiles"), "no headings: {shown:?}");
|
||||
let (row_top, row_bottom) = recent.expect("screen readers find the Recent Colors row");
|
||||
let (top, _) = list.expect("screen readers find the swatch list");
|
||||
assert!(row_top < 50.0, "the row sits under the proxy row: {row_top}");
|
||||
assert!(top > row_bottom && top - row_bottom < 12.0, "the list sits under the row: {row_bottom} {top}");
|
||||
}
|
||||
app.ui.swatches_show_recent_colors = false;
|
||||
let (_, recent, list) = look(&mut app);
|
||||
assert_eq!(recent, None, "Show Recent Colors unchecked hides the row");
|
||||
let (top, _) = list.expect("screen readers find the swatch list");
|
||||
assert!(top < 50.0, "the list starts under the proxy row: {top}");
|
||||
}
|
||||
|
||||
/// In a panel made taller the swatch list fills the space above the panel's footer instead of
|
||||
/// scrolling inside 150 or 200 pt (#1638); outside a sized panel it keeps those heights.
|
||||
#[test]
|
||||
|
||||
@@ -313,7 +313,7 @@ fn the_popover_swatch_libraries_button_opens_the_libraries_menu() {
|
||||
let libraries = *popover_bottom_buttons(&ctx).first().expect("the popover has a bottom bar");
|
||||
click(&mut app, &ctx, libraries.center(), Modifiers::NONE, control_bar);
|
||||
let shapes = frame(&mut app, &ctx, vec![], Modifiers::NONE, control_bar);
|
||||
assert!(text_rect(&shapes, "Swatch Tiles").is_some(), "the popover stays open");
|
||||
assert_eq!(popover_bottom_buttons(&ctx).first(), Some(&libraries), "the popover stays open");
|
||||
let defaults = menu_item_rect(&shapes, "Default Swatches").expect("the libraries menu is open");
|
||||
assert!(menu_item_rect(&shapes, "Other Library…").is_some());
|
||||
let earth = menu_item_rect(&shapes, "Earth Tones").expect("the menu lists the built-in libraries");
|
||||
|
||||
Reference in New Issue
Block a user