Compare commits

..
2 Commits
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 ea23b769a1 fix(options): Read Aloud slider, one Agents heading, hints, Apply/Clear on folders (#7987)
Part of #7987. Fixed: the Read Aloud speed is a slider again; the Agents
page no longer repeats its heading; the Display and Save hints sit under
the rows they explain (they were page footnotes), and the Privacy hint
is back; User templates and Dictionaries folder have v0.19.1's Apply and
Clear and the placeholder again (typing saves nothing until Apply or
Enter; Clear returns to the default).

Still open: the General > Initials placeholder (RowKind::Text has no
placeholder, needs craft-libs); the speed slider's accessible value text
does not carry the x unit. Reset Section at the bottom of Advanced is
not a defect: the page scrolls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 07:58:37 +00:00
Martin BallandClaude Opus 5.5 0b324da562 fix(layout): Read Mode fits a wide table to its column (#7988)
In the reading view a table with its own width is scaled to the column,
less its start offset (indent plus half border), mirrored tables too.

Not addressed here: Read Mode laying out 2 wider columns where v0.19.1
laid out 4, and the pager moving from bottom right to bottom left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 05:02:30 +00:00
4 changed files with 201 additions and 27 deletions
+15 -1
View File
@@ -10,7 +10,7 @@ use wordcraft_geom::Rect;
use crate::boxes::BoxContext;
use crate::para::{CellText, ClKind, ParaLayout};
use crate::{BoxInput, BoxLayout, Ctx, Placed, layout_box};
use crate::{BoxInput, BoxLayout, Ctx, Placed, ViewMode, layout_box};
/// Largest preferred table width, as a share of the text column, that a file can ask for.
const MAX_WIDTH_SHARE: f32 = 10.0;
@@ -431,6 +431,12 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
grid.iter_mut().for_each(|w| *w *= k);
total = avail;
}
// The reading view reflows to its column, so even a table with its own width fits it (#7988).
if ctx.opts.view == ViewMode::Read && total > avail && avail > 0.0 {
let k = avail / total;
grid.iter_mut().for_each(|w| *w *= k);
total = avail;
}
if !t.props.fixed {
// Measuring lays paragraphs out once more; it mustn't count their equations twice.
let eq_count = ctx.eq_count;
@@ -477,6 +483,14 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
} else {
indent - first_cell_left_margin_in(t, margins_def)
};
// The reading view fits the table into what the start offset leaves of the column, mirrored or not (#7988).
let room = (avail - start_offset.max(0.0)).max(1.0);
if ctx.opts.view == ViewMode::Read && acc > room && !matches!(t.props.align, Some(Align::Center | Align::Right)) {
let k = room / acc;
colx.iter_mut().for_each(|c| *c *= k);
acc = room;
total = room;
}
let x = match (t.props.align, rtl) {
(Some(Align::Center), _) => (avail - total) / 2.0,
// End alignment: the right margin, or the left one in a right-to-left table.
+25
View File
@@ -660,6 +660,31 @@ fn reading_layout_reflows_into_viewport_height_pages_without_changing_print_layo
assert!(invalid.pages.iter().all(|p| p.w.is_finite() && p.h.is_finite()));
}
#[test]
fn reading_layout_fits_a_wide_table_to_the_column() {
crate::test_fonts();
// #7988: a 468 pt table is wider than a reading column but must not run past its edge, however it is indented or mirrored.
let cases = [(0.0, false, None), (36.0, false, None), (36.0, true, None)];
let aligned = [None, Some(Align::Left), Some(Align::Center), Some(Align::Right)].map(|a| (36.0, false, a));
let aligned_rtl = [Some(Align::Left), Some(Align::Right)].map(|a| (36.0, true, a));
for (indent, rtl, align) in cases.into_iter().chain(aligned).chain(aligned_rtl) {
let mut d = Document::from_text("Before.");
let mut t = Table::new(2, 4, 468.0);
t.props.indent = Some(indent);
t.props.bidi_visual = rtl;
t.props.align = align;
d.insert_block(StoryRef::Body, &Path::top(1), wordcraft_doc::Block::Table(t)).unwrap();
let opts = LayoutOptions { view: ViewMode::Read, web_width: 360.0, read_height: 600.0, ..Default::default() };
let l = layout(&d, &mut LayoutCache::new(), &opts);
let p = &l.pages[0];
let cells: Vec<_> = p.items.iter().filter_map(|i| if let Placed::Cell { rect, .. } = i { Some(*rect) } else { None }).collect();
let (left, right) = cells.iter().fold((f32::MAX, 0.0f32), |(l, r), c| (l.min(c.x), r.max(c.x + c.w)));
assert!(right > left, "cells placed");
assert!(right <= p.body.x + p.body.w + 0.5, "indent {indent} rtl {rtl} {align:?}: right {right} vs column {}", p.body.x + p.body.w);
assert!(left >= p.body.x - 0.5, "indent {indent} rtl {rtl} {align:?}: left {left} vs column {}", p.body.x);
}
}
#[test]
fn hit_and_caret_agree() {
crate::test_fonts();
+76 -26
View File
@@ -9,6 +9,7 @@ use craft::behavior::{EditEvent, MotionMode, keyed};
use craft::ui::buttons::Button;
use craft::ui::contract::{Bind, Entry, Props as _, Show, ShowCollection, ShowContainer};
use craft::ui::display::{Elide, Shade, Text};
use craft::ui::form::{SliderField, SliderFieldLayout};
use craft::ui::layout_components::Row;
use craft::ui::list::{List, ListRow};
use craft::ui::patterns::preferences::{GroupSpec, PageSpec, PrefValue, PreferencesModel, PreferencesPage, RowKind, RowSpec};
@@ -302,7 +303,6 @@ impl PreferencesModel for OptionsModel<'_> {
use crate::StatusCount;
use crate::scroll::ScrollSpeed;
use crate::theme::{Animations, Appearance};
use wordcraft_engine::speech::{MAX_RATE, MIN_RATE};
let app = &*self.app;
let s = &self.strings;
let prefs = &app.session.prefs;
@@ -375,7 +375,8 @@ impl PreferencesModel for OptionsModel<'_> {
b("display.spaces", tl!("Spaces"), marks.spaces),
b("display.paragraphs", tl!("Paragraph marks"), marks.paragraphs),
b("display.hidden", tl!("Hidden text"), marks.hidden),
b("display.allMarks", tl!("Show all formatting marks"), app.session.view.marks),
b("display.allMarks", tl!("Show all formatting marks"), app.session.view.marks)
.help(tl!("These marks show even when Show/Hide ¶ is off.")),
],
),
GroupSpec::new(
@@ -404,8 +405,7 @@ impl PreferencesModel for OptionsModel<'_> {
],
),
],
)
.footnote(tl!("These marks show even when Show/Hide ¶ is off."));
);
let proofing = page_of(
"proofing",
@@ -445,7 +445,11 @@ impl PreferencesModel for OptionsModel<'_> {
GroupSpec::new(Some(tl!("Save documents")), {
// The browser can't write to the user's files, so AutoSave can't be turned on there (#176).
let row = b("save.autosave", tl!("AutoSave documents you have saved in WordCraft"), app.autosave && !browser).enabled(!browser);
vec![if browser { row.help(&s.autosave_reason) } else { row }]
vec![row.help(if browser {
&s.autosave_reason
} else {
tl!("AutoSave writes your changes to the file a moment after you stop typing.")
})]
}),
// The open document's `file.privacyOptions` (#1062): saved with it, honoured when it is saved.
GroupSpec::new(
@@ -460,12 +464,12 @@ impl PreferencesModel for OptionsModel<'_> {
"save.removeDateTime",
tl!("Leave out the date and time of comments and tracked changes when saving"),
settings.remove_date_time,
),
)
.help(tl!("The document you are editing keeps the names and dates; only the saved file leaves them out.")),
],
),
],
)
.footnote(tl!("AutoSave writes your changes to the file a moment after you stop typing."));
);
let language = page_of(
"language",
@@ -486,11 +490,7 @@ impl PreferencesModel for OptionsModel<'_> {
GroupSpec::new(
Some(tl!("Dictionaries")),
vec![
RowSpec::new(
"language.dictionariesFolder",
tl!("Dictionaries folder:"),
RowKind::Text(prefs.dictionaries_folder.as_deref().unwrap_or("")),
)
RowSpec::new("language.dictionariesFolder", tl!("Dictionaries folder:"), RowKind::Custom)
.help(tl!("Hunspell .aff and .dic files here (pl_PL, pt_BR, it_IT, hr_HR, tr_TR) are used before the system's.\nAn installed Language pack is used after this folder.")),
custom("language.dictionaryFiles", tl!("Dictionary files")),
],
@@ -523,12 +523,7 @@ impl PreferencesModel for OptionsModel<'_> {
GroupSpec::new(
Some(tl!("Read Aloud")),
vec![
RowSpec::new(
"accessibility.readAloudSpeed",
tl!("Speed"),
RowKind::float(app.session.read_aloud.rate() as f64, (MIN_RATE as f64)..=(MAX_RATE as f64), 2),
)
.step(0.05),
RowSpec::new("accessibility.readAloudSpeed", tl!("Speed"), RowKind::Custom),
b("accessibility.skipCitations", tl!("Skip citations & bibliography"), app.session.read_aloud.skip_citations),
],
),
@@ -586,12 +581,8 @@ impl PreferencesModel for OptionsModel<'_> {
groups.push(GroupSpec::new(
Some(tl!("File locations")),
vec![
RowSpec::new(
"advanced.templatesFolder",
tl!("User templates:"),
RowKind::Text(prefs.user_templates_folder.as_deref().unwrap_or("")),
)
.help(tl!("File › New lists the .dotx and .dotm templates here under Personal; Save as Word Template starts here.")),
RowSpec::new("advanced.templatesFolder", tl!("User templates:"), RowKind::Custom)
.help(tl!("File › New lists the .dotx and .dotm templates here under Personal; Save as Word Template starts here.")),
],
));
}
@@ -710,6 +701,15 @@ impl PreferencesModel for OptionsModel<'_> {
"general.defaultApp" => default_app_row(self.app, ui),
"proofing.autoCorrect" => self.command_button(ui, tl!("AutoCorrect Options"), "tools.autocorrect"),
"proofing.customDictionaryFile" => self.custom_dictionary_file(ui),
"language.dictionariesFolder" => {
let saved = self.app.session.prefs.dictionaries_folder.clone().unwrap_or_default();
self.folder_row(ui, key, tl!("Dictionaries folder:"), saved, tl!("Not set: the system's usual places").to_string())
}
"advanced.templatesFolder" => {
let saved = self.app.session.prefs.user_templates_folder.clone().unwrap_or_default();
let default = self.app.services.templates_dir.as_ref().map(|d| d.to_string_lossy().into_owned());
self.folder_row(ui, key, tl!("User templates:"), saved, default.unwrap_or_else(|| tl!("Not set").to_string()))
}
"proofing.customDictionary" => self.custom_dictionary(ui),
"language.proofingLanguage" => {
Text::new(self.strings.proofing_language.clone()).role(TypeRole::Caption).shade(Shade::Faint).show(ui);
@@ -724,6 +724,7 @@ impl PreferencesModel for OptionsModel<'_> {
dictionary_files(ui);
false
}
"accessibility.readAloudSpeed" => self.read_aloud_speed(ui),
"advanced.customizeKeyboard" => self.command_button(ui, tl!("Customize…"), "tools.customizeKeyboard"),
"advanced.customizeRibbon" => self.command_button(ui, tl!("Customize…"), "tools.customizeRibbon"),
_ => false,
@@ -732,7 +733,6 @@ impl PreferencesModel for OptionsModel<'_> {
fn custom_page(&mut self, ui: &mut Ui, page: &str) -> bool {
if page == "agents" {
Text::new(tl!("Agents")).role(TypeRole::Heading).show(ui);
Text::new(tl!("Every command is available to scripts and AI agents: run `wordcraft-cli mcp` for an MCP server, or start the app with `--control <port>` for the JSON control channel."))
.show(ui);
}
@@ -769,6 +769,56 @@ impl OptionsModel<'_> {
clicked
}
/// The Read Aloud speed: a slider with its number, as the player's.
fn read_aloud_speed(&mut self, ui: &mut Ui) -> bool {
use wordcraft_engine::speech::{MAX_RATE, MIN_RATE};
let rate = f64::from(self.app.session.read_aloud.rate());
let out = SliderField::new(tl!("Speed"), Bind::given(rate), f64::from(MIN_RATE)..=f64::from(MAX_RATE))
.step(0.05)
.layout(SliderFieldLayout::Inline)
.short(true)
.unit(tl!("×"))
.show(ui);
// Committed, not live, so a drag doesn't restart the sentence on every frame.
let committed = out.edit.events.committed().copied();
if let Some(v) = committed {
self.set("accessibility.readAloudSpeed", PrefValue::Float(v));
}
committed.is_some()
}
/// A folder setting (v0.19.1's): the saved path or a placeholder, Apply (or Enter) saves the typed path,
/// Clear returns to the default. The draft follows the saved path whenever that changes.
fn folder_row(&mut self, ui: &mut Ui, key: &str, label: &'static str, saved: String, placeholder: String) -> bool {
#[derive(Clone, Default)]
struct Draft {
text: String,
seen: Option<String>,
}
let mut changed = false;
Row::new().id_salt(key).show(ui, |ui, cx| {
let draft = &mut cx.keep::<Draft>();
if draft.seen.as_deref() != Some(saved.as_str()) {
draft.text = saved.clone();
draft.seen = Some(saved.clone());
}
let out = TextField::new(label, Bind::bound(&mut draft.text)).limit(None).placeholder(placeholder.clone()).submits().show(ui);
let typed = draft.text.trim().to_string();
let differs = typed != saved;
let apply = Button::new(tl!("Apply")).enabled(differs).show(ui).clicked() || (out.submitted && differs);
let clear = Button::new(tl!("Clear")).enabled(!saved.is_empty()).show(ui).clicked();
if apply {
self.set(key, PrefValue::Text(typed));
changed = true;
} else if clear {
self.set(key, PrefValue::Text(String::new()));
draft.text.clear();
changed = true;
}
});
changed
}
fn custom_dictionary_file(&mut self, ui: &mut Ui) -> bool {
let saved = self.app.session.prefs.custom_dictionary.clone().unwrap_or_default();
let out = TextField::new(tl!("Dictionary file:"), Bind::given(saved)).limit(None).show(ui);
+85
View File
@@ -454,3 +454,88 @@ fn escape_does_not_commit_the_custom_dictionary_path() {
assert_eq!(dictionary_field_text(&h), "", "the field shows the saved (empty) path");
let _ = std::fs::remove_dir_all(&dir);
}
/// #7987: the Read Aloud speed is a slider, not only a number box.
#[test]
fn read_aloud_speed_is_a_slider() {
use egui_kittest::kittest::Queryable;
let h = options_harness(app(), system_reducing_motion(false));
let _ = h.get_by_role_and_label(egui::accesskit::Role::Slider, "Speed");
}
/// #7987: the Agents page names itself once.
#[test]
fn agents_page_has_one_heading() {
use egui_kittest::kittest::Queryable;
let mut a = app();
a.run("ui.backstage", json!({"value": true, "page": "options", "pane": "agents"})).unwrap();
let mut h = crate::test_harness::builder().build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
options_frames(&mut h, 3);
use egui_kittest::kittest::NodeT;
// The nav entry is a list item; every other node that carries the name is a title.
let titles = h.query_all_by_label("Agents").filter(|n| n.accesskit_node().role() != egui::accesskit::Role::ListItem).count();
assert_eq!(titles, 2, "the page's group and its title, no second heading");
}
/// #7987: a hint sits under the setting it explains, not in a page footnote at the bottom.
#[test]
fn display_and_save_hints_sit_under_their_rows() {
let mut a = app();
let (display, save, privacy) = with_model(&mut a, true, |m| {
let pages = m.pages();
let help_of = |page: &str, key: &str| {
let p = pages.iter().find(|p| p.id == page).expect("page");
let r = p.groups.iter().flat_map(|g| g.rows.iter()).find(|r| r.key == key).expect("row");
(p.footnote.is_none(), r.help.is_some())
};
(help_of("display", "display.allMarks"), help_of("save", "save.autosave"), help_of("save", "save.removeDateTime"))
});
assert_eq!(display, (true, true));
assert_eq!(save, (true, true));
assert_eq!(privacy, (true, true), "the Privacy hint under its row");
}
/// #7987: a folder setting has Apply and Clear. Typing alone saves nothing, Apply saves the typed path, and Clear
/// returns to the default.
#[test]
fn folder_settings_have_apply_and_clear() {
use egui_kittest::kittest::Queryable;
let dir = std::env::temp_dir().join(format!("wc-ui-folder-row-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.to_string_lossy().into_owned();
for (pane, label, saved) in [
("advanced", "User templates:", (|a: &WordApp| a.session.prefs.user_templates_folder.clone()) as fn(&WordApp) -> Option<String>),
("language", "Dictionaries folder:", |a: &WordApp| a.session.prefs.dictionaries_folder.clone()),
] {
let mut a = app();
a.run("ui.backstage", json!({"value": true, "page": "options", "pane": pane})).unwrap();
let mut h = crate::test_harness::builder().build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
options_frames(&mut h, 3);
h.get_by_role_and_label(egui::accesskit::Role::TextInput, label).focus();
options_frames(&mut h, 2);
h.get_by_role_and_label(egui::accesskit::Role::TextInput, label).type_text(&path);
options_frames(&mut h, 3);
assert_eq!(saved(h.state()), None, "{label} typing alone saved");
h.get_by_label("Apply").click();
options_frames(&mut h, 3);
assert_eq!(saved(h.state()).as_deref(), Some(path.as_str()), "{label} Apply");
h.get_by_label("Clear").click();
options_frames(&mut h, 3);
assert_eq!(saved(h.state()), None, "{label} Clear");
}
let _ = std::fs::remove_dir_all(&dir);
}