Merge pull request #2445 from storytold/carry/2370

M3: a text field shows a value too long for it with an ellipsis and a tooltip (#2368)
This commit is contained in:
BFlat authored and GitHub committed 2026-11-18 19:09:07 +07:00
commit 5f87a60f2d
4 files changed
+116 -3

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
//! A text field that isn't being edited ends a value too long for it with an ellipsis, shows the
//! whole value on hover, and keeps it whole for screen readers (#2368: the variant value "Down
//! left" showed as "Down lef" in a 62 px chip).
use egui::accesskit::Node;
use egui::epaint::{ClippedShape, Shape};
use egui::{Event, Pos2, pos2};
use figcraft_doc::NodeId;
use figcraft_engine::Session;
use serde_json::json;
use crate::component_swap_default_tests::tree;
use crate::layers_drag_tests::Ui;
fn id(v: serde_json::Value) -> NodeId {
NodeId(v["id"].as_u64().unwrap())
}
/// A selected component set with a "Looking" property of `values`.
fn set_with(values: &[&str]) -> Ui {
let mut s = Session::new();
let mut variants = Vec::new();
for (k, v) in values.iter().enumerate() {
let f = id(s.execute("frame.create", &json!({"x": 0, "y": k * 60, "width": 80, "height": 40, "name": format!("Looking={v}")})).unwrap());
variants.push(id(s.execute("component.create", &json!({"ids": [f]})).unwrap()));
}
let set = id(s.execute("component.combineVariants", &json!({"ids": variants})).unwrap());
s.execute("select.set", &json!({"ids": [set]})).unwrap();
let u = Ui::new(s);
u.ctx.enable_accesskit();
u
}
/// How many painted texts read `text`.
fn count(shapes: &[String], text: &str) -> usize {
shapes.iter().filter(|t| *t == text).count()
}
/// Frames with a still pointer on `at`, long enough for egui's tooltip delay; the last one's texts.
fn hover(u: &mut Ui, at: Pos2) -> Vec<String> {
let mut shown = Vec::new();
u.frame(vec![Event::PointerMoved(at)]);
for _ in 0..90 {
shown = texts(&u.frame_output(vec![]).shapes);
}
shown
}
fn texts(shapes: &[ClippedShape]) -> Vec<String> {
fn walk(s: &Shape, out: &mut Vec<String>) {
match s {
Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
Shape::Text(t) => out.push(t.galley.text().to_owned()),
_ => {}
}
}
let mut out = Vec::new();
shapes.iter().for_each(|c| walk(&c.shape, &mut out));
out
}
/// The accesskit node of the value chip showing `value`.
fn chip(nodes: &[Node], value: &str) -> Pos2 {
let n = nodes.iter().find(|n| n.value() == Some(value) && n.bounds().is_some()).unwrap_or_else(|| panic!("a chip for {value}"));
let b = n.bounds().unwrap();
pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)
}
#[test]
fn a_variant_value_too_long_for_its_chip_ends_with_an_ellipsis() {
let mut u = set_with(&["Top right", "Down left"]);
let shown = texts(&u.frame_output(vec![]).shapes);
let cut: Vec<&String> = shown.iter().filter(|t| t.starts_with("Down l")).collect();
assert!(!cut.is_empty(), "the value is painted: {shown:?}");
assert!(cut.iter().all(|t| t.ends_with('…')), "ends with an ellipsis: {cut:?}");
assert!(!shown.iter().any(|t| t == "Down lef"), "not cut mid-letter: {shown:?}");
}
#[test]
fn the_shortened_value_shows_whole_on_hover() {
let mut u = set_with(&["Top right", "Down left"]);
let at = chip(&tree(&mut u), "Down left");
let before = count(&texts(&u.frame_output(vec![]).shapes), "Down left");
let shown = hover(&mut u, at);
assert_eq!(count(&shown, "Down left"), before + 1, "the whole value is painted again, in a tooltip: {shown:?}");
}
#[test]
fn a_value_that_fits_is_shown_whole_without_a_tooltip() {
let mut u = set_with(&["Top", "Down left"]);
let nodes = tree(&mut u);
let shown = texts(&u.frame_output(vec![]).shapes);
let before = count(&shown, "Top");
assert!(before > 0, "Top is painted as it is: {shown:?}");
let after = hover(&mut u, chip(&nodes, "Top"));
assert_eq!(count(&after, "Top"), before, "no tooltip repeats it: {after:?}");
}
#[test]
fn screen_readers_keep_the_whole_value() {
let mut u = set_with(&["Top right", "Down left"]);
let nodes = tree(&mut u);
assert!(nodes.iter().any(|n| n.value() == Some("Down left")), "the chip's value is the whole text");
assert!(!nodes.iter().any(|n| n.value().is_some_and(|v| v.ends_with('…'))), "no node announces a shortened value");
}
+2
View File
@@ -110,6 +110,8 @@ mod export_name_tests;
#[cfg(test)]
mod export_preview_tests;
#[cfg(test)]
mod field_ellipsis_tests;
#[cfg(test)]
mod field_tests;
#[cfg(test)]
mod font_menu_regrow_tests;
+7 -2
View File
@@ -718,9 +718,14 @@ fn text_field_in(ui: &mut Ui, id: Id, value: &str, rect: Rect, placeholder: &str
}
None => {
let (s, col) = if value.is_empty() { (placeholder, t.text_tertiary) } else { (&*shown, t.text) };
// Long text stays inside the field.
// Long text ends in an ellipsis inside the field; hovering shows the whole value (not
// of a secret one: that is a key).
let fitted = elide(ui, s, rect.width() - 16.0);
let painter = ui.painter().with_clip_rect(rect.shrink2(vec2(8.0, 0.0)));
painter.text(pos2(rect.min.x + 8.0, rect.center().y), Align2::LEFT_CENTER, s, regular(11.0), col);
painter.text(pos2(rect.min.x + 8.0, rect.center().y), Align2::LEFT_CENTER, &fitted, regular(11.0), col);
if fitted != s && !secret && !value.is_empty() {
resp.on_hover_text(value);
}
}
}
out
+2 -1
View File
@@ -22,7 +22,7 @@ accounts).
| A component can't contain its own instance, directly or through other components | done | refused with the loop named (creating, placing, swapping, switching variants, moving, pasting, an instance-swap value); each variant counts as its own component, so a variant may hold a sibling variant's instance unless that one leads back to it; a dropped instance lands on the page; a file holding a loop opens with one instance detached and a note, any other file unchanged; a loop merged in a live session stops expanding where an instance would show itself again (#1084) |
| Switching variants keeps overrides where names match and both variants had the same value; text layers keep theirs | done | |
| Default variant: the top-left one (new instances, Assets thumbnail, generated code) | done | |
| Variant property order (names rewritten), duplicate combinations reported | done | drag a property in the Properties section to reorder it, one undo step (#679), or `component.editProperty {index}` |
| Variant property order (names rewritten), duplicate combinations reported | done | drag a property in the Properties section to reorder it, one undo step (#679), or `component.editProperty {index}`; a variant value too long for its field ends with an ellipsis and shows whole on hover (#2368) |
| Properties: boolean, text, instance swap (preferred values), variant | done | listed in the order they were made, a rename keeping the place (#1536; the shared ones don't reorder by drag yet); every component menu scrolls past 320 pt, the default of an instance-swap property's too (#1338); the instance-swap menus (an instance's property and swap menus, a property's default, the playground) open with a search field that filters by name as you type, with Up, Down and Enter to pick and Escape to clear then close; the slot and preferred components menus have no search yet; an instance lists the properties its variant's layers use, so a set with one text property per variant shows one text field per instance (#2022; measured in Figma's web app, 2026-11-11); long names are cut to one line, the full name on hover |
| Slots (preferred components, fill menu, kept across updates) | done | Figma 2025 feature; Make slot asks for the name first (a field under the frame's Slot row), and slots are renamed in the component's Properties list (#1537); no rename with only the slot's frame selected yet |
| Exposed nested instances | done | hidden ones hide their properties |
@@ -80,6 +80,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`.
| Date | Change | Summary |
|---|---|---|
| 2026-11-18 | patch | M3, #2368: a text field that isn't being edited ends a value too long for it with an ellipsis and shows the whole value on hover (a secret field shows none), so the variant value "Down left" no longer reads "Down lef"; screen readers and editing keep the whole value (`field_ellipsis_tests`). Grade unchanged. |
| 2026-11-14 | patch | M3, #2354: the Local variables window resizes from its edges and corners, width and height (minimum 600 x 240), and keeps its size and place while the app runs. |
| 2026-11-07 | patch | M3, #2090: an instance's own resizing follows its main's unless its size is overridden. Measured in Figma: a plain instance turns Fixed when its main's width does (a child set to Fill along it) and back to Hug with it; an instance whose width was typed keeps it; Fill in its own auto layout parent is kept. Tests: `components_behaviour_tests::a_plain_instances_resizing_follows_the_mains_root_both_ways` and the instance resizing tests beside it. |
| 2026-11-13 | patch | Rows that recent merges had duplicated or garbled are merged back into one row each (no behaviour change): Create component, instances, detach, reset, go to main, restore main, push changes. |