Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ command leaves the lists that name it, such as `ON_A_COPY`, the policy tables an
at nothing. A literal that isn't a command goes in its `EXEMPT` list with a reason (file and host names
ending in a `NOT_IDS` word need none), and an `EXEMPT` entry the source no longer
holds fails it too.
The tests `every_control_can_be_reached_*` (`crates/ui-egui/src/layout_reach.rs`, Linux) show each ribbon tab, Workflows section
and listed pane, dialog and main view with English labels 40% longer (labels that hold a placeholder, and text
that isn't passed through `tl!` or `tl_raw!`, keep their length), at 1280×720 and the smallest window,
and fail on a control that lies on another or that scrolling doesn't bring into view: let the row wrap, scroll or
shrink rather than listing it. `KNOWN` holds the problems there are; take lines out, don't add them. A new pane,
dialog or main view goes in the test's lists, with how to tell it is shown.
The tests `every_control_can_be_reached_*` (`crates/ui-egui/src/layout_reach/desktop.rs`, and the phone's in
`crates/ui-touch/src/layout_reach.rs`; Linux) show each ribbon tab, Workflows section and listed pane, dialog and
main view, and each of the phone's sheets, with every English word 40% longer (labels that hold a placeholder, and
text that isn't passed through `tl!` or `tl_raw!`, keep their length), at 1280×720 and the smallest window (360×760
and 800×360 on the phone). They open each menu, list and context menu on them in turn, and fail on a control that
lies on another or that scrolling doesn't bring into view, and on text painted on other text: let the row wrap,
scroll or shrink rather than listing it. `KNOWN` holds the problems there are; take lines out, don't add them. A
new pane, dialog, main view or sheet goes in the test's lists, with how to tell it is shown; a control drawn by
hand gives itself a role and name (`widget_info`), or the test can't see it.
While you work, `cargo xtask changed` runs the same checks on only the packages your branch changes
and those that depend on them (and `test-hygiene` on the whole workspace, and formatting, `layers`,
`attribution` and `rows` when packages are checked; `attribution` also when only non-code files change), or everything when a
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/ui-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ sha2 = { workspace = true }
[target.'cfg(unix)'.dependencies]
rustix = { version = "1.1", features = ["process", "fs"] }

[features]
# The layout check (`layout_reach`) for other crates' tests: the phone's surfaces in `rustgis-ui-touch`.
testing = []

