Dialogs: tabs only; drop the size-keeping page wrapper

Keep the five tab conversions. Remove dialog_page and the Symbol button
move. The test now checks which page a tab shows.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
fluorineandClaude Sonnet 5.5 committed 2026-10-26 15:59:14 -04:00
1 parent 541483ce0b
commit d0f273bbfd
7 files changed
+49 -75

No files matched your search

+2 -2
View File
@@ -496,10 +496,10 @@ fn body(ui: &mut Ui, d: &mut ColorsDialog) -> Option<bool> {
ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.set_width(330.0);
crate::widgets::dialog_page(ui, "colors", |ui| match d.tab {
match d.tab {
ColorsTab::Standard => standard(ui, d),
ColorsTab::Custom => custom(ui, d),
});
}
});
ui.vertical(|ui| {
ui.add_space(110.0);
+28 -25
View File
@@ -828,10 +828,11 @@ fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> bool {
}
ui.add_space(6.0);
let mut insert: Option<(Value, String, String)> = None;
let double = crate::widgets::dialog_page(ui, "symbol", |ui| {
if f.tab == 1 {
return special_ui(app, ui, f, &t);
if f.tab == 1 {
if special_ui(app, ui, f, &mut insert, &t) {
return true;
}
} else {
f.load();
ui.horizontal(|ui| {
ui.label(tl!("Font:"));
@@ -947,15 +948,17 @@ fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> bool {
ui.label(tl!("Character code:"));
});
});
double
});
let (ok, close) = buttons(ui, "Insert", "Close", f.tab == 1 || f.selected.is_some());
if close {
return true;
}
if ok || double {
insert =
if f.tab == 1 { special_insert(f) } else { f.params().map(|p| (p, f.selected.map(String::from).unwrap_or_default(), f.font.clone())) };
if double && let Some(p) = f.params() {
insert = Some((p, f.selected.map(String::from).unwrap_or_default(), f.font.clone()));
}
// The Insert button.
let (ok, close) = buttons(ui, "Insert", "Close", f.selected.is_some());
if ok && let Some(p) = f.params() {
insert = Some((p, f.selected.map(String::from).unwrap_or_default(), f.font.clone()));
}
if close {
return true;
}
}
if let Some((params, ch, font)) = insert {
// Special characters with their own command insert through it (non-breaking hyphen…).
@@ -970,8 +973,8 @@ fn symbol_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm) -> bool {
false
}
/// The Special Characters tab; returns true after a double click.
fn special_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm, t: &Tokens) -> bool {
/// The Special Characters tab; returns true to close.
fn special_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm, insert: &mut Option<(Value, String, String)>, t: &Tokens) -> bool {
let mut double = false;
egui::ScrollArea::vertical().id_salt("special_chars").max_height(CELL * GRID_ROWS as f32 + 60.0).auto_shrink([false, false]).show(ui, |ui| {
egui::Grid::new("special_grid").num_columns(3).striped(true).spacing(vec2(14.0, 4.0)).show(ui, |ui| {
@@ -995,17 +998,17 @@ fn special_ui(app: &mut WordApp, ui: &mut Ui, f: &mut SymbolForm, t: &Tokens) ->
}
});
});
double
}
/// What the Insert button inserts on the Special Characters tab.
fn special_insert(f: &SymbolForm) -> Option<(Value, String, String)> {
let (_, c, cmd) = SPECIAL.get(f.special)?;
let params = match cmd {
Some(id) => json!({"command": id}),
None => json!({"char": c.to_string()}),
};
Some((params, c.to_string(), String::new()))
let (ok, close) = buttons(ui, "Insert", "Close", true);
if (ok || double)
&& let Some((_, c, cmd)) = SPECIAL.get(f.special)
{
let params = match cmd {
Some(id) => json!({"command": id}),
None => json!({"char": c.to_string()}),
};
*insert = Some((params, c.to_string(), String::new()));
}
close
}
// ---------------------------------------------------------------------------------------------
+2 -2
View File
@@ -558,7 +558,7 @@ pub fn borders(app: &mut WordApp, ui: &mut Ui, f: &mut BordersForm) -> bool {
}
ui.add_space(6.0);
let theme = app.session.doc.settings.theme_colors.clone();
crate::widgets::dialog_page(ui, "borders", |ui| match f.tab {
match f.tab {
0 => {
let to_text = f.to_text;
lines(ui, "para", &mut f.para, &theme, Rgb::parse(&f.fill), Target::from(to_text));
@@ -588,7 +588,7 @@ pub fn borders(app: &mut WordApp, ui: &mut Ui, f: &mut BordersForm) -> bool {
ui.radio_value(&mut f.fill_to_text, true, tl!("Text"));
});
}
});
}
let (ok, cancel) = buttons(ui, tl!("OK"));
if ok {
f.apply(app);
+2 -2
View File
@@ -388,7 +388,7 @@ fn autocorrect_ui(app: &mut WordApp, ui: &mut Ui, f: &mut AutoCorrectForm) -> bo
f.tab = k as u8;
}
ui.add_space(6.0);
crate::widgets::dialog_page(ui, "autocorrect", |ui| match f.tab {
match f.tab {
0 => autocorrect_tab(app, ui, f),
1 => {
let o = &mut f.options;
@@ -409,7 +409,7 @@ fn autocorrect_ui(app: &mut WordApp, ui: &mut Ui, f: &mut AutoCorrectForm) -> bo
ui.checkbox(&mut o.tab_indent, tl!("Set left- and first-indent with tabs and backspaces"));
}
_ => math_tab(ui, f),
});
}
error(ui, &f.message);
let (ok, cancel) = buttons(ui, true);
if ok {
+2 -2
View File
@@ -120,10 +120,10 @@ pub fn customize_ribbon(app: &mut WordApp, ui: &mut Ui, f: &mut RibbonForm) -> b
});
});
ui.add_space(4.0);
crate::widgets::dialog_page(ui, "ribbon", |ui| match f.page {
match f.page {
Page::Ribbon => ribbon_page(app, ui, f, h),
Page::QuickAccess => qat_page(app, ui, f, h),
});
}
});
if let Some(spec) = app.session.registry.get(&f.command) {
ui.label(egui::RichText::new(format!("{} · {}", crate::i18n::location(spec.location), spec.id)).small().weak());
+13 -28
View File
@@ -1,5 +1,4 @@
//! Dialogs with real tabs: a click on a tab shows its page, and the dialog
//! keeps its size when the tab changes.
//! Dialogs with real tabs: a click on a tab shows its page.
use egui_kittest::kittest::Queryable;
use serde_json::json;
@@ -40,39 +39,25 @@ fn tab_button<'a>(h: &'a egui_kittest::Harness<'static, WordApp>, label: &'a str
h.query_all_by_role_and_label(egui::accesskit::Role::Button, label).last().unwrap_or_else(|| panic!("no {label} button"))
}
/// Click each tab in turn. After every click `page` must report its index,
/// and the tab strip and the `anchor` button must sit where they sat on the
/// first page, so the dialog kept its size.
fn check(name: &str, tabs: &[&str], anchor: &str, page: impl Fn(&WordApp) -> usize) {
/// Click each tab in turn. After every click `page` must report its index.
fn check(name: &str, tabs: &[&str], page: impl Fn(&WordApp) -> usize) {
let mut h = harness(name);
assert_eq!(page(h.state()), 0, "{name}: opens on the first tab");
// Visit every page once, so the dialog has grown to its largest page.
for label in tabs {
tab_button(&h, label).click();
settle(&mut h);
}
let mut tops = vec![];
for (i, label) in tabs.iter().enumerate() {
tab_button(&h, label).click();
settle(&mut h);
assert_eq!(page(h.state()), i, "{name}: the {label} tab shows its page");
tops.push(tab_button(&h, label).rect().top());
tops.push(tab_button(&h, anchor).rect().top());
}
for pair in tops.chunks(2) {
assert!((pair[0] - tops[0]).abs() <= 0.5, "{name}: the tab strip stays put: {tops:?}");
assert!((pair[1] - tops[1]).abs() <= 0.5, "{name}: the {anchor} button stays put: {tops:?}");
}
}
#[test]
fn colors_tabs_switch_pages_and_keep_the_size() {
check("colors", &["Standard", "Custom"], "OK", |app| app.colors.as_ref().map_or(9, |d| d.tab as usize));
fn colors_tabs_switch_pages() {
check("colors", &["Standard", "Custom"], |app| app.colors.as_ref().map_or(9, |d| d.tab as usize));
}
#[test]
fn symbol_tabs_switch_pages_and_keep_the_size() {
check("symbol", &["Symbols", "Special Characters"], "Insert", |app| match &app.dialog {
fn symbol_tabs_switch_pages() {
check("symbol", &["Symbols", "Special Characters"], |app| match &app.dialog {
Some(Dialog::Insert(d)) => match &**d {
crate::dialogs_insert::InsertDialog::Symbol(f) => f.tab as usize,
_ => 9,
@@ -82,16 +67,16 @@ fn symbol_tabs_switch_pages_and_keep_the_size() {
}
#[test]
fn borders_tabs_switch_pages_and_keep_the_size() {
check("borders", &["Borders", "Page Border", "Shading"], "OK", |app| match &app.dialog {
fn borders_tabs_switch_pages() {
check("borders", &["Borders", "Page Border", "Shading"], |app| match &app.dialog {
Some(Dialog::Borders { form }) => form.tab as usize,
_ => 9,
});
}
#[test]
fn autocorrect_tabs_switch_pages_and_keep_the_size() {
check("autoCorrect", &["AutoCorrect", "AutoFormat As You Type", "Math AutoCorrect"], "OK", |app| match &app.dialog {
fn autocorrect_tabs_switch_pages() {
check("autoCorrect", &["AutoCorrect", "AutoFormat As You Type", "Math AutoCorrect"], |app| match &app.dialog {
Some(Dialog::Review(d)) => match &**d {
crate::dialogs_review::ReviewDialog::AutoCorrect(f) => f.tab as usize,
_ => 9,
@@ -101,8 +86,8 @@ fn autocorrect_tabs_switch_pages_and_keep_the_size() {
}
#[test]
fn customize_ribbon_tabs_switch_pages_and_keep_the_size() {
check("customizeRibbon", &["Ribbon", "Quick Access Toolbar"], "Close", |app| match &app.dialog {
fn customize_ribbon_tabs_switch_pages() {
check("customizeRibbon", &["Ribbon", "Quick Access Toolbar"], |app| match &app.dialog {
Some(Dialog::CustomizeRibbon { form }) => (form.page == crate::dialogs_ribbon::Page::QuickAccess) as usize,
_ => 9,
});
-14
View File
@@ -1348,20 +1348,6 @@ pub fn dialog_tabs(ui: &mut Ui, labels: &[String], selected: usize) -> Option<us
clicked
}
/// A dialog page under [`dialog_tabs`]. Every page of one dialog gets the
/// size of the largest page shown so far, so the dialog keeps its size when
/// the tab changes. `key` tells dialogs apart.
pub fn dialog_page<R>(ui: &mut Ui, key: &str, add: impl FnOnce(&mut Ui) -> R) -> R {
let id = ui.scope_id().with(("dialog_page", key));
let seen: egui::Vec2 = ui.ctx().data(|d| d.get_temp(id)).unwrap_or_default();
let out = ui.scope(|ui| {
ui.set_min_size(seen);
add(ui)
});
ui.ctx().data_mut(|d| d.insert_temp(id, seen.max(out.response.rect.size())));
out.inner
}
#[cfg(test)]
mod tests {
use super::*;