mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-01 10:13:26 -06:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d15cb5264 | ||
|
|
4deb338b44 | ||
|
|
0c6c377681 | ||
|
|
17c163c425 | ||
|
|
920cdb1edf |
@@ -250,7 +250,8 @@ fn side_menu(ui: &mut Ui, band: f32, current: &str, has_document: bool, show_dis
|
||||
.least_width(LeastWidth::SideMenu)
|
||||
.surface(SurfaceKind::Brand)
|
||||
.label(label("File"))
|
||||
.gap(Gap::None)
|
||||
// v0.19.1's row pitch (~42 pt against the 38 pt rows): the theme's tight gap between the page rows.
|
||||
.gap(Gap::Tight)
|
||||
.scroll(Scroll::vertical())
|
||||
.header(move |ui, _| {
|
||||
ui.add_space(band);
|
||||
|
||||
@@ -748,7 +748,7 @@ fn about_stays_at_the_bottom_of_a_side_menu_that_fits() {
|
||||
}
|
||||
|
||||
/// The side menu is production's rail: 200 pt wide (five rail columns, `LeastWidth::SideMenu`), its page rows about
|
||||
/// 38 pt tall one after another. The footer's links are rows of the same place, so they read in the rail's white ink;
|
||||
/// 38 pt tall a tight gap apart. The footer's links are rows of the same place, so they read in the rail's white ink;
|
||||
/// production's were a little shorter (32 pt), which the side menu place has no row for.
|
||||
#[test]
|
||||
fn the_side_menu_rows_are_production_s_rail_rows() {
|
||||
@@ -758,7 +758,9 @@ fn the_side_menu_rows_are_production_s_rail_rows() {
|
||||
// The least width holds in the row beside the page: before, the row gave the menu only its widest name (~123 pt).
|
||||
assert!((190.0..=260.0).contains(&info.width()), "the menu is production's 200 pt rail: {info:?}");
|
||||
assert!((34.0..=44.0).contains(&info.height()), "a page row is a rail row: {info:?}");
|
||||
assert!((recover.min.y - info.max.y).abs() < 1.0, "the rows follow each other without a gap: {info:?} {recover:?}");
|
||||
// v0.19.1's pitch was ~42 pt for 38 pt rows: the rows are a little apart, not touching and not far apart.
|
||||
let gap = recover.min.y - info.max.y;
|
||||
assert!((1.0..=8.0).contains(&gap), "the rows have a small gap between them: {info:?} {recover:?}");
|
||||
assert!(about.height() <= info.height() + 1.0, "the footer link is no taller than a page row: {info:?} {about:?}");
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||
use craft::behavior::{ColumnWidth, Selection, SelectionChange, keyed};
|
||||
use craft::font_manager::Catalog;
|
||||
use craft::font_manager::picker::FontPickerSettings;
|
||||
use craft::theme::Mode;
|
||||
use craft::ui::contract::{Bind, CollectionEvent, ColumnKey, ColumnSpec, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, HeldAnswer, HeldOk, StackDialog, dialog_id};
|
||||
use craft::ui::display::{Kbd, Text};
|
||||
@@ -11,7 +12,7 @@ use craft::ui::layout_components::Stack;
|
||||
use craft::ui::list::{ListRow, ThumbAspect, ThumbSize};
|
||||
use craft::ui::patterns::form_dialogs::{FormCx, FormDialog};
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::runtime::env::{Env, Label};
|
||||
use craft::ui::table::Table;
|
||||
use craft::ui::tabs::{Tab, TabKind, TabStrip};
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
|
||||
@@ -614,7 +615,8 @@ fn symbol_page(ui: &mut Ui, form: &mut SymbolForm, catalog: Option<&Arc<Catalog>
|
||||
{
|
||||
form.jump_to(name);
|
||||
}
|
||||
let dark = ui.visuals().dark_mode;
|
||||
// The theme's mode, not egui's `dark_mode`, which the craft theme does not drive (light tiles in the light theme, #8021).
|
||||
let dark = Env::of(ui).view().mode() == Mode::Dark;
|
||||
let activated = glyph_grid(ui, form, dark);
|
||||
recent_row(ui, form, dark);
|
||||
if let Some(c) = form.selected {
|
||||
|
||||
@@ -25,6 +25,7 @@ use craft::ui::list::{List, ListRow, ToggleCell, ToggleState};
|
||||
use craft::ui::notices::Notice;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::sections::{DialogRole, FooterButton};
|
||||
use craft::ui::style::SurfaceKind;
|
||||
use craft::ui::tabs::{Tab, TabKind, TabStrip};
|
||||
use craft::ui::text::TextField;
|
||||
use egui::{Context, Ui};
|
||||
@@ -260,6 +261,7 @@ impl RibbonDialog {
|
||||
let rows = &self.tree;
|
||||
let out = List::new(word("Ribbon tabs"))
|
||||
.id(self.tree_id(ui))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.tree(true)
|
||||
.select(SelectMode::Single)
|
||||
.columns(columns)
|
||||
@@ -403,6 +405,7 @@ fn pick(ui: &mut Ui, salt: &'static str, label: &str, rows: &[(String, String)],
|
||||
let mut selection = at.map_or_else(Selection::default, Selection::single);
|
||||
List::new(word(label))
|
||||
.id(ui.scope_id().with(salt))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.select(SelectMode::Single)
|
||||
// The list scrolls its own rows, as main's fixed-height boxes did, so the dialog's body does not scroll it too.
|
||||
.max_rows(12)
|
||||
|
||||
@@ -2389,3 +2389,37 @@ fn the_organizer_lists_are_framed() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of #7981 and #7980: the lists of Customize Ribbon and its Quick Access Toolbar page have a visible
|
||||
/// frame, as before the port; without it an empty list is a blank patch.
|
||||
#[test]
|
||||
fn the_ribbon_customizer_lists_are_framed() {
|
||||
use egui::accesskit::Role;
|
||||
fn rects<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::epaint::RectShape>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(inner) => inner.iter().for_each(|s| rects(s, out)),
|
||||
egui::Shape::Rect(r) => out.push(r),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn assert_framed(h: &egui_kittest::Harness<'_, WordApp>, label: &str) {
|
||||
let list = h.get_by_role_and_label(Role::List, label).rect();
|
||||
let mut seen = Vec::new();
|
||||
h.output().shapes.iter().for_each(|c| rects(&c.shape, &mut seen));
|
||||
assert!(
|
||||
seen.iter().any(|r| r.stroke.width > 0.0
|
||||
&& r.stroke.color.a() > 0
|
||||
&& r.rect.contains_rect(list.shrink(2.0))
|
||||
&& list.expand(2.0).contains_rect(r.rect)),
|
||||
"the list {label:?} {list:?} has a border"
|
||||
);
|
||||
}
|
||||
let mut h = app_harness(app_with(""));
|
||||
open_named(&mut h, "customizeRibbon", json!({}));
|
||||
assert_framed(&h, "Categories:");
|
||||
assert_framed(&h, "Commands:");
|
||||
assert_framed(&h, "Ribbon tabs");
|
||||
h.get_by_role_and_label(Role::Tab, "Quick Access Toolbar").click();
|
||||
h.run_steps(3);
|
||||
assert_framed(&h, "Quick Access Toolbar");
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ pub(crate) fn button_picture(id: &str) -> &'static str {
|
||||
|
||||
/// The ink math pictures are rendered in: the theme's text colour.
|
||||
fn ink(ui: &Ui) -> Color32 {
|
||||
ui.visuals().text_color()
|
||||
// The craft theme's token, not egui's visuals, which the craft theme does not drive (grey ink in the light theme, #7975).
|
||||
craft::ui::style::rgba_color(craft::ui::runtime::env::Env::of(ui).tokens.color.text.normal)
|
||||
}
|
||||
|
||||
/// The keys `0..n` as a collection source.
|
||||
@@ -386,6 +387,21 @@ mod placeholder_tests {
|
||||
output.textures_delta.clear();
|
||||
}
|
||||
|
||||
/// The pictures' ink is the craft theme's text colour, so it reads against the window in the light theme (egui's
|
||||
/// own visuals are not driven by the craft theme and gave grey ink there, #7975).
|
||||
#[test]
|
||||
fn the_equation_ink_contrasts_with_the_theme_surface() {
|
||||
let ctx = crate::test_harness::context();
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
let env = craft::ui::runtime::env::Env::of(ui);
|
||||
let luma = |c: egui::Color32| 0.299 * f32::from(c.r()) + 0.587 * f32::from(c.g()) + 0.114 * f32::from(c.b());
|
||||
let ink = super::ink(ui);
|
||||
let surface = craft::ui::style::rgba_color(env.tokens.color.surface.background);
|
||||
assert!((luma(ink) - luma(surface)).abs() > 100.0, "ink {ink:?} against {surface:?}");
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_math_glyph_falls_back_to_its_linear_name() {
|
||||
// Without craft-fonts the interface fonts may have no `┬`: the Equation button's picture
|
||||
|
||||
@@ -61,7 +61,7 @@ pub(super) fn smart_art_design(row: &mut RibbonRow<'_>, app: &mut WordApp) {
|
||||
let on = layouts.iter().position(|l| *l == g.layout);
|
||||
let colors = g.colors;
|
||||
let theme = &theme;
|
||||
let line = ui.visuals().weak_text_color();
|
||||
let line = craft::ui::style::rgba_color(craft::ui::runtime::env::Env::of(ui).tokens.color.text.muted);
|
||||
let picked = pick_tile(ui, tl!("Layouts"), 4, CaptionPlace::None, on, layouts.len(), |at| match layouts.get(at).copied() {
|
||||
Some(layout) => Tile::new(tl!(layout.label()).to_string())
|
||||
.thumb(ThumbAspect::new(46, 31), move |cx, r| crate::dialogs_smart_art::preview(cx, r, layout, colors, theme, line)),
|
||||
|
||||
@@ -476,9 +476,6 @@ impl Tokens {
|
||||
on_close: Color32::WHITE,
|
||||
}
|
||||
}
|
||||
pub fn get(ctx: &egui::Context) -> Tokens {
|
||||
if ctx.global_style().visuals.dark_mode { Tokens::dark() } else { Tokens::light() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Add `faces` after every other font of the interface families.
|
||||
|
||||
Reference in New Issue
Block a user