[dev-dependencies]
tempfile = "3"
# PDF downloads drawn off the frame (#2336).
Expand Down
12 changes: 10 additions & 2 deletions crates/ui-egui/src/backstage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ fn card(ui: &mut Ui, t: &Tokens, title: &str, sub: &str, icon: &str) -> bool {
let thumb = Rect::from_min_size(r.min + vec2(12.0, 12.0), vec2(176.0, 86.0));
ui.painter().rect_filled(thumb, CornerRadius::same(6), t.canvas);
icons::paint(ui.painter(), Rect::from_center_size(thumb.center(), vec2(48.0, 48.0)), icon, t.icon, t.accent);
ui.painter().text(pos2(r.min.x + 14.0, r.min.y + 116.0), Align2::LEFT_CENTER, tl!(title), semibold(13.5), t.text);
ui.painter().text(pos2(r.min.x + 14.0, r.min.y + 136.0), Align2::LEFT_CENTER, tl!(sub), regular(11.5), t.text_dim);
// Within the card: the title on one line, the line under it on two, cut short past that.
let fit = |text: &str, font: egui::FontId, color, rows: usize| {
let mut job = egui::text::LayoutJob::simple(text.to_string(), font, color, r.width() - 28.0);
job.wrap.max_rows = rows;
ui.fonts_mut(|f| f.layout_job(job))
};
let title = fit(tl!(title), semibold(13.5), t.text, 1);
let below = pos2(r.min.x + 14.0, r.min.y + 116.0 - title.size().y / 2.0);
ui.painter().galley(below, title.clone(), t.text);
ui.painter().galley(below + vec2(0.0, title.size().y + 3.0), fit(tl!(sub), regular(11.5), t.text_dim, 2), t.text_dim);
resp.clicked()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ui-egui/src/catalogsui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Default for State {
}

fn fetch(url: &str) -> Answer {
#[cfg(all(test, target_os = "linux"))]
#[cfg(all(any(test, feature = "testing"), target_os = "linux"))]
crate::layout_reach::downloaded();
let slot: Answer = Slot::default();
let land = slot.clone();
Expand Down
320 changes: 161 additions & 159 deletions crates/ui-egui/src/chrome.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions crates/ui-egui/src/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub fn tr(lang: Lang, s: &str) -> &str {
return t;
}
if lang == Lang::EN {
#[cfg(all(test, target_os = "linux"))]
#[cfg(all(any(test, feature = "testing"), target_os = "linux"))]
if pseudo::on() {
return pseudo::pad(s);
}
Expand Down Expand Up @@ -421,7 +421,7 @@ pub fn tr_raw(lang: Lang, s: &str) -> &str {
return t;
}
if lang == Lang::EN {
#[cfg(all(test, target_os = "linux"))]
#[cfg(all(any(test, feature = "testing"), target_os = "linux"))]
if pseudo::on() {
return pseudo::pad(s);
}
Expand Down Expand Up @@ -753,15 +753,15 @@ macro_rules! tl_raw {

#[cfg(test)]
mod boundary_tests;
#[cfg(all(test, target_os = "linux"))]
#[cfg(all(any(test, feature = "testing"), target_os = "linux"))]
pub(crate) mod pseudo;

/// Whether the layout tests' long English is on, on this thread; never outside them.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn pseudo_on() -> bool {
#[cfg(all(test, target_os = "linux"))]
#[cfg(all(any(test, feature = "testing"), target_os = "linux"))]
return pseudo::on();
#[cfg(not(all(test, target_os = "linux")))]
#[cfg(not(all(any(test, feature = "testing"), target_os = "linux")))]
false
}
#[cfg(test)]
Expand Down
25 changes: 22 additions & 3 deletions crates/ui-egui/src/i18n/pseudo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A stand-in for a long language: English with each line about 40% longer. Layout tests draw the
//! A stand-in for a long language: English with each word about 40% longer. Layout tests draw the
//! interface in it, so a label that only fits in English fails them without a translation or a
//! font of its own.

Expand All @@ -21,19 +21,34 @@ pub(crate) fn set(on: bool) {
ON.set(on);
}

/// `s` padded: each line grows by 40% of its length. A line with a placeholder is left alone,
/// `s` padded: each word grows by 40% of its length. A line with a placeholder is left alone,
/// since what fills it isn't translated.
pub(crate) fn pad(s: &str) -> &'static str {
PADDED.with_borrow_mut(|seen| {
if let Some(done) = seen.get(s) {
return *done;
}
// Each word grows, as in a language whose words run long: a label cut to its first word
// grows too. Each word padded is kept as well, so a row wrapped mid-label is put back a
// word at a time.
let mut words: Vec<(String, String)> = Vec::new();
let mut word = |w: &str| match w.chars().any(char::is_alphabetic) {
true => {
let padded = format!("{w}{}", "o".repeat((w.chars().count() * 2).div_ceil(5)));
words.push((w.to_string(), padded.clone()));
padded
}
false => w.to_string(),
};
let line = |l: &str| match l.trim().is_empty() || l.contains('{') {
true => l.to_string(),
false => format!("{l}{}", "o".repeat((l.chars().count() * 2).div_ceil(5))),
false => l.split(' ').map(&mut word).collect::<Vec<_>>().join(" "),
};
let padded: &'static str = Box::leak(s.split('\n').map(line).collect::<Vec<_>>().join("\n").into_boxed_str());
seen.insert(s.to_string(), padded);
for (w, p) in words {
seen.entry(w).or_insert_with(|| Box::leak(p.into_boxed_str()));
}
padded
})
}
Expand Down Expand Up @@ -84,5 +99,9 @@ mod tests {
assert_eq!(super::unpadded(long), "Goodbye");
assert_eq!(super::unpadded(&format!("{short} {long}")), "Go Goodbye");
assert_eq!(super::replace_words("GooGoo", "Goo", "Go"), "GooGoo");
// A row of a wrapped label holds some of its words: each is put back.
let words = super::pad("Single Symbol");
let first = words.split(' ').next().unwrap_or_default();
assert_eq!(super::unpadded(first), "Single");
}
}
Loading
Loading