Skip to content

Commit 4956a55

Browse files
OneSlipsclaude
andcommitted
LR-UI-DENSE-ROWS: tests that the name column follows the language and a long name ends in an ellipsis (FredApps, storytold#3155)
- `the_name_column_fits_the_longest_name_in_the_current_language`: the column is the longest name of its group in the language on screen, measured in the row's font (German "Dunst entfernen" widens the Effects column past English "Dehaze"). - `a_name_too_long_for_its_column_ends_in_an_ellipsis_and_shows_whole_on_hover`: the name is cut with an ellipsis to its (capped) column, and hovering it shows it whole with the reset hint. - accessibility.rs: a doc comment moved back onto its own test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 47f967d commit 4956a55

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎crates/ui-egui/src/widgets/tests_dense_row.rs‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,96 @@ fn corners_are_at_most_half_the_earlier_radius() {
246246
assert!(v.window_corner_radius.nw <= RADIUS_PANEL && v.menu_corner_radius.nw <= RADIUS_PANEL, "{kind:?}");
247247
}
248248
}
249+
250+
/// Puts the UI language back to English when a test that changed it ends (also when it fails).
251+
struct Language;
252+
253+
impl Language {
254+
fn set(language: crate::i18n::Locale) -> Self {
255+
crate::i18n::set_language(language);
256+
Language
257+
}
258+
}
259+
260+
impl Drop for Language {
261+
fn drop(&mut self) {
262+
crate::i18n::set_language(crate::i18n::Locale::En);
263+
}
264+
}
265+
266+
/// FredApps on #3155: the name column is as wide as the longest name of its group in the language
267+
/// on screen ("Dunst entfernen" in German, "Dehaze" in English), measured in the row's own font.
268+
#[test]
269+
fn the_name_column_fits_the_longest_name_in_the_current_language() {
270+
let ids = ["effects.texture", "effects.clarity", "effects.dehaze"];
271+
let column = |language: crate::i18n::Locale| {
272+
let _language = Language::set(language);
273+
let mut view = HeadlessView::new();
274+
let specs: Vec<ControlSpec> = ids.iter().map(|id| *controls::find(id).unwrap()).collect();
275+
let mut longest = 0.0f32;
276+
let mut registry = Vec::new();
277+
for frame in 0..3 {
278+
view.run(HeadlessView::raw_input(vec2(320.0, 200.0), 1.0, f64::from(frame) * 0.02, vec![]), |ui| {
279+
super::begin_slider_group(ui, "effects");
280+
for spec in &specs {
281+
slider(ui, spec, 0.0, true, None);
282+
}
283+
// the longest name in this language, in the row's own font
284+
let font = crate::theme::Tokens::get(ui.ctx()).font(super::ROW_FONT);
285+
longest = specs
286+
.iter()
287+
.map(|s| ui.painter().layout_no_wrap(crate::i18n::tr(s.label).to_string(), font.clone(), egui::Color32::WHITE).size().x.ceil())
288+
.fold(0.0f32, f32::max);
289+
});
290+
// (the registry keeps every frame's rects: the last frame's are the ones to check)
291+
registry = take_registry(&view.ctx);
292+
}
293+
let widths: Vec<f32> = ids
294+
.iter()
295+
.map(|id| registry.iter().find(|(r, _)| *r == format!("sliderLabel:{id}")).map(|(_, r)| r.width()).unwrap_or_else(|| panic!("no {id}")))
296+
.collect();
297+
for w in &widths {
298+
assert!((w - longest.max(super::NAME_MIN)).abs() < 0.5, "{language:?}: column {w} for a longest name of {longest}: {widths:?}");
299+
}
300+
longest
301+
};
302+
let (en, de) = (column(crate::i18n::Locale::En), column(crate::i18n::Locale::De));
303+
assert!(de > en + 10.0, "the German column is the wider one: {de} against {en}");
304+
}
305+
306+
/// FredApps on #3155: a name too long for its column is cut with an ellipsis, and hovering it
307+
/// shows the whole name.
308+
#[test]
309+
fn a_name_too_long_for_its_column_ends_in_an_ellipsis_and_shows_whole_on_hover() {
310+
let long = "Highlights Luminance Saturation Balance";
311+
let spec = *controls::find("light.exposure").unwrap();
312+
let mut view = HeadlessView::new();
313+
let mut label: Option<Rect> = None;
314+
let mut texts = Vec::new();
315+
let mut cut = None;
316+
let mut moved = false;
317+
for frame in 0..60 {
318+
// the pointer comes to rest on the name once (a move every frame would keep the tooltip away)
319+
let events = match label {
320+
Some(l) if !moved => {
321+
moved = true;
322+
vec![Event::PointerMoved(l.center())]
323+
}
324+
_ => vec![],
325+
};
326+
view.run(HeadlessView::raw_input(vec2(220.0, 200.0), 1.0, f64::from(frame) * 0.05, events), |ui| {
327+
slider(ui, &spec, 0.0, true, Some(long));
328+
});
329+
texts = view.painted_text();
330+
cut = view.painted_shapes().into_iter().find_map(|shape| match shape {
331+
egui::epaint::Shape::Text(t) if t.galley.job.text == long => Some((t.galley.elided, t.galley.size().x)),
332+
_ => None,
333+
});
334+
label = take_registry(&view.ctx).into_iter().find(|(id, _)| id == "sliderLabel:light.exposure").map(|(_, r)| r);
335+
}
336+
let label = label.expect("the name's rect");
337+
assert!(label.width() < 220.0 * 0.5, "the column is capped: {label:?}");
338+
let (elided, drawn_w) = cut.expect("the name is drawn");
339+
assert!(elided && drawn_w <= label.width() + 0.5, "the name is cut with an ellipsis to its column: {drawn_w} in {label:?}");
340+
assert!(texts.iter().any(|t| t != long && t.contains(long)), "hovering shows the whole name (with the reset hint): {texts:?}");
341+
}

‎crates/ui-egui/tests/it/accessibility.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ fn slider_value(h: &Harness<'_, LightcraftApp>, name: &str) -> Option<f64> {
158158
.and_then(|n| n.numeric_value())
159159
}
160160

161-
/// A screen reader's Increment on a develop slider moves it one step, as an arrow key does.
162161
/// A slider that shows a short name under its caption ("Amount" under Grain) is announced by its
163162
/// full name, which still says what it changes without the caption.
164163
#[test]
@@ -175,6 +174,7 @@ fn short_named_sliders_are_announced_by_their_full_name() {
175174
assert_eq!(sliders.iter().filter(|s| *s == "Amount").count(), 1, "only AI Denoise is announced as Amount: {sliders:?}");
176175
}
177176

177+
/// A screen reader's Increment on a develop slider moves it one step, as an arrow key does.
178178
#[test]
179179
fn screen_reader_increment_moves_a_slider() {
180180
let mut h = harness(ViewMode::Detail, RightPanel::Edit);

0 commit comments

Comments
 (0)