mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-28 21:49:49 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af6da289d1 | ||
|
|
f644f93a4b |
@@ -716,8 +716,17 @@ fn show_reading(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: R
|
||||
let mut state = std::mem::take(&mut app.canvas.reading);
|
||||
let source = source::WordPages::new(app, layout, false, None);
|
||||
let out = ReadingView::new(tl!("Document"), &source, &mut state, paper).zoom(zoom).show_at(ui, columns);
|
||||
// The page-turn row sits at the bottom right, as in v0.19.1 (the far end, so the bottom left in a right-to-left UI),
|
||||
// the page view's side margin in from the edge.
|
||||
let margin = Env::of(ui).tokens.space.inset.page_side;
|
||||
let footer = footer.shrink2(egui::vec2(margin, 0.0));
|
||||
let far = if crate::i18n::current().rtl() {
|
||||
egui::Layout::left_to_right(egui::Align::Center)
|
||||
} else {
|
||||
egui::Layout::right_to_left(egui::Align::Center)
|
||||
};
|
||||
let nav = ui
|
||||
.scope_builder(egui::UiBuilder::new().max_rect(footer), |ui| {
|
||||
.scope_builder(egui::UiBuilder::new().max_rect(footer).layout(far), |ui| {
|
||||
ReadingNav::new(&mut state, layout.pages.len()).position(true).action(tl!("Edit Document")).show(ui)
|
||||
})
|
||||
.inner;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -253,6 +253,48 @@ 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");
|
||||
}
|
||||
|
||||
/// #8019: the page-turn row (position and Edit Document) sits in the bottom-right quadrant, as in v0.19.1,
|
||||
/// not at the bottom left where craft's row starts.
|
||||
#[test]
|
||||
fn read_mode_pager_is_at_the_bottom_right() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
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 screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0));
|
||||
for label in ["Edit Document", "1 / 1"] {
|
||||
let r = h.get_all_by_label(label).last().unwrap().rect();
|
||||
assert!(r.center().x > screen.center().x && r.center().y > screen.center().y, "{label} at {r:?}: not bottom right");
|
||||
}
|
||||
}
|
||||
|
||||
/// #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]
|
||||
|
||||
Reference in New Issue
Block a user