mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 04:11:27 -06:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bf8e2fdb3 | ||
|
|
107659f059 | ||
|
|
a1aceae087 |
@@ -188,13 +188,17 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
egui::CentralPanel::default().frame(egui::Frame::NONE.fill(t.ribbon).inner_margin(egui::Margin::symmetric(0, 30))).show(ui, |ui| {
|
||||
// The side padding sits inside the pages, so the scroll area reaches the window's edge.
|
||||
let pad = egui::Frame::NONE.inner_margin(egui::Margin::symmetric(40, 0));
|
||||
// The Print page fills the pane and scrolls its settings and its preview itself (#1156).
|
||||
if app.ui.backstage_page == "print" {
|
||||
// The Print page fills the pane and scrolls its settings and its preview itself (#1156)
|
||||
// when at least the settings column fits; narrower windows fall through to sideways scroll.
|
||||
if app.ui.backstage_page == "print" && ui.available_width() >= 80.0 + crate::print_page::SETTINGS_WIDTH {
|
||||
pad.show(ui, |ui| crate::rtl::root(ui, |ui| export_page(app, ui)));
|
||||
return;
|
||||
}
|
||||
// Full width, so the bar sits at the window's edge and the wheel works over the whole page (#5282).
|
||||
egui::ScrollArea::vertical().auto_shrink([false, true]).show(ui, |ui| {
|
||||
// A page wider than a narrow window scrolls sideways instead of being cut off, with that bar
|
||||
// at the bottom of the window rather than under a short page (#5396).
|
||||
let page = app.ui.backstage_page.clone();
|
||||
crate::rtl::scroll_both(ui, &page, |ui| {
|
||||
pad.show(ui, |ui| {
|
||||
crate::rtl::root(ui, |ui| match app.ui.backstage_page.as_str() {
|
||||
"home" => home_page(app, ui),
|
||||
@@ -207,7 +211,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
"options" => crate::options::page(app, ui),
|
||||
_ => home_page(app, ui),
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -837,15 +841,42 @@ fn save_as_page(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
/// File › Info: document properties and protection at the reading start, with statistics beside them.
|
||||
fn info_page(app: &mut WordApp, ui: &mut Ui) {
|
||||
heading(ui, "Info");
|
||||
let info = app.session.run("file.info", &json!({})).unwrap_or_default();
|
||||
// Properties at the reading start, so at the right in a mirrored interface, Statistics after.
|
||||
let (first, second) = if crate::rtl::on() { (1, 0) } else { (0, 1) };
|
||||
ui.columns(2, |cols| {
|
||||
crate::rtl::root(&mut cols[first], |ui| info_properties(app, ui, &info));
|
||||
crate::rtl::root(&mut cols[second], |ui| info_statistics(ui, &info));
|
||||
let rtl = crate::rtl::flows(ui);
|
||||
let row = ui.available_rect_before_wrap();
|
||||
let gap = 32.0;
|
||||
let half = ((row.width() - gap) * 0.5).max(0.0);
|
||||
let prop_w = half.max(360.0);
|
||||
let align = if rtl { egui::Align::Max } else { egui::Align::Min };
|
||||
let layout = egui::Layout::top_down(align);
|
||||
let col1_max = if rtl {
|
||||
Rect::from_min_max(pos2(row.max.x - prop_w, row.min.y), row.max)
|
||||
} else {
|
||||
Rect::from_min_max(row.min, pos2(row.min.x + prop_w, row.max.y))
|
||||
};
|
||||
let col1 = ui.scope_builder(egui::UiBuilder::new().max_rect(col1_max).layout(layout), |ui| {
|
||||
ui.allocate_space(vec2(prop_w, 0.0));
|
||||
info_properties(app, ui, &info);
|
||||
});
|
||||
// Place Statistics strictly past the measured Properties column so wide fields or button
|
||||
// pairs never paint over Statistics in either direction; Backstage scrolls sideways when narrow.
|
||||
let col1_rect = col1.response.rect;
|
||||
let stat_w = (row.width() - gap - col1_rect.width()).max(240.0);
|
||||
let col2_max = if rtl {
|
||||
let right = col1_rect.min.x - gap;
|
||||
Rect::from_min_max(pos2(right - stat_w, row.min.y), pos2(right, row.max.y))
|
||||
} else {
|
||||
let left = col1_rect.max.x + gap;
|
||||
Rect::from_min_max(pos2(left, row.min.y), pos2(left + stat_w, row.max.y))
|
||||
};
|
||||
let col2 = ui.scope_builder(egui::UiBuilder::new().max_rect(col2_max).layout(layout), |ui| {
|
||||
ui.allocate_space(vec2(stat_w, 0.0));
|
||||
info_statistics(ui, &info);
|
||||
});
|
||||
ui.advance_cursor_after_rect(col1_rect.union(col2.response.rect));
|
||||
}
|
||||
|
||||
fn info_properties(app: &mut WordApp, ui: &mut Ui, info: &serde_json::Value) {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -1494,6 +1497,327 @@ fn file_page_wheel_at(x: f32) -> (f32, f32, egui::Rect) {
|
||||
(before.min.y, h.get_by_label("doc0.docx").rect().min.y, bar)
|
||||
}
|
||||
|
||||
/// #5396: on a window narrower than a File page, the page scrolls sideways, so the part past the
|
||||
/// right edge can be reached instead of being cut off.
|
||||
#[test]
|
||||
fn a_narrow_file_page_scrolls_sideways_to_its_cut_off_part() {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Services::default());
|
||||
a.run("ui.backstage", json!({"value": true, "page": "home"})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(760.0, 500.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(4);
|
||||
// The harness keeps an 8 point margin, so the window edge is at x=752.
|
||||
let before = h.get_by_label("Résumé").rect();
|
||||
assert!(before.right() > 752.0, "the last template tile must start out past the window edge: {before:?}");
|
||||
h.event(egui::Event::PointerMoved(egui::pos2(400.0, 300.0)));
|
||||
h.event(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(-400.0, 0.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
});
|
||||
h.run_steps(4);
|
||||
let after = h.get_by_label("Résumé").rect();
|
||||
assert!(after.right() <= 752.0, "the last template tile must scroll into view: before={before:?}, after={after:?}");
|
||||
}
|
||||
|
||||
/// #5396: the sideways scrollbar of a narrow File page sits at the bottom of the window, like the
|
||||
/// vertical one sits at its right edge (#5282), not under the end of a short page.
|
||||
#[test]
|
||||
fn a_narrow_file_pages_sideways_bar_sits_at_the_window_bottom() {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Services::default());
|
||||
a.run("ui.backstage", json!({"value": true, "page": "home"})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(760.0, 500.0)).build_ui_state(
|
||||
|ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
a,
|
||||
);
|
||||
h.run_steps(4);
|
||||
let bar = h
|
||||
.query_all_by_role(egui::accesskit::Role::ScrollBar)
|
||||
.map(|n| n.rect())
|
||||
.find(|r| r.width() > r.height())
|
||||
.expect("the File page's sideways scrollbar");
|
||||
// The harness keeps an 8 point margin, and the page keeps 30 points below it: 500 - 8 - 30.
|
||||
assert!((bar.bottom() - 462.0).abs() < 1.0, "expected the sideways scrollbar at the bottom of the page area: {bar:?}");
|
||||
}
|
||||
|
||||
/// A right-to-left test language. Only its code makes it right to left, so its catalog needs no
|
||||
/// Arabic text, and the test no Arabic font.
|
||||
fn right_to_left() -> crate::i18n::Lang {
|
||||
crate::i18n::fixture_lang("ar", "\tHome\tHome\n")
|
||||
}
|
||||
|
||||
/// A File page of `doc` in a window `width` wide and 500 high, after its first frame, drawn in the
|
||||
/// language `lang` holds. It sets that after `logic` and calls `show` directly, since a whole frame
|
||||
/// sets the language back from its setting.
|
||||
fn opened_page(doc: wordcraft_doc::Document, page: &str, width: f32, lang: Rc<Cell<crate::i18n::Lang>>) -> egui_kittest::Harness<'static, WordApp> {
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(doc), Services::default());
|
||||
a.run("ui.backstage", json!({"value": true, "page": page})).unwrap();
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(width, 500.0)).build_ui_state(
|
||||
move |ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
crate::i18n::set_current(lang.get());
|
||||
crate::rtl::sync(&ctx);
|
||||
super::show(app, ui);
|
||||
},
|
||||
a,
|
||||
)
|
||||
}
|
||||
|
||||
/// The same page of an empty document, settled.
|
||||
fn page_at(page: &str, width: f32, lang: Rc<Cell<crate::i18n::Lang>>) -> egui_kittest::Harness<'static, WordApp> {
|
||||
let mut h = opened_page(wordcraft_doc::Document::new(), page, width, lang);
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// The same File page in the smallest window this file measures.
|
||||
fn narrow_page(page: &str, lang: Rc<Cell<crate::i18n::Lang>>) -> egui_kittest::Harness<'static, WordApp> {
|
||||
page_at(page, 760.0, lang)
|
||||
}
|
||||
|
||||
/// Turns the wheel sideways over the page by `dx` points.
|
||||
fn wheel_sideways(h: &mut egui_kittest::Harness<'static, WordApp>, dx: f32) {
|
||||
h.event(egui::Event::PointerMoved(egui::pos2(400.0, 300.0)));
|
||||
h.event(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(dx, 0.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
});
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// The left end of the page's leftmost widget or text.
|
||||
fn leftmost(h: &egui_kittest::Harness<'static, WordApp>) -> f32 {
|
||||
use egui::accesskit::Role;
|
||||
[Role::Button, Role::CheckBox, Role::Label, Role::TextInput, Role::ComboBox]
|
||||
.into_iter()
|
||||
.flat_map(|role| h.query_all_by_role(role).map(|n| n.rect().left()).collect::<Vec<_>>())
|
||||
.fold(f32::MAX, f32::min)
|
||||
}
|
||||
|
||||
/// #5396: a right-to-left page runs from the right and overflows on its left. It opens at its
|
||||
/// start, with the sideways bar there, and the part past the left edge scrolls into view.
|
||||
#[test]
|
||||
fn a_narrow_right_to_left_file_page_scrolls_sideways_to_its_cut_off_part() {
|
||||
let mut h = narrow_page("home", Rc::new(Cell::new(right_to_left())));
|
||||
let first = h.get_by_label("Blank document").rect();
|
||||
let last = h.get_by_label("Résumé").rect();
|
||||
assert!(first.left() > last.left(), "the tiles must run from the right: first={first:?}, last={last:?}");
|
||||
assert!(last.left() < 8.0, "the last tile must start out past the window's left edge: {last:?}");
|
||||
let bar = h.query_all_by_role(egui::accesskit::Role::ScrollBar).map(|n| n.rect()).find(|r| r.width() > r.height()).expect("a sideways scrollbar");
|
||||
// The page keeps 40 points of padding to the edge of its area.
|
||||
assert!((bar.right() - 40.0 - first.right()).abs() < 1.0, "the page must open at its start: {first:?}, {bar:?}");
|
||||
wheel_sideways(&mut h, 400.0);
|
||||
let scrolled = h.get_by_label("Résumé").rect();
|
||||
assert!(scrolled.left() >= 8.0, "the last tile must scroll into view: {last:?}, then {scrolled:?}");
|
||||
wheel_sideways(&mut h, -800.0);
|
||||
assert_eq!(h.get_by_label("Résumé").rect(), last, "the page must scroll back to its start");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: every File page wider than the window can be scrolled to its far end right to left too:
|
||||
/// Options' settings and New's tiles, not only Home.
|
||||
#[test]
|
||||
fn every_narrow_right_to_left_file_page_reaches_its_far_end() {
|
||||
for page in ["home", "new", "options"] {
|
||||
let mut h = narrow_page(page, Rc::new(Cell::new(right_to_left())));
|
||||
let start = leftmost(&h);
|
||||
assert!(start < 8.0, "{page} must overflow on the left: {start}");
|
||||
wheel_sideways(&mut h, 2000.0);
|
||||
let end = leftmost(&h);
|
||||
assert!(end >= 8.0, "{page} must reach its far end: from {start} to {end}");
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: the wheel moves a right-to-left page right after it opens, with no frame in between that
|
||||
/// sets the page in place.
|
||||
#[test]
|
||||
fn a_right_to_left_file_page_takes_the_wheel_right_after_it_opens() {
|
||||
let doc = wordcraft_doc::Document::new();
|
||||
let mut h = opened_page(doc, "home", 760.0, Rc::new(Cell::new(right_to_left())));
|
||||
wheel_sideways(&mut h, 400.0);
|
||||
let last = h.get_by_label("Résumé").rect();
|
||||
assert!(last.left() >= 8.0, "the last tile must scroll into view: {last:?}");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: the issue's own example. Options > Language's description of the interface language is
|
||||
/// wider than a narrow window, and its far end can be reached in either direction.
|
||||
#[test]
|
||||
fn the_language_pane_reaches_its_far_end_in_either_direction() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
for (lang, dx) in [(crate::i18n::Lang::EN, -3000.0), (right_to_left(), 3000.0)] {
|
||||
let mut h = narrow_page("options", Rc::new(Cell::new(lang)));
|
||||
h.state_mut().ui.options_pane = "language".into();
|
||||
h.run_steps(4);
|
||||
let description = |h: &egui_kittest::Harness<'static, WordApp>| {
|
||||
let mut labels = h.query_all_by_role(Role::Label);
|
||||
labels.find(|n| n.accesskit_node().value().is_some_and(|v| v.starts_with("Automatic follows"))).expect("the description").rect()
|
||||
};
|
||||
let before = description(&h);
|
||||
assert!(before.left() < 8.0 || before.right() > 752.0, "it must start out past the window: {before:?}");
|
||||
wheel_sideways(&mut h, dx);
|
||||
let after = description(&h);
|
||||
assert!(after.left() >= 8.0 && after.right() <= 752.0, "it must scroll into view: {after:?}");
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: an offset doesn't carry over a change of direction: the page stands at its start in the
|
||||
/// new direction, whichever way the interface turned.
|
||||
#[test]
|
||||
fn a_sideways_scroll_does_not_carry_over_a_change_of_direction() {
|
||||
let arabic = right_to_left();
|
||||
let start_rtl = narrow_page("home", Rc::new(Cell::new(arabic))).get_by_label("Blank document").rect();
|
||||
let lang = Rc::new(Cell::new(crate::i18n::Lang::EN));
|
||||
let mut h = narrow_page("home", Rc::clone(&lang));
|
||||
let start_ltr = h.get_by_label("Blank document").rect();
|
||||
wheel_sideways(&mut h, -400.0);
|
||||
let scrolled = h.get_by_label("Blank document").rect();
|
||||
assert_ne!(scrolled, start_ltr, "the wheel must have scrolled the page");
|
||||
lang.set(arabic);
|
||||
h.step();
|
||||
assert_eq!(h.get_by_label("Blank document").rect(), start_rtl, "the page must stand at its right-to-left start");
|
||||
lang.set(crate::i18n::Lang::EN);
|
||||
h.step();
|
||||
assert_eq!(h.get_by_label("Blank document").rect(), start_ltr, "the page must stand at its left-to-right start");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: a sideways scroll stays with its page, so the next File page opens at its own start.
|
||||
#[test]
|
||||
fn a_file_page_opens_at_its_start_after_another_page_scrolled_sideways() {
|
||||
for (lang, dx) in [(crate::i18n::Lang::EN, -3000.0), (right_to_left(), 3000.0)] {
|
||||
let lang = Rc::new(Cell::new(lang));
|
||||
let start = narrow_page("new", Rc::clone(&lang)).get_by_label("Blank document").rect();
|
||||
let mut h = narrow_page("home", lang);
|
||||
let opened = h.get_by_label("Blank document").rect();
|
||||
wheel_sideways(&mut h, dx);
|
||||
assert_ne!(h.get_by_label("Blank document").rect(), opened, "the wheel must have scrolled Home");
|
||||
h.state_mut().ui.backstage_page = "new".into();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.get_by_label("Blank document").rect(), start, "New must open at its start");
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: a window wide enough for the page leaves nothing to scroll, right to left too, and a
|
||||
/// narrower one opens the page at its start again.
|
||||
#[test]
|
||||
fn a_right_to_left_file_page_follows_the_window_width() {
|
||||
let mut h = narrow_page("home", Rc::new(Cell::new(right_to_left())));
|
||||
let start = h.get_by_label("Blank document").rect();
|
||||
h.set_size(egui::vec2(1440.0, 500.0));
|
||||
h.run_steps(4);
|
||||
assert!(h.query_all_by_role(egui::accesskit::Role::ScrollBar).all(|n| n.rect().height() > n.rect().width()));
|
||||
assert!(h.get_by_label("Résumé").rect().left() >= 8.0, "the whole page must fit");
|
||||
h.set_size(egui::vec2(760.0, 500.0));
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.get_by_label("Blank document").rect(), start, "the page must stand at its start again");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: a window too narrow for Print's preview shows the settings alone, in either direction,
|
||||
/// and a window narrower than the settings column itself scrolls sideways cleanly without clipping.
|
||||
#[test]
|
||||
fn a_narrow_print_page_shows_its_settings_alone() {
|
||||
use egui::accesskit::Role;
|
||||
for (lang, dx) in [(crate::i18n::Lang::EN, -2000.0), (right_to_left(), 2000.0)] {
|
||||
for width in [500.0, 760.0, 850.0] {
|
||||
let mut h = page_at("print", width, Rc::new(Cell::new(lang)));
|
||||
assert!(h.query_by_label("Next sheet").is_none(), "at {width}: there is no room for the preview");
|
||||
let save = h.get_by_label("Save these pages as PDF…").rect();
|
||||
if width >= 760.0 {
|
||||
assert!(save.left() >= 8.0 && save.right() <= width - 8.0, "at {width}: the settings must fit: {save:?}");
|
||||
} else {
|
||||
let v_bars: Vec<egui::Rect> = h.query_all_by_role(Role::ScrollBar).map(|n| n.rect()).filter(|r| r.height() > r.width()).collect();
|
||||
assert!(v_bars.len() <= 1, "at {width} (rtl={}): expected no clipped inner vertical bar: {v_bars:?}", lang.rtl());
|
||||
if lang.rtl() {
|
||||
let close_nav = h.get_by_label("Close").rect();
|
||||
assert!(save.right() < close_nav.left(), "at {width}: RTL settings {save:?} must stay left of nav {close_nav:?}");
|
||||
assert!(save.left() < 8.0, "at {width}: RTL wide button {save:?} extends leftward to scroll");
|
||||
} else {
|
||||
let nav = h.get_by_label("Close").rect();
|
||||
assert!(save.left() > nav.right(), "at {width}: LTR settings {save:?} must start right of nav {nav:?}");
|
||||
}
|
||||
wheel_page_sideways(&mut h, dx);
|
||||
let scrolled = h.get_by_label("Save these pages as PDF…").rect();
|
||||
if lang.rtl() {
|
||||
assert!(scrolled.left() >= 8.0, "at {width}: after RTL sideways scroll, button far left {scrolled:?} must fit");
|
||||
} else {
|
||||
assert!(scrolled.right() <= width - 8.0, "at {width}: after LTR sideways scroll, button far right {scrolled:?} must fit");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: Print's preview bar stays inside a narrower preview, on two rows when it needs them, with
|
||||
/// three-digit page numbers and wide sheet labels too, and no button or page indicator runs over another.
|
||||
#[test]
|
||||
fn a_print_preview_keeps_its_whole_bar_at_any_width_it_shows() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let text = "line\n".repeat(9000);
|
||||
let wide_sheet_ltr = crate::i18n::fixture_lang("x-fixture", "\tSheet {page} of {pages}\tSheet {page} out of all {pages}\n");
|
||||
let wide_sheet_ar = crate::i18n::fixture_lang("ar", "\tSheet {page} of {pages}\tSheet {page} out of all {pages}\n");
|
||||
let mut tested_preview = false;
|
||||
for (lang, needle) in [(crate::i18n::Lang::EN, "Sheet "), (right_to_left(), "Sheet "), (wide_sheet_ltr, "out"), (wide_sheet_ar, "out")] {
|
||||
for width in [884.0, 890.0, 900.0, 910.0, 920.0, 950.0, 1000.0, 1004.0, 1010.0, 1020.0, 1050.0, 1100.0] {
|
||||
let doc = wordcraft_doc::Document::from_text(&text);
|
||||
let mut h = opened_page(doc, "print", width, Rc::new(Cell::new(lang)));
|
||||
h.run_steps(2);
|
||||
h.state_mut().ui.print.preview = 120;
|
||||
h.run_steps(4);
|
||||
if h.query_by_label("Next sheet").is_none() {
|
||||
continue;
|
||||
}
|
||||
tested_preview = true;
|
||||
let mut bar: Vec<_> =
|
||||
["Previous sheet", "Next sheet", "Zoom Out", "Zoom In", "One Page"].into_iter().map(|name| h.get_by_label(name).rect()).collect();
|
||||
let page = h.query_all_by_role(Role::Label).find(|n| n.accesskit_node().value().is_some_and(|v| v.contains("121") && v.contains(needle)));
|
||||
bar.push(
|
||||
page.unwrap_or_else(|| {
|
||||
let vals: Vec<_> = h.query_all_by_role(Role::Label).filter_map(|n| n.accesskit_node().value()).collect();
|
||||
panic!("no page indicator matching {needle:?} at {width} (rtl={}) in {vals:?}", lang.rtl());
|
||||
})
|
||||
.rect(),
|
||||
);
|
||||
for (i, r) in bar.iter().enumerate() {
|
||||
assert!(r.left() >= 8.0 && r.right() <= width - 8.0 && r.bottom() <= 492.0, "at {width} (rtl={}): {r:?} must fit", lang.rtl());
|
||||
assert!(!bar[i + 1..].iter().any(|o| o.intersects(*r)), "at {width} (rtl={}): {r:?} covers something in {bar:?}", lang.rtl());
|
||||
}
|
||||
if lang.rtl() {
|
||||
assert!(bar[0].left() > bar[1].right(), "at {width} RTL: Prev {:?} must be right of Next {:?}", bar[0], bar[1]);
|
||||
assert!(bar[4].right() < bar[2].left(), "at {width} RTL: One Page {:?} must be left of Zoom Out {:?}", bar[4], bar[2]);
|
||||
} else {
|
||||
assert!(bar[0].right() < bar[1].left(), "at {width} LTR: Prev {:?} must be left of Next {:?}", bar[0], bar[1]);
|
||||
assert!(bar[4].left() > bar[2].right(), "at {width} LTR: One Page {:?} must be right of Zoom Out {:?}", bar[4], bar[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(tested_preview, "must verify at least one width where preview is shown");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5282: the File page scrolls with the wheel over its right side.
|
||||
#[test]
|
||||
fn the_file_page_scrolls_with_the_wheel_over_its_right_side() {
|
||||
@@ -1647,6 +1971,385 @@ fn rtl_template_titles_are_right_aligned() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Finds the first `Label` whose AccessKit value starts with `prefix`.
|
||||
fn label_rect_starting(h: &egui_kittest::Harness<'static, WordApp>, prefix: &str) -> egui::Rect {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
h.query_all_by_role(Role::Label)
|
||||
.find(|n| n.accesskit_node().value().is_some_and(|v| v.starts_with(prefix)))
|
||||
.unwrap_or_else(|| panic!("expected label starting with {prefix:?}"))
|
||||
.rect()
|
||||
}
|
||||
|
||||
/// Builds a document whose paragraphs use distinct proofing tags so Options > Language > Your
|
||||
/// languages shows multiple rows without touching the global pack backend.
|
||||
fn multilingual_doc(tags: &[&str]) -> wordcraft_doc::Document {
|
||||
let text = vec!["Hello"; tags.len()].join("\n");
|
||||
let mut doc = wordcraft_doc::Document::from_text(&text);
|
||||
for (i, tag) in tags.iter().enumerate() {
|
||||
let mut s = wordcraft_engine::Session::new(doc);
|
||||
s.run("caret.set", &json!({"pos": {"block": i, "off": 0}})).unwrap();
|
||||
s.run("select.paragraph", &json!({})).unwrap();
|
||||
s.run("review.language", &json!({"lang": tag})).unwrap();
|
||||
doc = s.doc;
|
||||
}
|
||||
doc
|
||||
}
|
||||
|
||||
/// Scrolls the Backstage page sideways with the pointer inside `CentralPanel` for any window width
|
||||
/// (from 500 up) and direction, above inner sub-tables such as Your languages.
|
||||
fn wheel_page_sideways(h: &mut egui_kittest::Harness<'static, WordApp>, dx: f32) {
|
||||
h.event(egui::Event::PointerMoved(egui::pos2(250.0, 100.0)));
|
||||
h.event(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(dx, 0.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
});
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// #5396: Options > Language > Your languages keeps a fixed column count while Backstage scrolls
|
||||
/// sideways (no mid-scroll column jump) and draws no inner horizontal scrollbar over Set as default.
|
||||
#[test]
|
||||
fn your_languages_keeps_columns_and_buttons_unobscured_while_scrolling() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
for (width, lang, dx_click, dx_edge) in [
|
||||
(1440.0, crate::i18n::Lang::EN, 0.0, 0.0),
|
||||
(1440.0, right_to_left(), 0.0, 0.0),
|
||||
(760.0, crate::i18n::Lang::EN, -2000.0, -2000.0),
|
||||
(760.0, right_to_left(), 200.0, 2000.0),
|
||||
] {
|
||||
let doc = multilingual_doc(&["en-US", "fr-FR", "pl-PL"]);
|
||||
let mut h = opened_page(doc, "options", width, Rc::new(Cell::new(lang)));
|
||||
h.state_mut().ui.options_pane = "language".into();
|
||||
// Verify first frame (single step) keeps 3 columns right-to-left too before settling.
|
||||
h.step();
|
||||
let built_in_first = label_rect_starting(&h, "Built in");
|
||||
let set_first = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("Set as default on first frame")
|
||||
.rect();
|
||||
assert!(set_first.left() > built_in_first.right(), "first frame at {width} (rtl={}): {set_first:?} vs {built_in_first:?}", lang.rtl());
|
||||
if lang.rtl() {
|
||||
let sidebar = h.get_by_label("General").rect();
|
||||
assert!(set_first.right() < sidebar.left(), "first frame RTL action at {width}: {set_first:?} crossed sidebar {sidebar:?}");
|
||||
}
|
||||
h.run_steps(4);
|
||||
|
||||
let heading_before = label_rect_starting(&h, "Your languages");
|
||||
let built_in_before = label_rect_starting(&h, "Built in");
|
||||
let set_before = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("Set as default button")
|
||||
.rect();
|
||||
|
||||
// Keep the three-column grid (actions sit in column 3, beside column 2, not stacked under it).
|
||||
assert!(
|
||||
set_before.left() > built_in_before.right(),
|
||||
"at {width} (rtl={}): Set as default {set_before:?} must sit right of col 2 {built_in_before:?}",
|
||||
lang.rtl()
|
||||
);
|
||||
|
||||
// Any sideways scrollbar belongs at the bottom of the Backstage window, never over Set as default.
|
||||
let h_bars: Vec<egui::Rect> = h.query_all_by_role(Role::ScrollBar).map(|n| n.rect()).filter(|r| r.width() > r.height()).collect();
|
||||
if width >= 1440.0 {
|
||||
assert!(h_bars.is_empty(), "desktop {width} (rtl={}) needs no horizontal scrollbar: {h_bars:?}", lang.rtl());
|
||||
assert!(set_before.left() >= 8.0 && set_before.right() <= width - 8.0, "desktop button must fit: {set_before:?}");
|
||||
} else {
|
||||
assert!(h_bars.len() <= 1, "at {width} (rtl={}): expected at most one sideways scrollbar, got {h_bars:?}", lang.rtl());
|
||||
for bar in &h_bars {
|
||||
assert!((bar.bottom() - 462.0).abs() < 1.0, "bar must sit at Backstage bottom: {bar:?}");
|
||||
assert!(!bar.intersects(set_before), "bar {bar:?} overlaps Set as default {set_before:?}");
|
||||
}
|
||||
let view = *h_bars.first().expect("narrow Backstage exposes horizontal scrollbar");
|
||||
wheel_sideways(&mut h, dx_click);
|
||||
let heading_after = label_rect_starting(&h, "Your languages");
|
||||
let built_in_after = label_rect_starting(&h, "Built in");
|
||||
let set_after = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("Set as default after scroll")
|
||||
.rect();
|
||||
assert!(
|
||||
((set_after.top() - heading_after.top()) - (set_before.top() - heading_before.top())).abs() < 0.5
|
||||
&& ((set_after.left() - heading_after.left()) - (set_before.left() - heading_before.left())).abs() < 0.5,
|
||||
"Set as default jumped relative to heading during scroll at rtl={}: before=({heading_before:?}, {set_before:?}), after=({heading_after:?}, {set_after:?})",
|
||||
lang.rtl(),
|
||||
);
|
||||
assert!(
|
||||
((built_in_after.top() - heading_after.top()) - (built_in_before.top() - heading_before.top())).abs() < 0.5
|
||||
&& ((built_in_after.left() - heading_after.left()) - (built_in_before.left() - heading_before.left())).abs() < 0.5,
|
||||
"column 2 jumped relative to heading during scroll at rtl={}: before=({heading_before:?}, {built_in_before:?}), after=({heading_after:?}, {built_in_after:?})",
|
||||
lang.rtl(),
|
||||
);
|
||||
assert!(
|
||||
set_after.left() >= view.left() && set_after.right() <= view.right(),
|
||||
"Set as default must stay inside CentralPanel {view:?} at rtl={}: {set_after:?}",
|
||||
lang.rtl()
|
||||
);
|
||||
h.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("clickable Set as default")
|
||||
.click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(
|
||||
h.state().session.prefs.default_language.as_deref(),
|
||||
Some("fr-FR"),
|
||||
"clicking scrolled Set as default applies French at rtl={}",
|
||||
lang.rtl()
|
||||
);
|
||||
|
||||
// Also scroll to the trailing horizontal edge to confirm columns stay rigid end-to-end.
|
||||
wheel_sideways(&mut h, dx_edge);
|
||||
let heading_end = label_rect_starting(&h, "Your languages");
|
||||
let built_in_end = label_rect_starting(&h, "Built in");
|
||||
assert!(
|
||||
((built_in_end.top() - heading_end.top()) - (built_in_before.top() - heading_before.top())).abs() < 0.5
|
||||
&& ((built_in_end.left() - heading_end.left()) - (built_in_before.left() - heading_before.left())).abs() < 0.5,
|
||||
"column 2 jumped at scroll end for rtl={}: before=({heading_before:?}, {built_in_before:?}), end=({heading_end:?}, {built_in_end:?})",
|
||||
lang.rtl(),
|
||||
);
|
||||
}
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: a tall Your languages list renders inside Backstage's own scroll area (never a nested
|
||||
/// inner vertical scrollbar that clips onto column 2 before scrolling sideways), reaches Dictionaries
|
||||
/// below when scrolled vertically, and stays strictly left of the Options sidebar in RTL from frame 1.
|
||||
#[test]
|
||||
fn your_languages_tall_list_scrolls_vertically_without_bar_overlap() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let tags = ["en-US", "fr-FR", "de-DE", "es-ES", "it-IT", "nl-NL", "pl-PL", "pt-BR", "sv-SE", "cs-CZ", "tr-TR", "hr-HR"];
|
||||
for (width, lang, dx) in [
|
||||
(1440.0, crate::i18n::Lang::EN, 0.0),
|
||||
(1440.0, right_to_left(), 0.0),
|
||||
(760.0, crate::i18n::Lang::EN, -2000.0),
|
||||
(760.0, right_to_left(), 2000.0),
|
||||
] {
|
||||
let mut h = opened_page(multilingual_doc(&tags), "options", width, Rc::new(Cell::new(lang)));
|
||||
h.state_mut().ui.options_pane = "language".into();
|
||||
// Frame 1 of the language pane must already anchor RTL cleanly inside the Options sidebar.
|
||||
h.step();
|
||||
if lang.rtl() {
|
||||
let sidebar = h.get_by_label("General").rect();
|
||||
let built_in_first = label_rect_starting(&h, "Built in");
|
||||
assert!(built_in_first.right() < sidebar.left(), "at {width}: frame 1 RTL col 2 {built_in_first:?} crossed sidebar {sidebar:?}");
|
||||
for btn in h.query_all_by_role(Role::Button).filter(|n| n.accesskit_node().label().as_deref() == Some("Set as default")) {
|
||||
assert!(btn.rect().right() < sidebar.left(), "at {width}: frame 1 RTL action {:?} crossed sidebar {sidebar:?}", btn.rect());
|
||||
}
|
||||
}
|
||||
h.run_steps(4);
|
||||
|
||||
// Before scrolling sideways too, keep at most Backstage's single page vertical scrollbar and
|
||||
// keep RTL columns strictly left of the Options sidebar.
|
||||
let v_bars_before: Vec<egui::Rect> = h.query_all_by_role(Role::ScrollBar).map(|n| n.rect()).filter(|r| r.height() > r.width()).collect();
|
||||
assert!(v_bars_before.len() <= 1, "at {width} (rtl={}): expected no nested vertical scrollbar, got {v_bars_before:?}", lang.rtl());
|
||||
if lang.rtl() {
|
||||
let sidebar = h.get_by_label("General").rect();
|
||||
let built_in_before = label_rect_starting(&h, "Built in");
|
||||
assert!(built_in_before.right() < sidebar.left(), "at {width}: settled RTL col 2 {built_in_before:?} crossed sidebar {sidebar:?}");
|
||||
for btn in h.query_all_by_role(Role::Button).filter(|n| n.accesskit_node().label().as_deref() == Some("Set as default")) {
|
||||
assert!(btn.rect().right() < sidebar.left(), "at {width}: settled RTL action {:?} crossed sidebar {sidebar:?}", btn.rect());
|
||||
}
|
||||
}
|
||||
|
||||
if width < 1440.0 {
|
||||
wheel_page_sideways(&mut h, dx);
|
||||
}
|
||||
let v_bars: Vec<egui::Rect> = h.query_all_by_role(Role::ScrollBar).map(|n| n.rect()).filter(|r| r.height() > r.width()).collect();
|
||||
assert!(v_bars.len() <= 1, "at {width} (rtl={}) after sideways scroll: {v_bars:?}", lang.rtl());
|
||||
let v_bar = v_bars.into_iter().next().expect("tall Options > Language exposes Backstage's vertical scrollbar");
|
||||
let built_in = label_rect_starting(&h, "Built in");
|
||||
if width >= 1440.0 {
|
||||
assert!(!v_bar.intersects(built_in), "at {width} (rtl={}): vbar {v_bar:?} overlaps status {built_in:?}", lang.rtl());
|
||||
}
|
||||
for btn in h.query_all_by_role(Role::Button).filter(|n| n.accesskit_node().label().as_deref() == Some("Set as default")) {
|
||||
assert!(!v_bar.intersects(btn.rect()), "at {width} (rtl={}): vbar {v_bar:?} overlaps button {:?}", lang.rtl(), btn.rect());
|
||||
}
|
||||
if lang.rtl() {
|
||||
// Table and page scrollbar stay left of the Options sidebar instead of jutting right past it.
|
||||
let sidebar = h.get_by_label("General").rect();
|
||||
assert!(v_bar.right() < sidebar.left(), "RTL vertical bar {v_bar:?} must not cross sidebar {sidebar:?}");
|
||||
assert!(built_in.right() < sidebar.left(), "RTL col 2 {built_in:?} must not cross sidebar {sidebar:?}");
|
||||
for btn in h.query_all_by_role(Role::Button).filter(|n| n.accesskit_node().label().as_deref() == Some("Set as default")) {
|
||||
assert!(btn.rect().right() < sidebar.left(), "RTL action {:?} must not cross sidebar {sidebar:?}", btn.rect());
|
||||
}
|
||||
}
|
||||
|
||||
// Scrolling vertically reaches Dictionaries below a tall Your languages list.
|
||||
h.event(egui::Event::PointerMoved(egui::pos2(250.0, 200.0)));
|
||||
h.event(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(0.0, -2000.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
});
|
||||
h.run_steps(4);
|
||||
let dicts = label_rect_starting(&h, "Dictionaries folder:");
|
||||
assert!(dicts.top() >= 0.0 && dicts.bottom() <= 500.0, "at {width} (rtl={}): Dictionaries must scroll into view: {dicts:?}", lang.rtl());
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: File > Info separates Properties/Protect Document and Statistics cleanly without column
|
||||
/// overlap across desktop and narrow windows (encrypted and unencrypted), in both directions, and
|
||||
/// scrolls sideways cleanly when narrower than both columns.
|
||||
#[test]
|
||||
fn info_page_columns_never_overlap_across_widths_and_directions() {
|
||||
use egui::accesskit::Role;
|
||||
for width in [1440.0, 760.0, 500.0] {
|
||||
for encrypted in [false, true] {
|
||||
for (lang, dx) in [(crate::i18n::Lang::EN, -2000.0), (right_to_left(), 2000.0)] {
|
||||
let doc = wordcraft_doc::Document::from_text("XYZ");
|
||||
let mut h = opened_page(doc, "info", width, Rc::new(Cell::new(lang)));
|
||||
if encrypted {
|
||||
h.state_mut().session.run("file.encrypt", &json!({"password": "synthetic-password"})).unwrap();
|
||||
}
|
||||
// Check first frame before settling too, so RTL overflow or layout init never overlaps.
|
||||
h.step();
|
||||
let first_prop = h.get_by_label(if encrypted { "Change Password…" } else { "Encrypt with Password…" }).rect();
|
||||
let first_stat = label_rect_starting(&h, "Statistics");
|
||||
assert!(!first_prop.intersects(first_stat), "first frame overlap at {width} encrypted={encrypted} rtl={}", lang.rtl());
|
||||
h.run_steps(4);
|
||||
|
||||
let rtl = lang.rtl();
|
||||
let protect_desc = label_rect_starting(&h, if encrypted { "A password is required" } else { "Anyone can open" });
|
||||
if width < 1440.0 && !encrypted {
|
||||
assert!(
|
||||
protect_desc.width() <= 365.0,
|
||||
"at {width} rtl={rtl}: Protect description must wrap inside Properties column: {protect_desc:?}"
|
||||
);
|
||||
}
|
||||
let prop_rects = [
|
||||
label_rect_starting(&h, "Properties"),
|
||||
h.get_by_role_and_label(Role::TextInput, "Category").rect(),
|
||||
h.get_by_label("Advanced Properties…").rect(),
|
||||
label_rect_starting(&h, "Protect Document"),
|
||||
protect_desc,
|
||||
h.get_by_label(if encrypted { "Change Password…" } else { "Encrypt with Password…" }).rect(),
|
||||
];
|
||||
let mut prop_list = prop_rects.to_vec();
|
||||
if encrypted {
|
||||
let remove = h.get_by_label("Remove Password").rect();
|
||||
assert!(!prop_rects[5].intersects(remove), "password buttons overlap at {width} rtl={rtl}");
|
||||
prop_list.push(remove);
|
||||
}
|
||||
let stat_rects = [
|
||||
label_rect_starting(&h, "Statistics"),
|
||||
label_rect_starting(&h, "Paragraphs:"),
|
||||
label_rect_starting(&h, "Comments:"),
|
||||
label_rect_starting(&h, "Location:"),
|
||||
];
|
||||
|
||||
for p in &prop_list {
|
||||
for s in &stat_rects {
|
||||
assert!(!p.intersects(*s), "at width={width} encrypted={encrypted} rtl={rtl}: Properties {p:?} overlaps Statistics {s:?}");
|
||||
if rtl {
|
||||
assert!(
|
||||
s.right() < p.left() - 1.0,
|
||||
"at width={width} encrypted={encrypted} rtl=true: Statistics {s:?} must sit strictly left of Properties {p:?}"
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
p.right() < s.left() - 1.0,
|
||||
"at width={width} encrypted={encrypted} rtl=false: Properties {p:?} must sit strictly left of Statistics {s:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if width >= 1440.0 {
|
||||
assert!(
|
||||
h.query_all_by_role(Role::ScrollBar).all(|n| n.rect().height() > n.rect().width()),
|
||||
"desktop {width} encrypted={encrypted} rtl={rtl} needs no horizontal scrollbar",
|
||||
);
|
||||
for r in prop_list.iter().chain(stat_rects.iter()) {
|
||||
assert!(r.left() >= 8.0 && r.right() <= width - 8.0, "desktop item clipped: {r:?}");
|
||||
}
|
||||
} else {
|
||||
let h_bars: Vec<egui::Rect> = h.query_all_by_role(Role::ScrollBar).map(|n| n.rect()).filter(|r| r.width() > r.height()).collect();
|
||||
let view = *h_bars.first().expect("narrow Info exposes Backstage horizontal scrollbar");
|
||||
wheel_page_sideways(&mut h, dx);
|
||||
let scrolled_stat = label_rect_starting(&h, "Statistics");
|
||||
let scrolled_loc = label_rect_starting(&h, "Location:");
|
||||
assert!(
|
||||
scrolled_stat.left() >= view.left()
|
||||
&& scrolled_stat.right() <= view.right()
|
||||
&& scrolled_loc.left() >= view.left()
|
||||
&& scrolled_loc.right() <= view.right(),
|
||||
"after sideways scroll at width={width} encrypted={encrypted} rtl={rtl}, Statistics ({scrolled_stat:?}, {scrolled_loc:?}) must fit inside CentralPanel {view:?}",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// #5396: when Your languages is wider than an RTL parent column with `rtl::sync` active, the grid
|
||||
/// grows leftward from its right anchor instead of spilling rightwards into an adjacent sidebar
|
||||
/// already on true frame 1.
|
||||
#[test]
|
||||
fn your_languages_rtl_anchors_right_when_wider_than_container() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::NodeT;
|
||||
let tags = ["en-US", "fr-FR", "de-DE", "es-ES", "it-IT", "nl-NL", "pl-PL", "pt-BR", "sv-SE", "cs-CZ", "tr-TR", "hr-HR"];
|
||||
let doc = multilingual_doc(&tags);
|
||||
let app = WordApp::new(wordcraft_engine::Session::new(doc), Services::default());
|
||||
let rtl_lang = right_to_left();
|
||||
let show = Rc::new(Cell::new(false));
|
||||
let show_in_ui = Rc::clone(&show);
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 500.0)).build_ui_state(
|
||||
move |ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
crate::i18n::set_current(rtl_lang);
|
||||
crate::rtl::sync(&ctx);
|
||||
if !show_in_ui.get() {
|
||||
return;
|
||||
}
|
||||
let box_rect = egui::Rect::from_min_max(egui::pos2(280.0, 20.0), egui::pos2(700.0, 460.0));
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(box_rect).layout(egui::Layout::top_down(egui::Align::Max)), |ui| {
|
||||
crate::language_packs::your_languages_section(app, ui);
|
||||
});
|
||||
},
|
||||
app,
|
||||
);
|
||||
show.set(true);
|
||||
// True frame 1 for your_languages_section: must already anchor right without spilling past 700.
|
||||
h.step();
|
||||
let english_first = label_rect_starting(&h, "English (United States)");
|
||||
let set_first = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("Set as default button on true frame 1")
|
||||
.rect();
|
||||
let built_in_first = label_rect_starting(&h, "Built in");
|
||||
assert!(set_first.left() > built_in_first.right(), "frame 1 keeps 3 columns: {set_first:?} vs {built_in_first:?}");
|
||||
assert!(set_first.right() <= 700.5, "frame 1 RTL button {set_first:?} must stay left of container right edge 700");
|
||||
assert!(english_first.left() < 280.0, "frame 1 RTL table {english_first:?} must extend leftward past 280 instead of spilling right");
|
||||
assert!(h.query_all_by_role(Role::ScrollBar).count() == 0, "table itself needs no nested scrollbars inside RTL container");
|
||||
h.run_steps(4);
|
||||
let set_settled = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.find(|n| n.accesskit_node().label().as_deref() == Some("Set as default"))
|
||||
.expect("Set as default button after settle")
|
||||
.rect();
|
||||
let english_settled = label_rect_starting(&h, "English (United States)");
|
||||
assert!(set_settled.right() <= 700.5, "settled RTL button {set_settled:?} must stay left of container right edge 700");
|
||||
assert!(english_settled.left() < 280.0, "settled RTL table {english_settled:?} must stay extended leftward past 280");
|
||||
assert!(h.query_all_by_role(Role::ScrollBar).count() == 0, "settled table keeps zero inner scrollbars");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
/// A refused Word XML export (the typed name's `.xml` twin already exists) is said on the Export
|
||||
/// page itself: Backstage hides the status bar, so the person would otherwise see nothing.
|
||||
#[test]
|
||||
|
||||
@@ -567,124 +567,187 @@ pub(crate) fn your_languages_section(app: &mut WordApp, ui: &mut Ui) {
|
||||
let view = your_view(app, &index, &installed);
|
||||
let mut install = None;
|
||||
let mut removal = None;
|
||||
const COL1_W: f32 = 250.0;
|
||||
const COL2_MIN_W: f32 = 190.0;
|
||||
const COL_GAP: f32 = 16.0;
|
||||
const ROW_GAP: f32 = 8.0;
|
||||
let install_prompt = |row: &packs::LanguageRow| {
|
||||
let size = size_text(row.size);
|
||||
if row.proofing == Proofing::Install {
|
||||
crate::i18n::fmt(tl!("Install ({size})"), &[("size", &size)])
|
||||
} else {
|
||||
crate::i18n::fmt(tl!("Install spelling ({size})"), &[("size", &size)])
|
||||
}
|
||||
};
|
||||
let mut default = None;
|
||||
// As wide as the window leaves room for (the rows scroll sideways in a narrow one).
|
||||
let room = (ui.ctx().content_rect().right() - ui.cursor().min.x - 16.0).clamp(200.0, 760.0);
|
||||
let narrow = room < 660.0;
|
||||
egui::ScrollArea::both().id_salt("options_your_languages").max_width(room).max_height(300.0).auto_shrink([false, true]).show(ui, |ui| {
|
||||
crate::rtl::grid(
|
||||
ui,
|
||||
egui::Grid::new("options_your_languages_grid").num_columns(if narrow { 2 } else { 3 }).spacing(vec2(16.0, 8.0)).striped(true),
|
||||
|ui| {
|
||||
for (name, detail, row) in &view {
|
||||
let mut actions = |ui: &mut Ui| {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
if !row.default
|
||||
&& ui
|
||||
.small_button(tl!("Set as default"))
|
||||
.on_hover_text(tl!("New blank documents are written in this language"))
|
||||
.clicked()
|
||||
{
|
||||
default = Some(row_tag(row));
|
||||
}
|
||||
if row.installed
|
||||
&& let Some(locale) = &row.pack
|
||||
&& ui.add_enabled(!busy(), egui::Button::new(tl!("Remove")).small()).clicked()
|
||||
{
|
||||
removal = Some(locale.clone());
|
||||
}
|
||||
});
|
||||
};
|
||||
let here = caret.as_deref().is_some_and(|c| row.is_tag(c));
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(if narrow { 170.0 } else { 250.0 });
|
||||
let shown_name = shown(name, MAX_BAR_NAME);
|
||||
let line = if row.default { crate::i18n::fmt(tl!("{language} (default)"), &[("language", &shown_name)]) } else { shown_name };
|
||||
ui.label(if here { RichText::new(line).font(semibold(14.0)) } else { RichText::new(line) });
|
||||
ui.label(RichText::new(detail.as_str()).small().weak());
|
||||
// Measure columns upfront and lay rows out directly instead of using `egui::Grid` (whose
|
||||
// hidden pass-1 sizing leaves RTL right-anchoring too narrow on frame 1 inside `max_passes = 2`)
|
||||
// or a nested vertical ScrollArea (which clips its bar onto column 2 and overflows RTL right).
|
||||
let btn_gap = ui.spacing().item_spacing.x;
|
||||
let btn_w = |label: &str| {
|
||||
let galley = egui::WidgetText::from(label).into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Button);
|
||||
let pad = ui.spacing().button_padding.x * 2.0 + 2.0 * ui.visuals().widgets.inactive.bg_stroke.width;
|
||||
(galley.size().x + pad).ceil()
|
||||
};
|
||||
let mut col2_w = COL2_MIN_W;
|
||||
let mut col3_w = 0.0_f32;
|
||||
let set_w = btn_w(tl!("Set as default"));
|
||||
let remove_w = btn_w(tl!("Remove"));
|
||||
let cancel_w = btn_w(tl!("Cancel"));
|
||||
for (_, _, row) in &view {
|
||||
if row.pack.as_deref().and_then(|l| index.iter().find(|p| p.locale == l)).is_some()
|
||||
&& !row.installed
|
||||
&& matches!(row.proofing, Proofing::Install | Proofing::GrammarBuiltIn)
|
||||
{
|
||||
let w = if row.pack.as_deref().and_then(progress).is_some() { 90.0 + btn_gap + cancel_w } else { btn_w(&install_prompt(row)) };
|
||||
col2_w = col2_w.max(w);
|
||||
}
|
||||
let has_set = !row.default;
|
||||
let has_remove = row.installed && row.pack.is_some();
|
||||
let w3 = match (has_set, has_remove) {
|
||||
(true, true) => set_w + btn_gap + remove_w,
|
||||
(true, false) => set_w,
|
||||
(false, true) => remove_w,
|
||||
(false, false) => 0.0,
|
||||
};
|
||||
col3_w = col3_w.max(w3);
|
||||
}
|
||||
let total_w = COL1_W + COL_GAP + col2_w + if col3_w > 0.0 { COL_GAP + col3_w } else { 0.0 };
|
||||
let draw_table = |ui: &mut Ui| {
|
||||
ui.spacing_mut().item_spacing.y = ROW_GAP;
|
||||
let mut row_idx = 0usize;
|
||||
let mut add_row = |ui: &mut Ui, c1: &mut dyn FnMut(&mut Ui), c2: &mut dyn FnMut(&mut Ui), c3: &mut dyn FnMut(&mut Ui)| {
|
||||
let stripe = (row_idx % 2 == 1).then(|| ui.painter().add(egui::Shape::Noop));
|
||||
row_idx += 1;
|
||||
let row_resp = ui.horizontal_top(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = COL_GAP;
|
||||
ui.allocate_ui_with_layout(vec2(COL1_W, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
ui.set_width(COL1_W);
|
||||
c1(ui);
|
||||
});
|
||||
ui.allocate_ui_with_layout(vec2(col2_w, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| {
|
||||
ui.set_width(col2_w);
|
||||
ui.spacing_mut().item_spacing.x = btn_gap;
|
||||
c2(ui);
|
||||
});
|
||||
if col3_w > 0.0 {
|
||||
ui.allocate_ui_with_layout(vec2(col3_w, 0.0), egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
ui.set_min_width(col3_w);
|
||||
ui.spacing_mut().item_spacing.x = btn_gap;
|
||||
c3(ui);
|
||||
});
|
||||
let pack = row.pack.as_deref().and_then(|l| index.iter().find(|p| p.locale == l));
|
||||
let size = size_text(row.size);
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(190.0);
|
||||
match row.proofing {
|
||||
Proofing::BuiltIn => {
|
||||
ui.label(tl!("Built in"));
|
||||
}
|
||||
Proofing::Installed => {
|
||||
ui.label(RichText::new(tl!("Installed")).color(t.green));
|
||||
}
|
||||
Proofing::OwnDictionary => {
|
||||
ui.label(tl!("Your own dictionary"));
|
||||
}
|
||||
Proofing::SystemDictionary => {
|
||||
ui.label(tl!("System dictionary"));
|
||||
}
|
||||
Proofing::NotAvailable => {
|
||||
ui.label(RichText::new(tl!("Not available yet")).weak());
|
||||
}
|
||||
Proofing::GrammarBuiltIn => {
|
||||
ui.label(tl!("Grammar built in"));
|
||||
}
|
||||
Proofing::Install => {}
|
||||
}
|
||||
if let Some(pack) = pack
|
||||
&& !row.installed
|
||||
&& matches!(row.proofing, Proofing::Install | Proofing::GrammarBuiltIn)
|
||||
{
|
||||
match progress(&pack.locale) {
|
||||
Some((done, total)) => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::ProgressBar::new(done.min(total) as f32 / total as f32).desired_width(90.0).show_percentage());
|
||||
if ui.small_button(tl!("Cancel")).clicked() {
|
||||
packs::cancel(&pack.locale);
|
||||
}
|
||||
});
|
||||
}
|
||||
None => {
|
||||
let label = if row.proofing == Proofing::Install {
|
||||
crate::i18n::fmt(tl!("Install ({size})"), &[("size", &size)])
|
||||
} else {
|
||||
crate::i18n::fmt(tl!("Install spelling ({size})"), &[("size", &size)])
|
||||
};
|
||||
if ui.button(label).on_hover_text(licence_hover(pack)).clicked() {
|
||||
install = Some(pack.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if narrow {
|
||||
actions(ui);
|
||||
}
|
||||
});
|
||||
if !narrow {
|
||||
actions(ui);
|
||||
}
|
||||
ui.end_row();
|
||||
let error = row.pack.as_deref().and_then(|l| error_of(app, l));
|
||||
let unreadable = (matches!(row.proofing, Proofing::OwnDictionary | Proofing::SystemDictionary))
|
||||
.then(|| wordcraft_engine::proof::dictionary_load_error(wordcraft_engine::proof::ProofLang::from_tag(Some(&row_tag(row)))))
|
||||
.flatten();
|
||||
if error.is_some() || unreadable.is_some() {
|
||||
ui.label("");
|
||||
ui.vertical(|ui| {
|
||||
if let Some(e) = error {
|
||||
ui.add(egui::Label::new(RichText::new(e).small().color(t.red)).wrap());
|
||||
}
|
||||
if let Some(reason) = unreadable {
|
||||
let line = crate::i18n::fmt(tl!("Its dictionary couldn't be read: {reason}"), &[("reason", &shown_error(&reason))]);
|
||||
ui.add(egui::Label::new(RichText::new(line).small().color(t.red)).wrap());
|
||||
}
|
||||
});
|
||||
if !narrow {
|
||||
ui.label("");
|
||||
}
|
||||
ui.end_row();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
if let Some(slot) = stripe {
|
||||
ui.painter().set(
|
||||
slot,
|
||||
egui::epaint::RectShape::filled(row_resp.response.rect.expand2(vec2(0.0, 2.0)), 2.0, ui.style().visuals.faint_bg_color),
|
||||
);
|
||||
}
|
||||
};
|
||||
for (name, detail, row) in &view {
|
||||
let here = caret.as_deref().is_some_and(|c| row.is_tag(c));
|
||||
let pack = row.pack.as_deref().and_then(|l| index.iter().find(|p| p.locale == l));
|
||||
add_row(
|
||||
ui,
|
||||
&mut |ui| {
|
||||
let shown_name = shown(name, MAX_BAR_NAME);
|
||||
let line = if row.default { crate::i18n::fmt(tl!("{language} (default)"), &[("language", &shown_name)]) } else { shown_name };
|
||||
ui.label(if here { RichText::new(line).font(semibold(14.0)) } else { RichText::new(line) });
|
||||
ui.label(RichText::new(detail.as_str()).small().weak());
|
||||
},
|
||||
&mut |ui| {
|
||||
match row.proofing {
|
||||
Proofing::BuiltIn => {
|
||||
ui.label(tl!("Built in"));
|
||||
}
|
||||
Proofing::Installed => {
|
||||
ui.label(RichText::new(tl!("Installed")).color(t.green));
|
||||
}
|
||||
Proofing::OwnDictionary => {
|
||||
ui.label(tl!("Your own dictionary"));
|
||||
}
|
||||
Proofing::SystemDictionary => {
|
||||
ui.label(tl!("System dictionary"));
|
||||
}
|
||||
Proofing::NotAvailable => {
|
||||
ui.label(RichText::new(tl!("Not available yet")).weak());
|
||||
}
|
||||
Proofing::GrammarBuiltIn => {
|
||||
ui.label(tl!("Grammar built in"));
|
||||
}
|
||||
Proofing::Install => {}
|
||||
}
|
||||
if let Some(pack) = pack
|
||||
&& !row.installed
|
||||
&& matches!(row.proofing, Proofing::Install | Proofing::GrammarBuiltIn)
|
||||
{
|
||||
match progress(&pack.locale) {
|
||||
Some((done, total)) => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::ProgressBar::new(done.min(total) as f32 / total as f32).desired_width(90.0).show_percentage());
|
||||
if ui.small_button(tl!("Cancel")).clicked() {
|
||||
packs::cancel(&pack.locale);
|
||||
}
|
||||
});
|
||||
}
|
||||
None => {
|
||||
if ui.button(install_prompt(row)).on_hover_text(licence_hover(pack)).clicked() {
|
||||
install = Some(pack.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
&mut |ui| {
|
||||
if !row.default
|
||||
&& ui.small_button(tl!("Set as default")).on_hover_text(tl!("New blank documents are written in this language")).clicked()
|
||||
{
|
||||
default = Some(row_tag(row));
|
||||
}
|
||||
if row.installed
|
||||
&& let Some(locale) = &row.pack
|
||||
&& ui.add_enabled(!busy(), egui::Button::new(tl!("Remove")).small()).clicked()
|
||||
{
|
||||
removal = Some(locale.clone());
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let error = row.pack.as_deref().and_then(|l| error_of(app, l));
|
||||
let unreadable = (matches!(row.proofing, Proofing::OwnDictionary | Proofing::SystemDictionary))
|
||||
.then(|| wordcraft_engine::proof::dictionary_load_error(wordcraft_engine::proof::ProofLang::from_tag(Some(&row_tag(row)))))
|
||||
.flatten();
|
||||
if error.is_some() || unreadable.is_some() {
|
||||
add_row(
|
||||
ui,
|
||||
&mut |_| {},
|
||||
&mut |ui| {
|
||||
if let Some(e) = &error {
|
||||
ui.add(egui::Label::new(RichText::new(e).small().color(t.red)).wrap());
|
||||
}
|
||||
if let Some(reason) = &unreadable {
|
||||
let line = crate::i18n::fmt(tl!("Its dictionary couldn't be read: {reason}"), &[("reason", &shown_error(reason))]);
|
||||
ui.add(egui::Label::new(RichText::new(line).small().color(t.red)).wrap());
|
||||
}
|
||||
},
|
||||
&mut |_| {},
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
if crate::rtl::flows(ui) {
|
||||
let room = ui.available_rect_before_wrap();
|
||||
let left = room.max.x - total_w;
|
||||
if left.is_finite() {
|
||||
let max_rect = egui::Rect::from_min_max(egui::pos2(left, room.min.y), egui::pos2(room.max.x, room.max.y));
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(max_rect).layout(egui::Layout::top_down(egui::Align::Min)), draw_table);
|
||||
} else {
|
||||
ui.vertical(draw_table);
|
||||
}
|
||||
} else {
|
||||
ui.vertical(draw_table);
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
if let Some(e) = error_of(app, "") {
|
||||
ui.add(egui::Label::new(RichText::new(e).small().color(t.red)).wrap());
|
||||
@@ -1663,4 +1726,145 @@ mod tests {
|
||||
let grammar = json!({"kind": "grammar", "message": "Repeated word"});
|
||||
assert_eq!(crate::canvas::issue_heading(&grammar), tl!("Repeated word"));
|
||||
}
|
||||
|
||||
/// #5396: an active download row in Your languages uses the same button gap inside column 2
|
||||
/// as measured for `col2_w`, keeping column 3 aligned in LTR and avoiding rightward overflow
|
||||
/// in RTL even when a localized "Cancel" label pushes column 2 wider than `COL2_MIN_W`.
|
||||
#[test]
|
||||
fn your_languages_downloading_row_matches_measured_spacing() {
|
||||
let _g = BACKEND_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let _reset = ResetBackend;
|
||||
struct HoldBackend {
|
||||
base: FixedBackend,
|
||||
release: (std::sync::Mutex<bool>, std::sync::Condvar),
|
||||
}
|
||||
impl Backend for HoldBackend {
|
||||
fn index(&self) -> Result<Vec<packs::Pack>, String> {
|
||||
self.base.index()
|
||||
}
|
||||
fn fetch_index(&self, cancel: &packs::Cancel) -> Result<Vec<packs::Pack>, String> {
|
||||
self.base.fetch_index(cancel)
|
||||
}
|
||||
fn network_on(&self) -> bool {
|
||||
self.base.network_on()
|
||||
}
|
||||
fn enable_network(&self) -> Result<(), String> {
|
||||
self.base.enable_network()
|
||||
}
|
||||
fn install(&self, _pack: &packs::Pack, cancel: &packs::Cancel, progress: &mut dyn FnMut(u64, u64)) -> Result<(), String> {
|
||||
progress(50, 100);
|
||||
let (lock, cv) = &self.release;
|
||||
let mut done = lock.lock().unwrap();
|
||||
while !*done && !cancel.is_cancelled() {
|
||||
let (guard, _) = cv.wait_timeout(done, std::time::Duration::from_millis(20)).unwrap();
|
||||
done = guard;
|
||||
}
|
||||
Err("stopped test install".into())
|
||||
}
|
||||
fn remove(&self, locale: &str) -> Result<(), String> {
|
||||
self.base.remove(locale)
|
||||
}
|
||||
fn packs_dir(&self) -> Option<std::path::PathBuf> {
|
||||
self.base.packs_dir()
|
||||
}
|
||||
fn installed(&self) -> Vec<packs::Installed> {
|
||||
self.base.installed()
|
||||
}
|
||||
}
|
||||
struct DropHold<'a>(&'a HoldBackend);
|
||||
impl Drop for DropHold<'_> {
|
||||
fn drop(&mut self) {
|
||||
*self.0.release.0.lock().unwrap() = true;
|
||||
self.0.release.1.notify_all();
|
||||
packs::cancel("nl");
|
||||
for _ in 0..100 {
|
||||
if packs::installing().is_empty() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let hold = std::sync::Arc::new(HoldBackend {
|
||||
base: FixedBackend { network: std::sync::atomic::AtomicBool::new(true), ..FixedBackend::sample() },
|
||||
release: (std::sync::Mutex::new(false), std::sync::Condvar::new()),
|
||||
});
|
||||
let _drop_hold = DropHold(&hold);
|
||||
packs::set_backend(Some(hold.clone() as std::sync::Arc<dyn Backend>));
|
||||
packs::set_background(Some(std::sync::Arc::new(|| {})));
|
||||
|
||||
let doc = wordcraft_doc::Document::from_text("Hallo\nBonjour");
|
||||
let mut a = WordApp::new(wordcraft_engine::Session::new(doc), crate::Services::default());
|
||||
for (para, lang) in [(0, "nl-NL"), (1, "fr-FR")] {
|
||||
a.run("caret.set", json!({"pos": {"block": para, "off": 0}})).unwrap();
|
||||
a.run("select.paragraph", json!({})).unwrap();
|
||||
a.run("review.language", json!({"lang": lang})).unwrap();
|
||||
}
|
||||
packs::start_install("nl").unwrap();
|
||||
for _ in 0..200 {
|
||||
if packs::installing().iter().any(|p| p.locale == "nl" && p.done == 50) {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
assert!(packs::installing().iter().any(|p| p.locale == "nl"), "install must remain in flight");
|
||||
|
||||
let long_cancel_en = crate::i18n::fixture_lang("en", "\tCancel\tCancel language installation now\n");
|
||||
let long_cancel_ar = crate::i18n::fixture_lang("ar", "\tCancel\tCancel language installation now\n");
|
||||
|
||||
for lang in [long_cancel_en, long_cancel_ar] {
|
||||
crate::i18n::set_current(lang);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
crate::theme::apply(&ctx, crate::theme::Appearance::Light);
|
||||
crate::rtl::sync(&ctx);
|
||||
let rtl = lang.rtl();
|
||||
let mut set_rects = Vec::new();
|
||||
let container = egui::Rect::from_min_max(egui::pos2(200.0, 20.0), egui::pos2(800.0, 480.0));
|
||||
let align = if rtl { egui::Align::Max } else { egui::Align::Min };
|
||||
for _ in 0..3 {
|
||||
set_rects.clear();
|
||||
let mut out = ctx.run_ui(
|
||||
egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1000.0, 500.0))),
|
||||
focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
|ui| {
|
||||
crate::rtl::root(ui, |ui| {
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(container).layout(egui::Layout::top_down(align)), |ui| {
|
||||
super::your_languages_section(&mut a, ui);
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
out.textures_delta.clear();
|
||||
let set_default = crate::i18n::t("Set as default");
|
||||
for shape in &out.shapes {
|
||||
fn visit(shape: &egui::Shape, needle: &str, out: &mut Vec<(String, egui::Rect)>) {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == needle => {
|
||||
out.push((t.galley.text().to_string(), egui::Rect::from_min_size(t.pos, t.galley.size())));
|
||||
}
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| visit(s, needle, out)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
visit(&shape.shape, set_default, &mut set_rects);
|
||||
}
|
||||
}
|
||||
assert_eq!(set_rects.len(), 2, "both Dutch and French rows must render Set as default: {set_rects:?}");
|
||||
let dx = (set_rects[0].1.left() - set_rects[1].1.left()).abs();
|
||||
assert!(dx <= 0.5, "rtl={rtl}: Set as default buttons misaligned across rows ({set_rects:?})");
|
||||
if rtl {
|
||||
assert!(
|
||||
set_rects.iter().all(|(_, r)| r.right() <= container.right() + 0.5),
|
||||
"rtl={rtl}: column 3 overflowed container right {}: {set_rects:?}",
|
||||
container.right()
|
||||
);
|
||||
}
|
||||
}
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
}
|
||||
|
||||
+216
-179
@@ -215,147 +215,151 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
app.print_memo.said = result(&message).then_some(generation);
|
||||
}
|
||||
|
||||
let settings = |app: &mut WordApp, ui: &mut Ui| {
|
||||
let fit_settings = ui.available_width() >= SETTINGS_WIDTH;
|
||||
let settings_body = |app: &mut WordApp, ui: &mut Ui| {
|
||||
ui.set_width(SETTINGS_WIDTH);
|
||||
ui.spacing_mut().item_spacing.y = 8.0;
|
||||
let native = app.services.print_native.is_some();
|
||||
let hook = native || app.services.print.is_some();
|
||||
// #2958: as in Word, the page's action leads the settings, in the accent the app
|
||||
// gives a dialog's primary button: the first thing seen, and plainly a button
|
||||
// that prints now rather than one more setting in the list below.
|
||||
let ready = !native || app.printing.ready();
|
||||
// Return prints too, as in Word, whose ⌘P opens on Print as the default button.
|
||||
if hook
|
||||
&& (ui.add_enabled(ready, crate::widgets::primary_button(ui, tl!("Print")).min_size(vec2(320.0, 34.0))).clicked()
|
||||
|| (ready && app.dialog.is_none() && !app.file_dialog_open() && return_prints(ui.ctx())))
|
||||
{
|
||||
ui.set_width(SETTINGS_WIDTH);
|
||||
let params = app.ui.print.params();
|
||||
let _ = app.run("ui.print", params);
|
||||
}
|
||||
if native {
|
||||
if let Some(discover) = &app.services.printers {
|
||||
crate::printing::show(&mut app.printing, ui, discover, hide_message, |label| crate::i18n::t(label).to_owned());
|
||||
}
|
||||
// A job can wait long on a sleeping printer's driver; Cancel frees the page.
|
||||
if app.printing.busy() && app.services.cancel_print.is_some() && ui.button(tl!("Cancel printing")).clicked() {
|
||||
let _ = app.run("ui.printCancel", serde_json::json!({}));
|
||||
}
|
||||
app.ui.print.copies = app.printing.settings.copies;
|
||||
} else if hook {
|
||||
ui.label(tl!("Send the document straight to the system print dialog, or save a copy in another format below."));
|
||||
} else {
|
||||
ui.label(tl!("Save a copy in another format. Printing goes through a PDF you can print from any viewer."));
|
||||
}
|
||||
if ui.add(egui::Button::new(egui::RichText::new(tl!("Save these pages as PDF…")).font(medium(13.5))).min_size(vec2(320.0, 34.0))).clicked()
|
||||
{
|
||||
app.print_pdf_dialog();
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
|
||||
if native {
|
||||
if app.ui.print.copies > 1 {
|
||||
ui.add_enabled_ui(!app.printing.busy(), |ui| ui.checkbox(&mut app.ui.print.collate, tl!("Collate copies")));
|
||||
}
|
||||
} else {
|
||||
let copies_label = ui.label(egui::RichText::new(tl!("Copies")).font(medium(13.0)));
|
||||
ui.horizontal(|ui| {
|
||||
let mut n = app.ui.print.copies;
|
||||
ui.add(egui::DragValue::new(&mut n).range(1..=wordcraft_engine::print::MAX_COPIES).speed(0.2)).labelled_by(copies_label.id);
|
||||
app.ui.print.copies = n.clamp(1, wordcraft_engine::print::MAX_COPIES);
|
||||
if app.ui.print.copies > 1 {
|
||||
ui.checkbox(&mut app.ui.print.collate, tl!("Collate copies"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let pages_label = ui.label(egui::RichText::new(tl!("Pages")).font(medium(13.0)));
|
||||
if choice(ui, "print_range", &mut app.ui.print.range, &RANGES, &pages_label) {
|
||||
// Show the first page that will print.
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
if app.ui.print.range == "custom"
|
||||
&& ui
|
||||
.add(
|
||||
egui::TextEdit::singleline(&mut app.ui.print.pages)
|
||||
.hint_text(tl!("Pages like 1-3, 5"))
|
||||
.desired_width(260.0)
|
||||
.char_limit(wordcraft_engine::print::MAX_SPEC_CHARS),
|
||||
)
|
||||
.labelled_by(pages_label.id)
|
||||
.changed()
|
||||
{
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
if choice_named(ui, "print_parity", &mut app.ui.print.parity, &PARITIES, tl!("Pages in the range")) {
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
let orientation_label = ui.label(egui::RichText::new(tl!("Orientation")).font(medium(13.0)));
|
||||
if app.ui.print.pages_per_sheet == "2" || app.ui.print.pages_per_sheet.starts_with("booklet") {
|
||||
ui.label(tl!("Landscape"));
|
||||
} else {
|
||||
choice(ui, "print_orientation", &mut app.ui.print.orientation, &ORIENTATIONS, &orientation_label);
|
||||
}
|
||||
let pages_per_sheet_label = ui.label(egui::RichText::new(tl!("Pages per sheet")).font(medium(13.0)));
|
||||
choice(
|
||||
ui,
|
||||
"print_pages_per_sheet",
|
||||
&mut app.ui.print.pages_per_sheet,
|
||||
&[
|
||||
("1", "1"),
|
||||
("2", "2"),
|
||||
("4", "4"),
|
||||
("6", "6"),
|
||||
("9", "9"),
|
||||
("16", "16"),
|
||||
("booklet", "Booklet (left binding)"),
|
||||
("bookletReverse", "Booklet (right binding)"),
|
||||
],
|
||||
&pages_per_sheet_label,
|
||||
);
|
||||
if app.ui.print.pages_per_sheet.starts_with("booklet") {
|
||||
ui.label(tl!("Booklets: duplex on the short edge. Blank pages are added at the end."));
|
||||
}
|
||||
// Word: Pages per sheet › Scale to paper size. Only the printout changes.
|
||||
let paper_label = ui.label(egui::RichText::new(tl!("Scale to paper size")).font(medium(13.0)));
|
||||
let papers: Vec<(&str, &str)> =
|
||||
std::iter::once((NO_SCALING, "No Scaling")).chain(wordcraft_geom::PAPER_SIZES.iter().map(|(n, _, _)| (*n, *n))).collect();
|
||||
choice(ui, "print_paper", &mut app.ui.print.paper, &papers, &paper_label);
|
||||
|
||||
match wordcraft_engine::print::plan(&app.ui.print.params(), total, current) {
|
||||
Ok(plan) => {
|
||||
let msg = crate::i18n::fmt(
|
||||
tl!("{count} of {total} pages will print"),
|
||||
&[("count", &plan.chosen.to_string()), ("total", &total.to_string())],
|
||||
);
|
||||
ui.label(egui::RichText::new(msg).color(t.text_dim));
|
||||
}
|
||||
Err(e) => {
|
||||
ui.label(egui::RichText::new(e.to_string()).color(t.red));
|
||||
}
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
ui.add_space(4.0);
|
||||
if hook {
|
||||
ui.label(tl!("Or save a copy in another format:"));
|
||||
}
|
||||
export_formats(app, ui);
|
||||
};
|
||||
let settings = |app: &mut WordApp, ui: &mut Ui| {
|
||||
if fit_settings {
|
||||
// The settings scroll on their own: the preview beside them keeps the whole height (#1156).
|
||||
// egui draws the bar at the right edge, over the right-aligned controls of a mirrored
|
||||
// column: a solid bar there takes its own gutter instead of floating over them.
|
||||
if crate::rtl::flows(ui) {
|
||||
ui.spacing_mut().scroll = egui::style::ScrollStyle::solid();
|
||||
}
|
||||
egui::ScrollArea::vertical().id_salt("print_settings").show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = 8.0;
|
||||
let native = app.services.print_native.is_some();
|
||||
let hook = native || app.services.print.is_some();
|
||||
// #2958: as in Word, the page's action leads the settings, in the accent the app
|
||||
// gives a dialog's primary button: the first thing seen, and plainly a button
|
||||
// that prints now rather than one more setting in the list below.
|
||||
let ready = !native || app.printing.ready();
|
||||
// Return prints too, as in Word, whose ⌘P opens on Print as the default button.
|
||||
if hook
|
||||
&& (ui.add_enabled(ready, crate::widgets::primary_button(ui, tl!("Print")).min_size(vec2(320.0, 34.0))).clicked()
|
||||
|| (ready && app.dialog.is_none() && !app.file_dialog_open() && return_prints(ui.ctx())))
|
||||
{
|
||||
let params = app.ui.print.params();
|
||||
let _ = app.run("ui.print", params);
|
||||
}
|
||||
if native {
|
||||
if let Some(discover) = &app.services.printers {
|
||||
crate::printing::show(&mut app.printing, ui, discover, hide_message, |label| crate::i18n::t(label).to_owned());
|
||||
}
|
||||
// A job can wait long on a sleeping printer's driver; Cancel frees the page.
|
||||
if app.printing.busy() && app.services.cancel_print.is_some() && ui.button(tl!("Cancel printing")).clicked() {
|
||||
let _ = app.run("ui.printCancel", serde_json::json!({}));
|
||||
}
|
||||
app.ui.print.copies = app.printing.settings.copies;
|
||||
} else if hook {
|
||||
ui.label(tl!("Send the document straight to the system print dialog, or save a copy in another format below."));
|
||||
} else {
|
||||
ui.label(tl!("Save a copy in another format. Printing goes through a PDF you can print from any viewer."));
|
||||
}
|
||||
if ui
|
||||
.add(egui::Button::new(egui::RichText::new(tl!("Save these pages as PDF…")).font(medium(13.5))).min_size(vec2(320.0, 34.0)))
|
||||
.clicked()
|
||||
{
|
||||
app.print_pdf_dialog();
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
|
||||
if native {
|
||||
if app.ui.print.copies > 1 {
|
||||
ui.add_enabled_ui(!app.printing.busy(), |ui| ui.checkbox(&mut app.ui.print.collate, tl!("Collate copies")));
|
||||
}
|
||||
} else {
|
||||
let copies_label = ui.label(egui::RichText::new(tl!("Copies")).font(medium(13.0)));
|
||||
ui.horizontal(|ui| {
|
||||
let mut n = app.ui.print.copies;
|
||||
ui.add(egui::DragValue::new(&mut n).range(1..=wordcraft_engine::print::MAX_COPIES).speed(0.2)).labelled_by(copies_label.id);
|
||||
app.ui.print.copies = n.clamp(1, wordcraft_engine::print::MAX_COPIES);
|
||||
if app.ui.print.copies > 1 {
|
||||
ui.checkbox(&mut app.ui.print.collate, tl!("Collate copies"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let pages_label = ui.label(egui::RichText::new(tl!("Pages")).font(medium(13.0)));
|
||||
if choice(ui, "print_range", &mut app.ui.print.range, &RANGES, &pages_label) {
|
||||
// Show the first page that will print.
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
if app.ui.print.range == "custom"
|
||||
&& ui
|
||||
.add(
|
||||
egui::TextEdit::singleline(&mut app.ui.print.pages)
|
||||
.hint_text(tl!("Pages like 1-3, 5"))
|
||||
.desired_width(260.0)
|
||||
.char_limit(wordcraft_engine::print::MAX_SPEC_CHARS),
|
||||
)
|
||||
.labelled_by(pages_label.id)
|
||||
.changed()
|
||||
{
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
if choice_named(ui, "print_parity", &mut app.ui.print.parity, &PARITIES, tl!("Pages in the range")) {
|
||||
app.ui.print.preview = 0;
|
||||
}
|
||||
let orientation_label = ui.label(egui::RichText::new(tl!("Orientation")).font(medium(13.0)));
|
||||
if app.ui.print.pages_per_sheet == "2" || app.ui.print.pages_per_sheet.starts_with("booklet") {
|
||||
ui.label(tl!("Landscape"));
|
||||
} else {
|
||||
choice(ui, "print_orientation", &mut app.ui.print.orientation, &ORIENTATIONS, &orientation_label);
|
||||
}
|
||||
let pages_per_sheet_label = ui.label(egui::RichText::new(tl!("Pages per sheet")).font(medium(13.0)));
|
||||
choice(
|
||||
ui,
|
||||
"print_pages_per_sheet",
|
||||
&mut app.ui.print.pages_per_sheet,
|
||||
&[
|
||||
("1", "1"),
|
||||
("2", "2"),
|
||||
("4", "4"),
|
||||
("6", "6"),
|
||||
("9", "9"),
|
||||
("16", "16"),
|
||||
("booklet", "Booklet (left binding)"),
|
||||
("bookletReverse", "Booklet (right binding)"),
|
||||
],
|
||||
&pages_per_sheet_label,
|
||||
);
|
||||
if app.ui.print.pages_per_sheet.starts_with("booklet") {
|
||||
ui.label(tl!("Booklets: duplex on the short edge. Blank pages are added at the end."));
|
||||
}
|
||||
// Word: Pages per sheet › Scale to paper size. Only the printout changes.
|
||||
let paper_label = ui.label(egui::RichText::new(tl!("Scale to paper size")).font(medium(13.0)));
|
||||
let papers: Vec<(&str, &str)> =
|
||||
std::iter::once((NO_SCALING, "No Scaling")).chain(wordcraft_geom::PAPER_SIZES.iter().map(|(n, _, _)| (*n, *n))).collect();
|
||||
choice(ui, "print_paper", &mut app.ui.print.paper, &papers, &paper_label);
|
||||
|
||||
match wordcraft_engine::print::plan(&app.ui.print.params(), total, current) {
|
||||
Ok(plan) => {
|
||||
let msg = crate::i18n::fmt(
|
||||
tl!("{count} of {total} pages will print"),
|
||||
&[("count", &plan.chosen.to_string()), ("total", &total.to_string())],
|
||||
);
|
||||
ui.label(egui::RichText::new(msg).color(t.text_dim));
|
||||
}
|
||||
Err(e) => {
|
||||
ui.label(egui::RichText::new(e.to_string()).color(t.red));
|
||||
}
|
||||
}
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
ui.add_space(4.0);
|
||||
if hook {
|
||||
ui.label(tl!("Or save a copy in another format:"));
|
||||
}
|
||||
export_formats(app, ui);
|
||||
});
|
||||
egui::ScrollArea::vertical().id_salt("print_settings").show(ui, |ui| settings_body(app, ui));
|
||||
} else {
|
||||
settings_body(app, ui);
|
||||
}
|
||||
};
|
||||
// A right-to-left interface splits the room by hand, settings on the side reading starts from:
|
||||
// a `horizontal_top` row there lays the preview over the settings.
|
||||
if crate::rtl::flows(ui) {
|
||||
// a `horizontal_top` row there lays the preview over the settings. When narrower than
|
||||
// `SETTINGS_WIDTH`, `backstage` wraps the page in `scroll_both`, so a plain column lets
|
||||
// `scroll_both` open at the reading start and scroll sideways cleanly in both directions.
|
||||
if fit_settings && crate::rtl::flows(ui) {
|
||||
let room = ui.available_rect_before_wrap();
|
||||
let split = (room.max.x - SETTINGS_WIDTH).max(room.min.x);
|
||||
let settings_rect = Rect::from_min_max(pos2(split, room.min.y), room.max);
|
||||
@@ -371,16 +375,21 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
crate::rtl::horizontal_top(ui, |ui| {
|
||||
crate::rtl::vertical(ui, |ui| settings(app, ui));
|
||||
ui.add_space(SETTINGS_GAP);
|
||||
crate::rtl::vertical(ui, |ui| preview(app, ui, &lay));
|
||||
if ui.available_width() - SETTINGS_GAP >= MIN_PREVIEW_WIDTH {
|
||||
ui.add_space(SETTINGS_GAP);
|
||||
crate::rtl::vertical(ui, |ui| preview(app, ui, &lay));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The settings column's width, and the space between it and the preview.
|
||||
const SETTINGS_WIDTH: f32 = 380.0;
|
||||
pub(crate) const SETTINGS_WIDTH: f32 = 380.0;
|
||||
const SETTINGS_GAP: f32 = 24.0;
|
||||
/// The narrowest preview pane worth drawing when the layout is mirrored.
|
||||
/// The narrowest preview pane worth drawing.
|
||||
const MIN_PREVIEW_WIDTH: f32 = 200.0;
|
||||
/// The narrowest pane that keeps its bar on one row: the page indicator, with three-digit page
|
||||
/// numbers, beside the zoom buttons without their slider. A narrower one takes two rows.
|
||||
const ONE_ROW_BAR_WIDTH: f32 = 320.0;
|
||||
|
||||
/// Room around the page inside the preview pane.
|
||||
const PREVIEW_MARGIN: f32 = 10.0;
|
||||
@@ -410,13 +419,18 @@ fn preview(app: &mut WordApp, ui: &mut Ui, lay: &DocLayout) {
|
||||
app.ui.print.preview = page;
|
||||
let Some(sheet) = sheets.get(page) else { return };
|
||||
let (pw, ph) = (sheet.width, sheet.height);
|
||||
let pane = vec2(ui.available_width().max(120.0), (ui.available_height() - PREVIEW_BAR).max(120.0));
|
||||
// Navigate the imposed sheet views rather than the logical document pages.
|
||||
let label = crate::i18n::fmt(tl!("Sheet {page} of {pages}"), &[("page", &(page + 1).to_string()), ("pages", &total.to_string())]);
|
||||
let label_w = ui.painter().layout_no_wrap(label.clone(), regular(13.0), t.text).size().x;
|
||||
let pct_w = ui.painter().layout_no_wrap("500%".into(), regular(13.0), t.text).size().x;
|
||||
let min_one_row = (5.0 * 26.0 + 6.0 * ui.spacing().item_spacing.x + label_w + pct_w + 8.0).max(ONE_ROW_BAR_WIDTH);
|
||||
let one_row = ui.available_width() >= min_one_row;
|
||||
let bar_height = if one_row { PREVIEW_BAR } else { 2.0 * PREVIEW_BAR };
|
||||
let pane = vec2(ui.available_width().max(120.0), (ui.available_height() - bar_height).max(120.0));
|
||||
// Screen points per page point.
|
||||
let fit = ((pane.x - 2.0 * PREVIEW_MARGIN) / pw).min((pane.y - 2.0 * PREVIEW_MARGIN) / ph).max(0.01);
|
||||
let scale = app.ui.print.zoom.map_or(fit, |z| z * crate::canvas::PX_PER_PT);
|
||||
let size = vec2(pw * scale, ph * scale);
|
||||
// Navigate the imposed sheet views rather than the logical document pages.
|
||||
let label = crate::i18n::fmt(tl!("Sheet {page} of {pages}"), &[("page", &(page + 1).to_string()), ("pages", &total.to_string())]);
|
||||
egui::ScrollArea::both().id_salt("print_preview").auto_shrink(false).max_width(pane.x).max_height(pane.y).show(ui, |ui| {
|
||||
let room = vec2((size.x + 2.0 * PREVIEW_MARGIN).max(ui.available_width()), (size.y + 2.0 * PREVIEW_MARGIN).max(ui.available_height()));
|
||||
let (area, _) = ui.allocate_exact_size(room, Sense::hover());
|
||||
@@ -436,55 +450,78 @@ fn preview(app: &mut WordApp, ui: &mut Ui, lay: &DocLayout) {
|
||||
}
|
||||
});
|
||||
let rtl = crate::rtl::flows(ui);
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_height(PREVIEW_BAR);
|
||||
let nav = |ui: &mut Ui, icon: &str, tip: &str, enabled: bool| {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(26.0, 26.0), Sense::click());
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, tip));
|
||||
let col = if enabled { t.icon } else { t.text_disabled };
|
||||
if enabled && resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
}
|
||||
icons::paint(ui.painter(), r.shrink(4.0), icon, col, col);
|
||||
enabled && resp.on_hover_text(tip).clicked()
|
||||
};
|
||||
let nav = |ui: &mut Ui, icon: &str, tip: &str, enabled: bool| {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(26.0, 26.0), Sense::click());
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, tip));
|
||||
let col = if enabled { t.icon } else { t.text_disabled };
|
||||
if enabled && resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
}
|
||||
icons::paint(ui.painter(), r.shrink(4.0), icon, col, col);
|
||||
enabled && resp.on_hover_text(tip).clicked()
|
||||
};
|
||||
let mut page_cluster = |ui: &mut Ui| {
|
||||
if nav(ui, if rtl { "chevronRight" } else { "chevronLeft" }, tl!("Previous sheet"), page > 0) {
|
||||
app.ui.print.preview = page - 1;
|
||||
}
|
||||
ui.label(egui::RichText::new(&label).font(regular(13.0)));
|
||||
let max_label_w = (ui.available_width() - 26.0 - ui.spacing().item_spacing.x - 1.0).max(0.0);
|
||||
if label_w <= max_label_w {
|
||||
ui.label(egui::RichText::new(&label).font(regular(13.0)));
|
||||
} else {
|
||||
ui.add_sized(vec2(max_label_w, 26.0), egui::Label::new(egui::RichText::new(&label).font(regular(13.0))).truncate());
|
||||
}
|
||||
if nav(ui, if rtl { "chevronLeft" } else { "chevronRight" }, tl!("Next sheet"), page + 1 < total) {
|
||||
app.ui.print.preview = page + 1;
|
||||
}
|
||||
ui.with_layout(crate::rtl::far_side(ui, egui::Align::Center), |ui| {
|
||||
let z = scale / crate::canvas::PX_PER_PT;
|
||||
if nav(ui, "onePage", tl!("One Page"), true) {
|
||||
app.ui.print.zoom = None;
|
||||
}
|
||||
ui.label(egui::RichText::new(format!("{}%", (z * 100.0).round())).font(regular(13.0)));
|
||||
// The slider grows to the right in every language, as in the status bar: minus at its
|
||||
// left end, plus at its right. This cluster fills from the far end inwards.
|
||||
let (inner, outer) = (("minus", "Zoom Out", false), ("plus", "Zoom In", true));
|
||||
let (near, far) = if rtl { (inner, outer) } else { (outer, inner) };
|
||||
let enabled = |up: bool| if up { z < 5.0 } else { z > 0.1 };
|
||||
if nav(ui, near.0, tl!(near.1), enabled(near.2)) {
|
||||
app.ui.print.zoom = Some(zoom_step(z, near.2));
|
||||
}
|
||||
// A narrow window shortens the slider, then drops it, before it covers the page indicator.
|
||||
let room = ui.available_width() - 26.0 - 2.0 * ui.spacing().item_spacing.x - 12.0;
|
||||
if room >= 40.0 {
|
||||
let mut v = z;
|
||||
ui.spacing_mut().slider_width = room.min(110.0);
|
||||
let response = ui.add(egui::Slider::new(&mut v, 0.1..=5.0).logarithmic(true).show_value(false)).on_hover_text(tl!("Zoom"));
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, ui.is_enabled(), tl!("Zoom")));
|
||||
if response.changed() {
|
||||
app.ui.print.zoom = Some(v.clamp(0.1, 5.0));
|
||||
}
|
||||
}
|
||||
if nav(ui, far.0, tl!(far.1), enabled(far.2)) {
|
||||
app.ui.print.zoom = Some(zoom_step(z, far.2));
|
||||
};
|
||||
let mut zoom_cluster = |ui: &mut Ui| {
|
||||
let z = scale / crate::canvas::PX_PER_PT;
|
||||
if nav(ui, "onePage", tl!("One Page"), true) {
|
||||
app.ui.print.zoom = None;
|
||||
}
|
||||
ui.label(egui::RichText::new(format!("{}%", (z * 100.0).round())).font(regular(13.0)));
|
||||
// The slider grows to the right in every language, as in the status bar: minus at its
|
||||
// left end, plus at its right. This cluster fills from the far end inwards.
|
||||
let (inner, outer) = (("minus", "Zoom Out", false), ("plus", "Zoom In", true));
|
||||
let (near, far) = if rtl { (inner, outer) } else { (outer, inner) };
|
||||
let enabled = |up: bool| if up { z < 5.0 } else { z > 0.1 };
|
||||
if nav(ui, near.0, tl!(near.1), enabled(near.2)) {
|
||||
app.ui.print.zoom = Some(zoom_step(z, near.2));
|
||||
}
|
||||
// A narrow window shortens the slider, then drops it, before it covers the page indicator.
|
||||
let room = ui.available_width() - 26.0 - 2.0 * ui.spacing().item_spacing.x - 12.0;
|
||||
if room >= 40.0 {
|
||||
let mut v = z;
|
||||
ui.spacing_mut().slider_width = room.min(110.0);
|
||||
let response = ui.add(egui::Slider::new(&mut v, 0.1..=5.0).logarithmic(true).show_value(false)).on_hover_text(tl!("Zoom"));
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, ui.is_enabled(), tl!("Zoom")));
|
||||
if response.changed() {
|
||||
app.ui.print.zoom = Some(v.clamp(0.1, 5.0));
|
||||
}
|
||||
}
|
||||
if nav(ui, far.0, tl!(far.1), enabled(far.2)) {
|
||||
app.ui.print.zoom = Some(zoom_step(z, far.2));
|
||||
}
|
||||
};
|
||||
if one_row {
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_height(PREVIEW_BAR);
|
||||
page_cluster(ui);
|
||||
ui.with_layout(crate::rtl::far_side(ui, egui::Align::Center), &mut zoom_cluster);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
crate::rtl::vertical(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing.y = 4.0;
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_height(28.0);
|
||||
page_cluster(ui);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.set_height(28.0);
|
||||
ui.with_layout(crate::rtl::far_side(ui, egui::Align::Center), &mut zoom_cluster);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// The export "format" of a Word 2003 XML Document: an `.xml` file saved with `format: "wordml2003"`.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//! to right inside, because everything here follows the enclosing layout rather than the language.
|
||||
//! The document itself is never mirrored: its direction belongs to the document.
|
||||
|
||||
use egui::{Align, Align2, InnerResponse, Layout, Rect, Ui, UiBuilder, pos2};
|
||||
use egui::{Align, Align2, InnerResponse, Layout, Rect, Ui, UiBuilder, pos2, vec2};
|
||||
|
||||
use craft_ui::direction::{self, Direction};
|
||||
|
||||
@@ -161,9 +161,11 @@ pub fn island<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R {
|
||||
if !flows(ui) {
|
||||
return add(ui);
|
||||
}
|
||||
// The island gets all the room there is, so its content takes its natural width; it starts
|
||||
// The island gets all the room there is, so its content takes its natural width. It starts
|
||||
// where content of last frame's width would end at the leading edge. A change of width shows
|
||||
// one frame late, so that frame asks for another.
|
||||
// one pass late, so that pass is discarded when passes remain (or repainted on the next frame).
|
||||
// If an inner widget such as `Grid` discarded this pass for its own invisible sizing pass, wait
|
||||
// until a visible pass before recording the width.
|
||||
let key = ui.next_auto_id().with("rtl_island_width");
|
||||
let known = ui.data(|d| d.get_temp::<f32>(key));
|
||||
let room = ui.available_rect_before_wrap();
|
||||
@@ -174,15 +176,56 @@ pub fn island<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R {
|
||||
return add(ui);
|
||||
}
|
||||
let max_rect = Rect::from_min_max(pos2(left, room.min.y), pos2(left + available.max(width), room.max.y));
|
||||
let discard_before = ui.ctx().will_discard();
|
||||
let shown = ui.scope_builder(UiBuilder::new().max_rect(max_rect).layout(Layout::top_down(Align::Min)), add);
|
||||
let child_discarded = !discard_before && ui.ctx().will_discard();
|
||||
let now = shown.response.rect.width();
|
||||
if now.is_finite() && known.is_none_or(|w| (w - now).abs() > 0.5) {
|
||||
if !child_discarded && now.is_finite() && known.is_none_or(|w| (w - now).abs() > 0.5) {
|
||||
ui.data_mut(|d| d.insert_temp(key, now));
|
||||
ui.ctx().request_repaint();
|
||||
ui.ctx().request_discard("rtl island width changed");
|
||||
if !ui.ctx().will_discard() {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
}
|
||||
shown.inner
|
||||
}
|
||||
|
||||
/// A scroll area in both directions that fills `ui`, for content wider than it. Right-to-left
|
||||
/// content runs from the right, so what doesn't fit lands left of the area, where no scroll offset
|
||||
/// reaches: egui's offsets only move content further left. So the content is set as far to the
|
||||
/// right as it overflowed last frame, and the area keeps its distance from the right end, which
|
||||
/// shows the content's start first. A change of overflow shows one frame late, so that frame is
|
||||
/// done again. Left-to-right content doesn't overflow on its left, so this is a plain scroll area.
|
||||
/// `page` names the content, which keeps its own place when another page takes the area.
|
||||
pub fn scroll_both(ui: &mut Ui, page: &str, add: impl FnOnce(&mut Ui)) {
|
||||
let key = ui.scope_id().with(("rtl_scroll_overflow", page));
|
||||
let (known, offset): (f32, Option<f32>) = ui.data(|d| d.get_temp(key)).unwrap_or_default();
|
||||
let mut area = egui::ScrollArea::both().id_salt(page).auto_shrink([false, false]);
|
||||
if let Some(offset) = offset {
|
||||
area = area.horizontal_scroll_offset(offset);
|
||||
}
|
||||
let shown = area.show(ui, |ui| {
|
||||
let room = ui.max_rect().translate(vec2(known, 0.0));
|
||||
let page = ui.scope_builder(UiBuilder::new().max_rect(room), add);
|
||||
room.left() - page.response.rect.left()
|
||||
});
|
||||
let now = shown.inner.max(0.0);
|
||||
if !now.is_finite() {
|
||||
return;
|
||||
}
|
||||
if (now - known).abs() > 0.5 {
|
||||
let end = (shown.content_size.x - shown.inner_rect.width()).max(0.0);
|
||||
let offset = (shown.state.clamped_offset().x + now - known).clamp(0.0, end);
|
||||
ui.data_mut(|d| d.insert_temp(key, (now, Some(offset))));
|
||||
ui.ctx().request_discard("right-to-left overflow changed");
|
||||
if !ui.ctx().will_discard() {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
} else if offset.is_some() {
|
||||
ui.data_mut(|d| d.insert_temp(key, (known, None::<f32>)));
|
||||
}
|
||||
}
|
||||
|
||||
/// `grid.show(ui, add)`. egui's `Grid` cannot be laid out from the right (it places cells from a
|
||||
/// left edge that a right-to-left parent does not have, and says so with a debug assertion), so
|
||||
/// inside a right-to-left area it is drawn in an [`island`]. Its columns keep their order.
|
||||
@@ -389,4 +432,41 @@ mod tests {
|
||||
set_current(Lang::EN);
|
||||
assert!(label > field, "right to left: label {label}, field {field}");
|
||||
}
|
||||
|
||||
/// #5396: when an RTL child (`island` / `grid`) already overflows inside `scroll_both` and
|
||||
/// widens so it spends pass 0's single discard before `scroll_both` sees the larger overflow
|
||||
/// on pass 1 (`max_passes = 2`), `scroll_both` asks for a repaint rather than leaving the
|
||||
/// widened left edge clipped until an unrelated event.
|
||||
#[test]
|
||||
fn scroll_both_requests_repaint_when_child_discard_exhausts_passes() {
|
||||
set_current(fixture_lang("ar", "\tHome\tHome\n"));
|
||||
let ctx = egui::Context::default();
|
||||
sync(&ctx);
|
||||
let screen = |frame_width: f32, wide: bool| {
|
||||
let mut raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(frame_width, 200.0))), ..Default::default() };
|
||||
raw.focused = true;
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
ui.scope_builder(UiBuilder::new().max_rect(Rect::from_min_size(egui::Pos2::ZERO, vec2(frame_width, 200.0))), |ui| {
|
||||
scroll_both(ui, "rtl_repaint_test", |ui| {
|
||||
root(ui, |ui| {
|
||||
grid(ui, egui::Grid::new("widening_rtl_grid"), |ui| {
|
||||
let label = if wide { "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" } else { "MMMMMMMMMMMMMMMM" };
|
||||
ui.label(label);
|
||||
ui.end_row();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
out
|
||||
};
|
||||
for _ in 0..4 {
|
||||
screen(100.0, false);
|
||||
}
|
||||
let out = screen(100.0, true);
|
||||
set_current(Lang::EN);
|
||||
let delay = out.viewport_output.values().next().expect("root viewport output").repaint_delay;
|
||||
assert!(delay.is_zero(), "scroll_both must request immediate repaint when discard is exhausted (repaint_delay={delay:?})");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Localization parity with Microsoft Word
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-06 · **Change:** minor (Bosnian interface: `bs` in the language list, `bs-BA` system locales, catalog in storytold/craft-i18n); previously trivial (Arabic: the Home tab's Styles gallery reads from the right, its arrows at the left (#5566); readiness unchanged); previously trivial (table sort and formulas read the Panamanian balboa's `B/.` around a number (`B/. 1,250.50`, `1,250.50 B/.`), as Word does, matched only at the ends of the text so `1/.5` stays a fraction); previously trivial (Arabic: the dialogs of the mirrored Arabic interface read right to left: label-and-field rows, tables (list columns, the Models table), tile galleries and the Add/Remove arrows follow the reading direction, through one `rtl::Table` helper that draws exactly as before in English; no ranked gap closed, readiness estimates unchanged); previously minor (Options › Language redesign: Your languages, Add a language…, Set as default; the Dictionaries folder moved from Proofing); previously trivial (Language packs: the missing-pack bar works on a fresh install and counts the caret's language); previously trivial (Language lists: every installed and available Language pack's language can be chosen in Set Proofing Language, installed ones in Review › Language and the status bar; craft-i18n.rev at 9d6d54d: region names and the Language (Region) template in 35 locales, craft-i18n#145); previously trivial (craft-i18n.rev at cde4900: rows for Options › Language, the missing-pack bar and 28 Language pack language names in 35 locales, craft-i18n#136); previously trivial (craft-proof pin: French elision suggestions first, ca-ES-valencia reads the ca-valencia pack); previously minor (Arabic `ar` interface: craft-i18n catalog, mirrored shell, font fallback, #1195; 28 languages); previously trivial (Language packs: language-packs-2 is published and pinned: 75 packs, adding Danish, German (Germany, Austria, Switzerland), Esperanto, Estonian, Persian, Croatian, Hungarian, Norwegian (Bokmål, Nynorsk), Dutch and Swedish (Sweden, Finland)); previously trivial (Language packs: language-packs-1 is published and pinned, 61 packs; the language requests it covers); previously minor (Language packs: languages beyond English install their spelling dictionary and hyphenation as a pack from File › Options › Language or the missing-pack bar; the default build embeds English Language data only) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-15 · **Change:** trivial (Arabic File pages, Print settings and Options › Language › Your languages tables wider than the window scroll sideways from the right, and narrow File › Info / Print preview bars fit cleanly, #5396); previously minor (Bosnian interface: `bs` in the language list, `bs-BA` system locales, catalog in storytold/craft-i18n); previously trivial (Arabic: the Home tab's Styles gallery reads from the right, its arrows at the left (#5566); readiness unchanged); previously trivial (table sort and formulas read the Panamanian balboa's `B/.` around a number (`B/. 1,250.50`, `1,250.50 B/.`), as Word does, matched only at the ends of the text so `1/.5` stays a fraction); previously trivial (Arabic: the dialogs of the mirrored Arabic interface read right to left: label-and-field rows, tables (list columns, the Models table), tile galleries and the Add/Remove arrows follow the reading direction, through one `rtl::Table` helper that draws exactly as before in English; no ranked gap closed, readiness estimates unchanged); previously minor (Options › Language redesign: Your languages, Add a language…, Set as default; the Dictionaries folder moved from Proofing); previously trivial (Language packs: the missing-pack bar works on a fresh install and counts the caret's language); previously trivial (Language lists: every installed and available Language pack's language can be chosen in Set Proofing Language, installed ones in Review › Language and the status bar; craft-i18n.rev at 9d6d54d: region names and the Language (Region) template in 35 locales, craft-i18n#145); previously trivial (craft-i18n.rev at cde4900: rows for Options › Language, the missing-pack bar and 28 Language pack language names in 35 locales, craft-i18n#136); previously trivial (craft-proof pin: French elision suggestions first, ca-ES-valencia reads the ca-valencia pack); previously minor (Arabic `ar` interface: craft-i18n catalog, mirrored shell, font fallback, #1195; 28 languages); previously trivial (Language packs: language-packs-2 is published and pinned: 75 packs, adding Danish, German (Germany, Austria, Switzerland), Esperanto, Estonian, Persian, Croatian, Hungarian, Norwegian (Bokmål, Nynorsk), Dutch and Swedish (Sweden, Finland)); previously trivial (Language packs: language-packs-1 is published and pinned, 61 packs; the language requests it covers); previously minor (Language packs: languages beyond English install their spelling dictionary and hyphenation as a pack from File › Options › Language or the missing-pack bar; the default build embeds English Language data only) · **Target:** Microsoft Word (Microsoft 365) for Mac 16.113.4
|
||||
|
||||
Interface languages, script support and proofing per language. How translation works (adding a
|
||||
language, the embedded catalogs): `crates/ui-egui/src/i18n.rs`. The catalogs, their format and
|
||||
@@ -276,6 +276,7 @@ WordCraft keeps 2,54 cm).
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-15 | trivial | Arabic: File pages (including narrow File › Info, Print settings and Options › Language › Your languages) wider than the window open at their start on the right and scroll sideways to the left, and the Print preview bar measures localized sheet labels before staying on one row (#5396) |
|
||||
| 2026-10-29 | minor | Bosnian interface (`bs`, Latin script): listed in `LANGUAGES`, `bs-BA` system locales, saved preference and bundled-font tests; catalog in storytold/craft-i18n (`locales/bs/wordcraft.tsv`); no Bosnian proofing |
|
||||
| 2026-11-06 | trivial | Arabic: the Home tab's Styles gallery reads from the right: Normal is the rightmost tile and the scroll arrows and More sit at the gallery's left end, as the rest of the mirrored ribbon (#5566); left to right is unchanged; regression test `the_styles_gallery_reads_from_the_right_in_a_right_to_left_interface` |
|
||||
| 2026-11-05 | trivial | Arabic letters join across a change of formatting and past hidden or deleted text (#4093) |
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user