mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Frame tool: draw the "#" sides caption and keep "Sides" as its name (#13922)
The sides field passed "#" as its label, but a bare NumberField draws no caption, so the bar showed only the value while screen readers announced the field as "#". The field now sits in a Field with a glyph side label: "#" is drawn before it, and "Sides" stays its accessible name. The test checks the painted "#" and the accessible name. Co-Authored-By: mlo0352 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e557e3006c
commit
7e907e44da
2 files changed
+13
-7
No files matched your search
@@ -23,8 +23,9 @@ use craft::draw::ui::{
|
||||
use craft::keymap::Mods;
|
||||
use craft::ui::canvas::{CanvasTool, ToolAction, ToolClaims, ToolContext, ToolHostResponse, ToolKey, ToolPath, ToolPointer};
|
||||
use craft::ui::choice::Segmented;
|
||||
use craft::ui::contract::{Bind, Entry, Show};
|
||||
use craft::ui::contract::{Bind, Entry, GlyphLabel, LabelKind, Props as _, Show, ShowContainer as _, SideLabel, Sizing};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::primitives::Draw;
|
||||
use craft::ui::text::NumberField;
|
||||
use egui::{Pos2, Stroke, StrokeKind};
|
||||
@@ -819,7 +820,11 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
|
||||
}
|
||||
if app.ui.frame_tool.shape == "polygon" {
|
||||
let mut sides = Some(f64::from(app.ui.frame_tool.sides.clamp(3, 100)));
|
||||
NumberField::new("#", Bind::bound(&mut sides)).range(3.0..=100.0).show(ui);
|
||||
// The bar shows the "#" caption; "Sides" stays the field's accessible name.
|
||||
let side = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text("#")));
|
||||
Field::new("Sides").side(side).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
NumberField::new("Sides", Bind::bound(&mut sides)).range(3.0..=100.0).show(ui);
|
||||
});
|
||||
if let Some(n) = sides {
|
||||
app.ui.frame_tool.sides = (n.round() as u32).clamp(3, 100);
|
||||
}
|
||||
|
||||
@@ -70,10 +70,11 @@ fn polygon_shows_the_hash_caption_and_keeps_the_default_and_accessible_name() {
|
||||
h.state_mut().ui.frame_tool.shape = "polygon".into();
|
||||
h.run_steps(4);
|
||||
let text = drawn(&h);
|
||||
// The framework exposes the short caption through the field's accessible label; the numeric
|
||||
// editor itself only paints the value in the shape tree.
|
||||
assert!(h.query_by_role_and_label(Role::SpinButton, "#").is_some(), "polygon caption: {text:?}");
|
||||
assert!(!text.iter().any(|text| text == "Sides"), "old caption: {text:?}");
|
||||
// The bar paints "#" as the caption, and the field keeps "Sides" as its accessible name.
|
||||
assert!(text.iter().any(|text| text == "#"), "polygon caption: {text:?}");
|
||||
assert!(!text.iter().any(|text| text.starts_with("Sides")), "old caption: {text:?}");
|
||||
assert!(h.query_by_role_and_label(Role::SpinButton, "Sides").is_some(), "accessible name");
|
||||
assert!(h.query_by_role_and_label(Role::SpinButton, "#").is_none(), "\"#\" alone names nothing");
|
||||
assert_eq!(h.state().ui.frame_tool.sides, 5);
|
||||
assert!(text.iter().any(|text| text == "5"), "the field displays the default: {text:?}");
|
||||
}
|
||||
@@ -84,7 +85,7 @@ fn polygon_sides_field_keeps_the_three_to_one_hundred_range() {
|
||||
h.state_mut().ui.frame_tool.shape = "polygon".into();
|
||||
h.run_steps(4);
|
||||
for (typed, expected) in [("1", 3), ("3", 3), ("100", 100), ("101", 100)] {
|
||||
h.get_by_role_and_label(Role::SpinButton, "#").click();
|
||||
h.get_by_role_and_label(Role::SpinButton, "Sides").click();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Text(typed.into()));
|
||||
|
||||
Reference in new issue
Block a user