Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 f644f93a4b fix(read-mode): lay out 4 columns at 1440 px, not 2 (#8019)
craft's reading_size takes its column target from the body text's measure
(66 characters), which is wider than the 295 px v0.19.1 used. Keep the
gaps from the tokens and pin the target and least width to the old values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 12:03:36 +00:00
2 changed files with 33 additions and 1 deletions
+14 -1
View File
@@ -56,7 +56,7 @@ impl Component for ReadingProbe {
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> egui::Vec2 {
let measure = ReadingMeasure::of(TypeRole::Body, |run| cx.layout(run));
self.measured = Some(ReadingMetrics::new(cx.style.column_gap, cx.style.nav_bar, measure));
self.measured = Some(metrics(cx.style.column_gap, cx.style.nav_bar, measure));
egui::Vec2::ZERO
}
@@ -69,6 +69,19 @@ impl Component for ReadingProbe {
}
}
/// Column widths Read Mode has always used (about one column per 295 screen points, none under 192), as v0.19.1 laid out 4
/// columns at 1440 screen points. craft's body-text measure (66 characters) gives 2 there, so only the gaps come from it.
const COLUMN_TARGET: f32 = 295.0;
const COLUMN_MIN: f32 = 192.0;
fn metrics(column_gap: f32, nav_bar: f32, measure: ReadingMeasure) -> ReadingMetrics {
let mut m = ReadingMetrics::new(column_gap, nav_bar, measure);
// lean: fixed px, not the text size; follow the body text again if Read Mode should scale with it.
m.column_target = COLUMN_TARGET;
m.column_min = COLUMN_MIN;
m
}
/// The reading metrics under the current theme, or `None` when the probe did not measure this pass.
pub(super) fn read(ui: &mut Ui) -> Option<ReadingMetrics> {
ReadingProbe { common: Common::new(), measured: None }.label("Reading metrics").show(ui).metrics
+19
View File
@@ -253,6 +253,25 @@ fn drawing_over_the_pages_follows_the_read_mode_page_color() {
assert_eq!(blank(&a), Rgb::WHITE, "the paper under the raster, not the page color");
}
/// #8019: at 1440 x 900 Read Mode lays out several narrow columns (v0.19.1: 4), not the two the body
/// text's measure gave after the port.
#[test]
fn read_mode_lays_out_several_columns_at_1440() {
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Hello WordCraft")), Default::default());
a.run("view.readMode", json!({})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.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 px = ReadingView::screen_scale(1.0) * h.state().session.view.read_width;
assert!(px > 0.0 && 4.0 * px < 1440.0, "columns {px} px wide: four do not fit");
}
/// #299: the caret's colour is worked out only when the caret is drawn: with text selected
/// there is no caret, so the page's draw list isn't built for it.
#[test]