mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-24 21:09:15 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
799ce2bb6c | ||
|
|
e433bdb784 |
@@ -0,0 +1,69 @@
|
||||
# Accessibility
|
||||
|
||||
Source: `standards/app-accessibility.md` in [storytold/craft-contrib](https://github.com/storytold/craft-contrib/blob/main/standards/app-accessibility.md); do not edit this copy directly. Propose changes to the shared statement in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib).
|
||||
|
||||
We want people who use screen readers, braille displays, screen magnifiers, voice control, high contrast, large text, reduced motion, or keyboard navigation to be able to get their work done in the Craft applications.
|
||||
|
||||
## Supported environments and how accessibility works
|
||||
|
||||
The Craft applications draw their own interface in Rust with `egui` and expose accessibility information through **AccessKit**:
|
||||
|
||||
- **Windows:** UI Automation (for tools such as NVDA, JAWS, and Narrator)
|
||||
- **macOS:** NSAccessibility (VoiceOver)
|
||||
- **Linux and FreeBSD:** AT-SPI (Orca)
|
||||
- **Web (WebAssembly):** Browser accessibility tree in modern evergreen browsers
|
||||
- **Display and motion:** Light and dark themes, along with ongoing work to honour system high-contrast, text-scaling, and reduced-motion settings
|
||||
- **Headless and command-line workflows:** Most Craft applications also ship a command-line and automation binary (`<app>-cli`) that can inspect and edit documents from a terminal without using the graphical interface; see [This application](#this-application) below
|
||||
|
||||
**Current status:** The Craft suite is in early-alpha development. We use WCAG 2.2 and W3C's [WCAG2ICT](https://www.w3.org/TR/wcag2ict-22/) as practical reference points for user needs ([RFC-0014](https://github.com/storytold/craft-contrib/blob/main/rfcs/0014-accessibility.md)), while manual testing with assistive technologies across every tool and surface is still in progress.
|
||||
|
||||
## Known limitations and workarounds
|
||||
|
||||
Shared framework improvements are tracked in [storytold/craft-libs#437](https://github.com/storytold/craft-libs/issues/437). Current suite-wide gaps include:
|
||||
|
||||
- **Custom drawn surfaces (canvases, pages, grids, timelines, node graphs, and layer lists):** Some custom-painted views do not yet publish complete `AccessKit` nodes, caret bounds for magnifiers, or editable states (for example, `AccessKit`'s Windows adapter reporting `Document` nodes as read-only, which can prevent typing echo in screen readers). *Workaround:* Use structured inspector panels where available, or run headless commands through `<app>-cli` when a task does not need direct canvas interaction.
|
||||
- **Focus in menus, toolbars, and dialogs:** Some popups, menus, or keyboard access-key overlays may leave focus in the underlying document or not yet restore focus cleanly when dismissed. *Workaround:* Press `Escape` to close open popups, `Alt` or `F10` for menu/toolbar navigation, and `F6` to move between major regions where supported.
|
||||
- **Unannounced state changes:** Shortcuts or background tasks that change state away from focus do not yet consistently announce updates through a live region.
|
||||
- **Pointer-heavy interactions:** Certain timeline, node-wiring, or object-placement gestures do not yet have non-dragging keyboard alternatives.
|
||||
|
||||
See [This application](#this-application) below for repository-specific links and details.
|
||||
|
||||
## Reporting an accessibility barrier
|
||||
|
||||
If you run into an accessibility barrier, please open an issue using the link in [This application](#this-application) below (or let us know in the [ArtCraft Discord](https://discord.gg/artcraft) if GitHub's issue form gets in the way).
|
||||
|
||||
- **No personal disclosure needed:** You never have to disclose a disability or explain why you use assistive technology.
|
||||
- **Screenshots and recordings are optional:** Plain-text descriptions are always welcome and sufficient.
|
||||
- **Helpful details to share (when convenient):**
|
||||
- What you were trying to do, what happened, and what you expected
|
||||
- Application version (or commit) and operating system or browser
|
||||
- Input method, display settings, or assistive technology and version (for example, NVDA, JAWS, Narrator, VoiceOver, Orca, screen magnifier, high contrast, text scaling, or keyboard-only)
|
||||
|
||||
## How we respond
|
||||
|
||||
- **Triage and labels:** Maintainers and triagers label barrier reports with `accessibility` and set priority during triage based on impact—barriers that block a core workflow are treated as high-priority bugs, and barriers that risk losing work are critical.
|
||||
- **Assistive-technology verification (`needs screen reader test`):** Pull requests that fix a reported assistive-technology barrier or add custom accessibility-tree or focus behaviour are labelled `needs screen reader test` so someone using assistive technology can verify a build and share what they observed; if the barrier remains, we reopen the issue.
|
||||
|
||||
## Note for contributors and coding agents
|
||||
|
||||
`ACCESSIBILITY.md` is a user-facing overview, **not** an extra rule set or audit checklist for coding agents:
|
||||
|
||||
- **Follow `AGENTS.md` and [`standards/accessibility.md`](https://github.com/storytold/craft-contrib/blob/main/standards/accessibility.md) for engineering work,** and keep every pull request scoped strictly to its issue. Do not widen an unrelated change to audit or rework surrounding UI.
|
||||
- **Design for the actual user need—do not overbuild or apply naive readings of standards.** Accessibility guidelines exist to support real workflows and give flexible ways to meet them. Understand what a criterion genuinely requires in context before changing UI: for example, a button whose label or icon is legible and whose focus or selection ring already has clear contrast does **not** need its resting fill or border restyled to hit a 3:1 ratio, and inherently spatial or freehand tools should not have artificial keyboard grids bolted onto them.
|
||||
- **Preserve visual design and shared primitives.** Use shared theme tokens and shared widgets from `storytold/craft-libs` instead of inventing one-off styling, contrast overrides, focus shims, or live-region scaffolding inside an application.
|
||||
- **Be candid in pull requests.** Automated accessibility-tree checks never prove a change works with a real screen reader; describe only what was actually verified.
|
||||
|
||||
## Ownership
|
||||
|
||||
Maintained by the `craft-app-team` maintainers in [`storytold`](https://github.com/storytold). Shared updates belong in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib); repository-specific facts follow below.
|
||||
|
||||
## This application
|
||||
|
||||
**WordCraft** (`storytold/wordcraft`) is an open-source word processor written in pure Rust.
|
||||
|
||||
- **Published application builds:** macOS, Windows, Linux, FreeBSD, and Web (WebAssembly)
|
||||
- **Command-line and automation interface:** `wordcraft-cli` provides headless terminal and automation access for scripted workflows without the graphical interface
|
||||
- **Report an accessibility barrier:** [Open an issue in `storytold/wordcraft`](https://github.com/storytold/wordcraft/issues/new)
|
||||
- **Tracked accessibility issues:** [Open issues labelled `accessibility` in `storytold/wordcraft`](https://github.com/storytold/wordcraft/issues?q=is%3Aissue+state%3Aopen+label%3Aaccessibility)
|
||||
- **Pull requests awaiting assistive-technology verification:** [Pull requests labelled `needs screen reader test` in `storytold/wordcraft`](https://github.com/storytold/wordcraft/pulls?q=is%3Apr+label%3A%22needs+screen+reader+test%22)
|
||||
- **Contributor and agent rules for this repository:** [`AGENTS.md`](AGENTS.md)
|
||||
@@ -123,107 +123,4 @@ mod tests {
|
||||
assert!(supplied.exists());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
const TOKEN: &str = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
|
||||
fn boot() -> (u16, Receiver<ControlRequest>, Control) {
|
||||
let options = ControlOptions { token: Some(TOKEN.to_string()), ..ControlOptions::default() };
|
||||
let (rx, control) = start(&options, 0, host(), None).unwrap();
|
||||
let port = control.listening.addr.port();
|
||||
(port, rx, control)
|
||||
}
|
||||
|
||||
/// Answer the next request that reaches the UI with `ok`, and return it.
|
||||
fn answer(rx: &Receiver<ControlRequest>) -> ControlRequest {
|
||||
let req = rx.recv_timeout(std::time::Duration::from_secs(5)).unwrap();
|
||||
let _ = req.reply.send(serde_json::json!({"ok": true, "result": {}}));
|
||||
req
|
||||
}
|
||||
|
||||
/// One connection, several lines.
|
||||
struct Conn(std::io::BufReader<std::net::TcpStream>, std::net::TcpStream);
|
||||
|
||||
impl Conn {
|
||||
fn open(port: u16) -> Self {
|
||||
let s = std::net::TcpStream::connect(("127.0.0.1", port)).unwrap();
|
||||
s.set_read_timeout(Some(std::time::Duration::from_secs(5))).unwrap();
|
||||
Self(std::io::BufReader::new(s.try_clone().unwrap()), s)
|
||||
}
|
||||
fn send(&mut self, line: &str) {
|
||||
use std::io::Write;
|
||||
writeln!(self.1, "{line}").unwrap();
|
||||
}
|
||||
fn recv(&mut self) -> serde_json::Value {
|
||||
use std::io::BufRead;
|
||||
let mut r = String::new();
|
||||
let n = self.0.read_line(&mut r).expect("read reply line");
|
||||
assert!(n > 0, "unexpected EOF while waiting for reply");
|
||||
serde_json::from_str(&r).expect("reply is valid JSON")
|
||||
}
|
||||
fn call(&mut self, line: &str) -> serde_json::Value {
|
||||
self.send(line);
|
||||
self.recv()
|
||||
}
|
||||
/// The server closed the connection.
|
||||
fn closed(&mut self) -> bool {
|
||||
use std::io::BufRead;
|
||||
let mut r = String::new();
|
||||
match self.0.read_line(&mut r) {
|
||||
Ok(0) => true,
|
||||
Err(e) => matches!(
|
||||
e.kind(),
|
||||
std::io::ErrorKind::ConnectionReset
|
||||
| std::io::ErrorKind::ConnectionAborted
|
||||
| std::io::ErrorKind::NotConnected
|
||||
| std::io::ErrorKind::BrokenPipe
|
||||
),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Post-#7101 adaptation of `the_key_on_each_request` (#124, tracked under #7317 / #7720):
|
||||
/// `craft::automation::server` replaced the legacy per-request `"key"` field with one-time
|
||||
/// per-connection token authentication (`docs/control-protocol.md`, Token).
|
||||
#[test]
|
||||
fn a_connection_authenticates_once_with_the_token_and_unauthenticated_requests_are_refused() {
|
||||
let (port, rx, control) = boot();
|
||||
|
||||
// Authenticate once per connection with `params.token`.
|
||||
let mut c = Conn::open(port);
|
||||
let auth_resp = c.call(&format!(r#"{{"id":1,"method":"auth","params":{{"token":"{TOKEN}"}}}}"#));
|
||||
assert_eq!(auth_resp, serde_json::json!({"id": 1, "ok": true, "result": {"authenticated": true}}));
|
||||
|
||||
// Subsequent requests on the authenticated connection carry no token and reach the UI.
|
||||
c.send(r#"{"id":7,"method":"document.inspect","params":{"text":true}}"#);
|
||||
let req = answer(&rx);
|
||||
assert_eq!((req.method.as_str(), &req.params), ("document.inspect", &serde_json::json!({"text": true})));
|
||||
let r = c.recv();
|
||||
assert_eq!((&r["ok"], &r["id"]), (&serde_json::json!(true), &serde_json::json!(7)));
|
||||
|
||||
c.send(r#"{"id":8,"method":"document.inspect","params":{"text":false}}"#);
|
||||
let req = answer(&rx);
|
||||
assert_eq!((req.method.as_str(), &req.params), ("document.inspect", &serde_json::json!({"text": false})));
|
||||
let r = c.recv();
|
||||
assert_eq!((&r["ok"], &r["id"]), (&serde_json::json!(true), &serde_json::json!(8)));
|
||||
drop(c);
|
||||
|
||||
// An unauthenticated connection is refused and closed without reaching the UI.
|
||||
let mut unauth = Conn::open(port);
|
||||
let r = unauth.call(r#"{"id":9,"method":"document.inspect"}"#);
|
||||
assert_eq!(r, serde_json::json!({"id": 9, "ok": false, "error": "authentication required"}));
|
||||
assert!(unauth.closed());
|
||||
assert!(rx.try_recv().is_err(), "unauthenticated request must not reach the UI");
|
||||
drop(unauth);
|
||||
|
||||
// Legacy pre-#7101 per-request `"key"` does not bypass `auth` and closes the connection.
|
||||
let mut legacy = Conn::open(port);
|
||||
let r = legacy.call(&format!(r#"{{"id":10,"key":"{TOKEN}","method":"document.inspect","params":{{"text":true}}}}"#));
|
||||
assert_eq!(r, serde_json::json!({"id": 10, "ok": false, "error": "authentication required"}));
|
||||
assert!(legacy.closed());
|
||||
assert!(rx.try_recv().is_err(), "legacy per-request key must not reach the UI");
|
||||
drop(legacy);
|
||||
|
||||
control.shut_down();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,145 +158,4 @@ mod tests {
|
||||
let missing = missing_glyphs(&stack, &FontRef::proportional(), samples, false);
|
||||
assert!(missing.is_empty(), "symbols without a glyph: {missing:#?}");
|
||||
}
|
||||
|
||||
/// An installed Arabic font is asked for only when Arabic text needs one (and no embedded
|
||||
/// Arabic face covers it): neither installing the UI font stack for English/CJK/Arabic nor
|
||||
/// triggering CJK on-demand fallback ever asks for an Arabic system font, and Arabic on-demand
|
||||
/// fallback never asks for a CJK system font.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn the_installed_arabic_font_is_asked_for_by_arabic_alone() {
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use craft::host::Wake;
|
||||
use craft::i18n::Han;
|
||||
use craft::ui::fonts::{FontCandidates, on_demand_registered};
|
||||
|
||||
struct RecordingCandidates {
|
||||
scripts: Mutex<Vec<String>>,
|
||||
}
|
||||
|
||||
impl RecordingCandidates {
|
||||
fn new() -> Arc<Self> {
|
||||
Arc::new(Self { scripts: Mutex::new(Vec::new()) })
|
||||
}
|
||||
|
||||
fn scripts(&self) -> Vec<String> {
|
||||
self.scripts.lock().map(|guard| guard.clone()).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl FontCandidates for RecordingCandidates {
|
||||
fn files(&self, script: &str, han: Option<Han>) -> Vec<PathBuf> {
|
||||
if let Ok(mut scripts) = self.scripts.lock() {
|
||||
scripts.push(script.to_owned());
|
||||
}
|
||||
SystemCandidates.files(script, han)
|
||||
}
|
||||
|
||||
fn covers(&self, data: &[u8], c: char) -> Option<u32> {
|
||||
SystemCandidates.covers(data, c)
|
||||
}
|
||||
|
||||
fn pending(&self) -> bool {
|
||||
SystemCandidates.pending()
|
||||
}
|
||||
|
||||
fn wake_when_ready(&self, wake: Wake) {
|
||||
SystemCandidates.wake_when_ready(wake);
|
||||
}
|
||||
}
|
||||
|
||||
let paint = |ctx: &egui::Context, text: &str| {
|
||||
for _ in 0..6 {
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
ui.label(text);
|
||||
})
|
||||
.drop_without_applying_deltas();
|
||||
}
|
||||
};
|
||||
let is_cjk_script = |script: &str| matches!(script, "Hani" | "Hira" | "Kana" | "Hang" | "Bopo");
|
||||
|
||||
let en = Lang::EN;
|
||||
let ja = crate::i18n::fixture_lang("ja", "\tHome\tホーム\n");
|
||||
let ar = crate::i18n::fixture_lang("ar", "\tHome\tالرئيسية\n");
|
||||
|
||||
// Installing the production `ui_fonts` stack and painting Latin text never requests or
|
||||
// loads an installed Arabic or CJK system font up front.
|
||||
for lang in [en, ja, ar] {
|
||||
let ctx = egui::Context::default();
|
||||
let spy = RecordingCandidates::new();
|
||||
ui_fonts(lang).on_demand(Arc::clone(&spy) as Arc<dyn FontCandidates>).install(&ctx);
|
||||
assert!(on_demand_registered(&ctx).is_empty(), "{}: installing ui_fonts reads no system font eagerly", lang.code());
|
||||
assert!(spy.scripts().is_empty(), "{}: installing ui_fonts requests no system font candidates", lang.code());
|
||||
paint(&ctx, "Hello");
|
||||
assert!(on_demand_registered(&ctx).is_empty(), "{}: Latin UI text reads no system font", lang.code());
|
||||
assert!(spy.scripts().is_empty(), "{}: Latin UI text requests no system font candidates", lang.code());
|
||||
}
|
||||
|
||||
let embedded_arabic: Vec<String> = CRAFT_FONTS.iter().filter(|f| f.has_script("Arab")).map(EmbeddedFace::name).collect();
|
||||
let ar_ctx = egui::Context::default();
|
||||
let ar_stack = ui_fonts(ar).install(&ar_ctx);
|
||||
let en_stack = ui_fonts(en).stack();
|
||||
let ja_stack = ui_fonts(ja).stack();
|
||||
if !embedded_arabic.is_empty() {
|
||||
assert!(
|
||||
ar_stack.chain(&FontRef::proportional()).first().is_some_and(|name| embedded_arabic.contains(name)),
|
||||
"Arabic UI leads with its embedded Arabic face"
|
||||
);
|
||||
assert!(
|
||||
!en_stack.chain(&FontRef::proportional()).first().is_some_and(|name| embedded_arabic.contains(name)),
|
||||
"English UI does not lead with an Arabic face"
|
||||
);
|
||||
assert!(
|
||||
!ja_stack.chain(&FontRef::proportional()).first().is_some_and(|name| embedded_arabic.contains(name)),
|
||||
"CJK UI does not lead with an Arabic face"
|
||||
);
|
||||
paint(&ar_ctx, "مرحبا");
|
||||
assert!(ar_ctx.fonts_mut(|f| f.has_glyph(&egui::FontId::proportional(14.0), 'ع')), "embedded Arabic face draws Arabic text");
|
||||
assert!(on_demand_registered(&ar_ctx).is_empty(), "no installed Arabic system font is read when an embedded Arabic face covers Arabic");
|
||||
} else {
|
||||
paint(&ar_ctx, "مرحبا");
|
||||
let registered = on_demand_registered(&ar_ctx);
|
||||
let arabic_candidates = SystemCandidates.files("Arab", None);
|
||||
assert!(!registered.is_empty() || cfg!(not(any(target_os = "macos", windows))), "macOS and Windows ship an installed Arabic font");
|
||||
if !registered.is_empty() {
|
||||
assert_eq!(registered.len(), 1, "Arabic text registers one installed Arabic face");
|
||||
assert!(arabic_candidates.contains(®istered[0].1), "registered face {:?} came from Arabic system candidates", registered[0].1);
|
||||
assert!(ar_ctx.fonts_mut(|f| f.has_glyph(&egui::FontId::proportional(14.0), 'ع')), "installed Arabic system font draws Arabic text");
|
||||
}
|
||||
}
|
||||
|
||||
// CJK on-demand lookup through `ui_fonts` never asks for an Arabic system font (U+3400 is
|
||||
// CJK Extension A, outside embedded catalog subsets, so it exercises CJK on-demand lookup
|
||||
// even in builds with `CRAFT_FONTS_DIR`).
|
||||
let cjk_spy = RecordingCandidates::new();
|
||||
let cjk_ctx = egui::Context::default();
|
||||
ui_fonts(ja).on_demand(Arc::clone(&cjk_spy) as Arc<dyn FontCandidates>).install(&cjk_ctx);
|
||||
paint(&cjk_ctx, "日本語 㐀");
|
||||
let cjk_scripts = cjk_spy.scripts();
|
||||
assert!(!cjk_scripts.iter().any(|s| s == "Arab"), "CJK fallback never asks for an Arabic font: {cjk_scripts:?}");
|
||||
if !cjk_ctx.fonts_mut(|f| f.has_glyph(&egui::FontId::proportional(14.0), '\u{3400}')) || !on_demand_registered(&cjk_ctx).is_empty() {
|
||||
assert!(cjk_scripts.iter().any(|s| is_cjk_script(s)), "uncovered CJK text asks for CJK candidates: {cjk_scripts:?}");
|
||||
}
|
||||
|
||||
// Arabic on-demand lookup when no embedded Arabic face is present asks for Arabic alone
|
||||
// and never triggers a CJK system-font lookup.
|
||||
let ar_spy = RecordingCandidates::new();
|
||||
let ar_no_embed_ctx = egui::Context::default();
|
||||
if embedded_arabic.is_empty() {
|
||||
ui_fonts(ar).on_demand(Arc::clone(&ar_spy) as Arc<dyn FontCandidates>).install(&ar_no_embed_ctx);
|
||||
} else {
|
||||
UiFonts::new(&I18nScripts)
|
||||
.languages(&["en", "ja", "ar"])
|
||||
.ui_language(ar.code())
|
||||
.on_demand(Arc::clone(&ar_spy) as Arc<dyn FontCandidates>)
|
||||
.install(&ar_no_embed_ctx);
|
||||
}
|
||||
paint(&ar_no_embed_ctx, "مرحبا");
|
||||
let ar_scripts = ar_spy.scripts();
|
||||
assert!(ar_scripts.iter().any(|s| s == "Arab"), "Arabic text without an embedded Arabic face asks for Arab: {ar_scripts:?}");
|
||||
assert!(!ar_scripts.iter().any(|s| is_cjk_script(s)), "Arabic fallback never asks for a CJK font: {ar_scripts:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ impl WordApp {
|
||||
let mode = self.screen_mode();
|
||||
let dropped = self.ribbon_dropped;
|
||||
let key = self.windows.window_key();
|
||||
let ribbon_out = std::cell::RefCell::new(None);
|
||||
let shell = AppShell::new(key)
|
||||
.mode_set(ScreenModeSet::Document)
|
||||
.screen_mode(Bind::given(mode))
|
||||
@@ -95,12 +94,12 @@ impl WordApp {
|
||||
// tabs and collapsed every one of them.
|
||||
.top(Slot::new("ribbonDrop").drops().size(SlotSize::Content), |ui, _cx, app: &mut WordApp| {
|
||||
if !stale(app) {
|
||||
*ribbon_out.borrow_mut() = Some(ribbon::show(app, ui));
|
||||
ribbon_slot(app, ui);
|
||||
}
|
||||
})
|
||||
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _cx, app: &mut WordApp| {
|
||||
if !stale(app) {
|
||||
*ribbon_out.borrow_mut() = Some(ribbon::show(app, ui));
|
||||
ribbon_slot(app, ui);
|
||||
}
|
||||
})
|
||||
// As tall as the bar: a failure's line under the message puts Install below the first line, and a slot of
|
||||
@@ -133,11 +132,6 @@ impl WordApp {
|
||||
self.follow_screen_mode(out.screen_mode);
|
||||
}
|
||||
self.ribbon_dropped = out.dropped;
|
||||
// Keytips run outside the ribbon slots so legacy sequences and their hint still work when
|
||||
// no ribbon shows (Focus, Full Screen View) and anchor under the slim screen bar.
|
||||
let ribbon = ribbon_out.into_inner().unwrap_or_else(ribbon::no_ribbon);
|
||||
let screen_bar = out.regions.slots.iter().find(|(slot, _)| *slot == "screenBar").map(|(_, rect)| *rect);
|
||||
crate::keytips::show(ui, self, &ribbon, screen_bar);
|
||||
out.regions
|
||||
}
|
||||
|
||||
@@ -162,3 +156,9 @@ impl WordApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The ribbon, then its keytips, in a top slot: the keytips read what the ribbon recorded this pass.
|
||||
fn ribbon_slot(app: &mut WordApp, ui: &mut egui::Ui) {
|
||||
let out = ribbon::show(app, ui);
|
||||
crate::keytips::show(ui, app, &out);
|
||||
}
|
||||
|
||||
@@ -156,10 +156,6 @@ pub struct CanvasState {
|
||||
pub(crate) read_force_reflow: bool,
|
||||
/// Web Layout's width follows the window once a drag has settled, not on every frame of it.
|
||||
web_viewport: reading::Settle,
|
||||
/// Side gutter the last `PageView` pass laid pages out with (`PageSpacing::side`), in screen points.
|
||||
pub(crate) page_side: Option<f32>,
|
||||
/// `PageView`'s side gutter changed since the last Web Layout pass, so Web Layout must reflow at once.
|
||||
web_force_reflow: bool,
|
||||
/// First text position on the column currently leading the reading view, captured from the last
|
||||
/// pass's layout. Survives changing page sizes, even when the caret stays elsewhere.
|
||||
pub(crate) read_first_visible: Option<Pos>,
|
||||
@@ -409,8 +405,6 @@ impl Default for CanvasState {
|
||||
nav_to_caret: false,
|
||||
read_force_reflow: false,
|
||||
web_viewport: Default::default(),
|
||||
page_side: None,
|
||||
web_force_reflow: false,
|
||||
read_first_visible: None,
|
||||
dragging: false,
|
||||
column_drag: None,
|
||||
@@ -471,19 +465,16 @@ fn update_viewport(app: &mut WordApp, full: Rect, metrics: &ReadingMetrics, side
|
||||
// Without an anchor (Read Mode was just entered) the view starts at the caret.
|
||||
app.canvas.scroll_to_caret |= reflow_anchor.is_none();
|
||||
}
|
||||
app.canvas.web_force_reflow = false;
|
||||
} else {
|
||||
if app.session.view.mode == wordcraft_layout::ViewMode::Web {
|
||||
// Web Layout wraps to the work area (#1876).
|
||||
let scale = app.session.view.zoom.clamp(0.1, 5.0) * PX_PER_PT;
|
||||
// The page view keeps its side gutter (`PageSpacing::side`) clear on both sides of a page, so the page
|
||||
// The page view keeps its side gutter (the rail width) clear on both sides of a page, so the page
|
||||
// fits the window only when its width leaves that room.
|
||||
let w = web_layout_width((full.width() - 2.0 * side).max(0.0), scale);
|
||||
let changed = (app.session.view.web_width - w).abs() > 0.5;
|
||||
let forced = std::mem::take(&mut app.canvas.web_force_reflow);
|
||||
// At once on entry, a zoom, or a page-spacing change (the viewport holds still), after a window drag
|
||||
// has settled.
|
||||
if app.canvas.web_viewport.apply(full.size(), ctx.input(|i| i.time), changed, forced) {
|
||||
// At once on entry or a zoom (the viewport holds still), after a window drag has settled.
|
||||
if app.canvas.web_viewport.apply(full.size(), ctx.input(|i| i.time), changed, false) {
|
||||
app.session.view.web_width = w;
|
||||
// The pixel offset no longer points at the same text: keep the caret's line in view.
|
||||
app.canvas.scroll_to_caret = true;
|
||||
@@ -492,7 +483,6 @@ fn update_viewport(app: &mut WordApp, full: Rect, metrics: &ReadingMetrics, side
|
||||
}
|
||||
} else {
|
||||
app.canvas.web_viewport.leave();
|
||||
app.canvas.web_force_reflow = false;
|
||||
}
|
||||
app.canvas.read_force_reflow = false;
|
||||
app.canvas.read_first_visible = None;
|
||||
@@ -742,8 +732,7 @@ fn show_reading(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: R
|
||||
pub fn show(app: &mut WordApp, ui: &mut Ui) {
|
||||
let full = ui.available_rect_before_wrap();
|
||||
let Some(metrics) = reading_metrics::read(ui) else { return };
|
||||
let side = app.canvas.page_side.unwrap_or(0.0);
|
||||
let layout = prepare_layout(app, full, &metrics, side, ui.ctx());
|
||||
let layout = prepare_layout(app, full, &metrics, Env::of(ui).tokens.size.rail.width, ui.ctx());
|
||||
if app.session.view.read_mode {
|
||||
show_reading(app, ui, &layout, full, &metrics);
|
||||
} else {
|
||||
@@ -882,20 +871,6 @@ fn show_pages(app: &mut WordApp, ui: &mut Ui, layout: &Arc<DocLayout>, full: Rec
|
||||
});
|
||||
let caret = caret_after.or(caret);
|
||||
app.canvas.page_keys = source.into_keys();
|
||||
let side = out.spacing.side as f32;
|
||||
if side.is_finite() {
|
||||
let side = side.max(0.0);
|
||||
if app.canvas.page_side.is_none_or(|prev| (prev - side).abs() > 0.01) {
|
||||
app.canvas.page_side = Some(side);
|
||||
if app.session.view.mode == wordcraft_layout::ViewMode::Web {
|
||||
app.canvas.web_force_reflow = true;
|
||||
ui.ctx().request_discard("page view side gutter changed");
|
||||
if !ui.ctx().will_discard() {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// This pass's own input changed the document under the pages it drew: run the pass again, so the frame that
|
||||
// delivers a key paints its text (production laid out and painted in the one pass) rather than the next frame.
|
||||
if ran && !Arc::ptr_eq(&laid_before, &app.session.layout()) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use craft::behavior::IconId;
|
||||
use craft::ui::buttons::IconButton;
|
||||
use craft::ui::contract::{BodyCx, Props as _, Show as _, TooltipSpec};
|
||||
use craft::ui::runtime::inspect;
|
||||
use egui::Ui;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -10,9 +11,9 @@ use super::Screen;
|
||||
use crate::WordApp;
|
||||
|
||||
/// Fills the screen-bar slot. Focus: a `more` button that drops the ribbon down over the page. Immersive: the
|
||||
/// command search field.
|
||||
/// command search field. The bar is an inspected region, where the keytips hang their hint while no ribbon shows.
|
||||
pub(crate) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
match Screen::of(&app.session.view) {
|
||||
inspect::record(ui, crate::keytips::screen_bar_region(), |ui| match Screen::of(&app.session.view) {
|
||||
Screen::Focus => {
|
||||
let out = IconButton::new(IconId::new("wordcraft.more"))
|
||||
.label(tl!("Show the ribbon").to_string())
|
||||
@@ -26,5 +27,5 @@ pub(crate) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
_ => {
|
||||
super::search::show(app, ui, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,39 +103,6 @@ fn undo_list_matches_the_session_and_undoes_up_to_the_clicked_row() {
|
||||
assert_eq!(h.query_all_by_role(Role::ListBoxOption).count(), 0, "the list closes");
|
||||
}
|
||||
|
||||
/// #3040: clicking a row in the Undo History popover undoes the step and returns keyboard focus
|
||||
/// to the document so typing continues immediately.
|
||||
#[test]
|
||||
fn undo_list_row_returns_focus_to_the_document() {
|
||||
use egui::accesskit::Role;
|
||||
let mut a = new_app();
|
||||
a.run("text.insert", json!({"text": "Hello"})).unwrap();
|
||||
assert_eq!(a.session.undo_history().len(), 1);
|
||||
|
||||
let mut h = harness(a);
|
||||
assert!(h.state().canvas.focused(&h.ctx), "canvas starts focused");
|
||||
|
||||
let arrow = h.get_by_label("Undo History").rect().center();
|
||||
click_at(&mut h, arrow, egui::PointerButton::Primary);
|
||||
assert_eq!(h.query_all_by_role(Role::ListBoxOption).count(), 1, "the arrow opens the Undo list");
|
||||
assert!(!h.state().canvas.focused(&h.ctx), "the open Undo list holds the keyboard");
|
||||
|
||||
let row = h.get_by_role_and_label(Role::ListBoxOption, "Typing").rect().center();
|
||||
click_at(&mut h, row, egui::PointerButton::Primary);
|
||||
assert_eq!(h.query_all_by_role(Role::ListBoxOption).count(), 0, "picking a row closes the Undo list");
|
||||
assert!(h.state().session.undo_history().is_empty(), "the step was undone");
|
||||
assert_eq!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body), "", "the undone text is gone");
|
||||
assert!(h.state().canvas.focused(&h.ctx), "the row click returns focus to the document");
|
||||
|
||||
h.event(egui::Event::Text("!".into()));
|
||||
crate::test_harness::frames(&mut h, 2);
|
||||
assert_eq!(
|
||||
h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body),
|
||||
"!",
|
||||
"typing reaches the document immediately after picking an Undo list row"
|
||||
);
|
||||
}
|
||||
|
||||
/// #1975: the zoom percentage gains and loses digits (9% → 100% → 500%); the controls to its
|
||||
/// left must not shift with it.
|
||||
#[test]
|
||||
@@ -470,96 +437,6 @@ fn status_bar_texts_stop_before_the_controls_in_a_narrow_window() {
|
||||
assert!(painted_on_row_of(&wide, focus).iter().any(|(t, _)| t == "Track Changes: On"), "a wide window shows everything");
|
||||
}
|
||||
|
||||
/// Finds the painted track and knob rects inside a rendered `craft::ui::choice::Switch`.
|
||||
/// `Switch` sets `PARTS = false` and exposes only its `Role::Switch` node and toggled state, so
|
||||
/// the thumb position is read from the unblurred filled shapes painted inside the switch rect.
|
||||
fn switch_track_and_knob(shapes: &[egui::epaint::ClippedShape], switch_rect: egui::Rect) -> (egui::Rect, egui::Rect) {
|
||||
fn filled_rects(shape: &egui::Shape, inside: egui::Rect, out: &mut Vec<egui::Rect>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(children) => children.iter().for_each(|c| filled_rects(c, inside, out)),
|
||||
egui::Shape::Rect(r) if r.blur_width == 0.0 && r.fill != egui::Color32::TRANSPARENT && inside.contains_rect(r.rect) => {
|
||||
out.push(r.rect);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut rects = Vec::new();
|
||||
for clipped in shapes {
|
||||
filled_rects(&clipped.shape, switch_rect.expand(1.0), &mut rects);
|
||||
}
|
||||
let track = rects
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|r| r.width() > r.height())
|
||||
.max_by(|a, b| a.area().total_cmp(&b.area()))
|
||||
.unwrap_or_else(|| panic!("expected painted switch track inside {switch_rect:?}: {rects:?}"));
|
||||
let knob = rects
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|r| track.contains_rect(*r) && r.width() < track.width())
|
||||
.max_by(|a, b| a.area().total_cmp(&b.area()))
|
||||
.unwrap_or_else(|| panic!("expected painted switch knob inside track {track:?}: {rects:?}"));
|
||||
(track, knob)
|
||||
}
|
||||
|
||||
/// The AutoSave switch renders its knob on the right when on and on the left when off in a
|
||||
/// left-to-right interface, and mirrors through `WordApp::root_env()` for an Arabic interface.
|
||||
#[test]
|
||||
fn the_autosave_knob_sits_right_when_on_and_mirrors_right_to_left() {
|
||||
use craft::i18n::Direction;
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
|
||||
struct ResetLang;
|
||||
impl Drop for ResetLang {
|
||||
fn drop(&mut self) {
|
||||
crate::i18n::apply_language(crate::i18n::Lang::EN);
|
||||
}
|
||||
}
|
||||
let _reset = ResetLang;
|
||||
|
||||
let mut a = new_app();
|
||||
a.ui.animations = crate::theme::Animations::Off;
|
||||
a.ui.language = "en".into();
|
||||
// Mark the document as saved here without touching disk (`session.dirty` stays false).
|
||||
let path = std::path::PathBuf::from("draft.docx");
|
||||
a.session.path = Some(path.clone());
|
||||
a.autosave_path = Some(path);
|
||||
|
||||
let mut h = harness(a);
|
||||
// Arabic UI labels draw even when built without `CRAFT_FONTS_DIR` (embedded Arabic faces).
|
||||
h.ctx.set_missing_glyph_policy(egui::MissingGlyphPolicy::Tofu);
|
||||
let mut measure = |lang: crate::i18n::Lang, on: bool| -> (egui::Rect, egui::Rect) {
|
||||
h.state_mut().run("ui.language", json!({"value": lang.code()})).unwrap();
|
||||
h.state_mut().run("file.autosave", json!({"value": on})).unwrap();
|
||||
let want_dir = if lang.rtl() { Direction::Rtl } else { Direction::Ltr };
|
||||
assert_eq!(h.state().root_env().direction, want_dir, "root_env supplies direction for {}", lang.code());
|
||||
assert_eq!(h.state().autosaves(), on);
|
||||
crate::test_harness::frames(&mut h, 4);
|
||||
|
||||
let label = crate::i18n::tr(lang, "AutoSave");
|
||||
let node = h.get_by_role_and_label(Role::Switch, label);
|
||||
assert_eq!(node.accesskit_node().toggled(), Some(if on { Toggled::True } else { Toggled::False }));
|
||||
switch_track_and_knob(&h.output().shapes, node.rect())
|
||||
};
|
||||
|
||||
let (ltr_on_track, ltr_on_knob) = measure(crate::i18n::Lang::EN, true);
|
||||
let (ltr_off_track, ltr_off_knob) = measure(crate::i18n::Lang::EN, false);
|
||||
assert!(ltr_on_knob.center().x > ltr_on_track.center().x, "left to right, on: knob sits right ({ltr_on_knob:?} in {ltr_on_track:?})");
|
||||
assert!(ltr_off_knob.center().x < ltr_off_track.center().x, "left to right, off: knob sits left ({ltr_off_knob:?} in {ltr_off_track:?})");
|
||||
|
||||
let Some(ar) = crate::i18n::Lang::from_code("ar") else {
|
||||
eprintln!("skipped RTL check: built without the craft-i18n Arabic catalog (set CRAFT_I18N_DIR to a checkout)");
|
||||
return;
|
||||
};
|
||||
let (rtl_on_track, rtl_on_knob) = measure(ar, true);
|
||||
let (rtl_off_track, rtl_off_knob) = measure(ar, false);
|
||||
assert!(rtl_on_knob.center().x < rtl_on_track.center().x, "right to left, on: knob sits left ({rtl_on_knob:?} in {rtl_on_track:?})");
|
||||
assert!(rtl_off_knob.center().x > rtl_off_track.center().x, "right to left, off: knob sits right ({rtl_off_knob:?} in {rtl_off_track:?})");
|
||||
assert!(rtl_on_track.center().x > ltr_on_track.center().x, "right to left mirrors the AutoSave switch toward the start (right) edge");
|
||||
assert!(((ltr_on_knob.center().x - ltr_on_track.min.x) - (rtl_on_track.max.x - rtl_on_knob.center().x)).abs() <= 0.5);
|
||||
assert!(((ltr_off_knob.center().x - ltr_off_track.min.x) - (rtl_off_track.max.x - rtl_off_knob.center().x)).abs() <= 0.5);
|
||||
}
|
||||
|
||||
/// #7311: the title bar's Discord community button keeps its solid accent fill and contrasting
|
||||
/// `on_strong` icon/label in both wide (pill with label) and narrow (compact icon-only) windows,
|
||||
/// across Light and Dark themes, and still dispatches `ui.discord` when clicked.
|
||||
|
||||
@@ -200,11 +200,6 @@ fn undo_arrow(app: &mut WordApp, ui: &mut Ui, enabled: bool) -> egui::Rect {
|
||||
app.chrome.undo_mark = if open { mark } else { UndoMark::default() };
|
||||
if let Some(count) = picked {
|
||||
let _ = app.run("edit.undoTo", json!({"count": count}));
|
||||
// Picking a row closes the Undo History popover on its foreground layer; return keyboard
|
||||
// focus to the document both now and after the pass's overlay-close focus hook (#3040).
|
||||
app.canvas.focus_page(ui.ctx());
|
||||
app.canvas.focus_page_after_pass();
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
out.response.rect
|
||||
}
|
||||
|
||||
@@ -147,14 +147,10 @@ pub(crate) fn open(app: &mut WordApp, _name: &str, _params: &Value, parent: Opti
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use craft::keymap::{Binding, CommandRef};
|
||||
use craft::ui::dialog::dialog_id;
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::{By, NodeT, Queryable};
|
||||
use craft::keymap::Binding;
|
||||
use serde_json::json;
|
||||
use wordcraft_engine::Session;
|
||||
|
||||
use super::KEY;
|
||||
use crate::{Services, WordApp};
|
||||
|
||||
fn app() -> WordApp {
|
||||
@@ -185,66 +181,4 @@ mod tests {
|
||||
assert_eq!(chords(&b, "format.bold"), Some(Vec::new()));
|
||||
assert_eq!(chords(&b, "format.italic"), Some(italic));
|
||||
}
|
||||
|
||||
/// #1905: a command with no shortcuts shows `None` in the Current shortcuts list, whereas a
|
||||
/// command with a built-in shortcut shows its binding instead of `None`.
|
||||
#[test]
|
||||
fn keys_list_without_shortcuts_says_none() {
|
||||
let mut a = app();
|
||||
super::open(&mut a, KEY, &json!({}), None).expect("dialog opens");
|
||||
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
|
||||
h.run_steps(2);
|
||||
|
||||
let keymap = craft::ui::runtime::commands::keymap(&h.ctx).expect("command board installs a keymap");
|
||||
let unbound_id = h
|
||||
.state()
|
||||
.session
|
||||
.registry
|
||||
.all()
|
||||
.iter()
|
||||
.find(|spec| {
|
||||
let cmd = CommandRef::new(spec.id);
|
||||
keymap.bindable(&cmd).is_some() && keymap.bindings(&cmd).is_empty()
|
||||
})
|
||||
.map(|spec| spec.id.to_string())
|
||||
.expect("a bindable command with no built-in shortcut");
|
||||
assert!(!keymap.bindings(&CommandRef::new("format.bold")).is_empty(), "format.bold has a built-in shortcut");
|
||||
|
||||
let dlg_id = dialog_id(KEY);
|
||||
let ctx = h.ctx.clone();
|
||||
let select = |h: &mut egui_kittest::Harness<'_, WordApp>, id: &str| {
|
||||
h.state_mut().dialog_host.set_json_field(&ctx, dlg_id, "command", json!(id)).expect("command field accepts id");
|
||||
h.run_steps(3);
|
||||
let selected = h
|
||||
.state()
|
||||
.dialog_host
|
||||
.open_dialogs()
|
||||
.into_iter()
|
||||
.find(|d| d.id == dlg_id)
|
||||
.and_then(|d| d.fields)
|
||||
.and_then(|fields| fields.get("command").and_then(|v| v.as_str()).map(str::to_owned));
|
||||
assert_eq!(selected.as_deref(), Some(id), "dialog selected {id}");
|
||||
};
|
||||
let keys_list_labels = |h: &egui_kittest::Harness<'_, WordApp>| -> Vec<String> {
|
||||
let list = h.get_by_role_and_label(Role::List, "Current shortcuts:");
|
||||
let list_id = list.accesskit_node().id();
|
||||
let rect = list.rect();
|
||||
h.query_all(By::new())
|
||||
.filter(|n| n.accesskit_node().id() != list_id && !n.accesskit_node().is_hidden() && n.accesskit_node().bounding_box().is_some())
|
||||
.filter(|n| rect.contains_rect(n.rect()))
|
||||
.filter_map(|n| n.accesskit_node().label())
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Positive contrast: a bound command lists its shortcut and does not show the empty `None` placeholder.
|
||||
select(&mut h, "format.bold");
|
||||
let bound_labels = keys_list_labels(&h);
|
||||
assert!(!bound_labels.is_empty(), "bound command lists its shortcut");
|
||||
assert!(!bound_labels.iter().any(|t| t == "None"), "bound command keys list does not say None: {bound_labels:?}");
|
||||
|
||||
// Target behavior: an unbound command shows `None` inside the Current shortcuts list.
|
||||
select(&mut h, &unbound_id);
|
||||
let unbound_labels = keys_list_labels(&h);
|
||||
assert!(unbound_labels.iter().any(|t| t == "None"), "empty keys list says None: {unbound_labels:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,83 +950,6 @@ fn opened_paper(h: &mut egui_kittest::Harness<'_, WordApp>) -> (f32, f32) {
|
||||
paper
|
||||
}
|
||||
|
||||
/// #1433: in a right-to-left interface, typing a number wider than the field's column into a
|
||||
/// margin spin button keeps the dialog the same width; clicking the visible end of the blurred
|
||||
/// field enters editing again, and entering a normal value restores the field.
|
||||
#[test]
|
||||
fn page_setup_rtl_large_margin_can_be_edited_again_after_blur() {
|
||||
use egui::accesskit::Role;
|
||||
let mut app = app_with("Page");
|
||||
app.run("ui.dialog", json!({"name": "pageSetup"})).unwrap();
|
||||
let ar = crate::i18n::fixture_lang("ar", "\tMargins\tMargins\n");
|
||||
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|
||||
move |ui, app: &mut WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
// Draw the actual dialog in a fixture language even without embedded catalogs.
|
||||
crate::i18n::apply_language(ar);
|
||||
ctx.global_style_mut(|s| s.right_to_left = true);
|
||||
assert!(crate::i18n::current().rtl() && ctx.global_style().right_to_left);
|
||||
craft::ui::runtime::env::with_env(ui, |o| o.direction = Some(craft::i18n::Direction::Rtl), |ui| app.ui(ui));
|
||||
ctx.global_style_mut(|s| s.right_to_left = false);
|
||||
crate::i18n::apply_language(crate::i18n::Lang::EN);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(4);
|
||||
let initial = h.get_by_role_and_label(Role::SpinButton, "Bottom").rect();
|
||||
assert!(h.get_by_role_and_label(Role::SpinButton, "Top").rect().center().x > initial.center().x, "the form is mirrored");
|
||||
let window = |h: &egui_kittest::Harness<'_, WordApp>| h.get_by_role_and_label(Role::Dialog, "Page Setup").rect();
|
||||
let before = window(&h).width();
|
||||
let id = id_of(h.state(), "pageSetup");
|
||||
let initial_bottom = h.state().dialog_host.get_by_id::<PageSetupHost>(id).unwrap().setup.margins.bottom;
|
||||
assert!(initial_bottom < craft::pages::setup::MAX_PAGE_SIDE, "initial margin starts below the upper bound: {initial_bottom}");
|
||||
h.get_by_role_and_label(Role::SpinButton, "Bottom").click();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Paste(format!("1{}", "0".repeat(36))));
|
||||
h.run_steps(3);
|
||||
let id = id_of(h.state(), "pageSetup");
|
||||
let value = h.state().dialog_host.get_by_id::<PageSetupHost>(id).unwrap().setup.margins.bottom;
|
||||
assert!(
|
||||
value > initial_bottom && (value - craft::pages::setup::MAX_PAGE_SIDE).abs() < 1e-3,
|
||||
"oversized margin paste should be accepted and clamped to MAX_PAGE_SIDE: got {value}"
|
||||
);
|
||||
// While the 37-digit text is in the field, the dialog does not blow up to the typed text width.
|
||||
assert!(window(&h).width() <= before + 15.0);
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
let id = id_of(h.state(), "pageSetup");
|
||||
assert_eq!(h.state().dialog_host.get_by_id::<PageSetupHost>(id).unwrap().setup.margins.bottom, value);
|
||||
let field = h.get_by_role_and_label(Role::SpinButton, "Bottom");
|
||||
assert!(!field.is_focused());
|
||||
let wide = field.rect();
|
||||
let visible = wide.intersect(initial).intersect(window(&h));
|
||||
assert!(visible.is_positive());
|
||||
// The inline notice "Margins do not fit" may add a few points, but the dialog does not blow up to the typed text width.
|
||||
assert!(window(&h).width() <= before + 15.0);
|
||||
// The AccessKit bounds include clipped text: click the visible part, not their centre.
|
||||
let pos = visible.center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
for pressed in [true, false] {
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE });
|
||||
}
|
||||
h.run_steps(3);
|
||||
assert!(h.get_by_role_and_label(Role::SpinButton, "Bottom").is_focused(), "the visible field enters editing");
|
||||
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
h.event(egui::Event::Paste("2".into()));
|
||||
h.run_steps(3);
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
let id = id_of(h.state(), "pageSetup");
|
||||
let bottom = h.state().dialog_host.get_by_id::<PageSetupHost>(id).unwrap().setup.margins.bottom;
|
||||
let unit = crate::options::unit_kind(h.state().session.units());
|
||||
let expected =
|
||||
unit.to_pixels(2.0, 0.0, craft::ui::runtime::env::UnitKind::POINTS_PER_INCH, craft::ui::runtime::env::UnitKind::POINTS_PER_INCH).unwrap();
|
||||
assert!((bottom - expected).abs() < 1e-3, "the field accepts a normal value again: got {bottom}, expected {expected}");
|
||||
assert!(window(&h).width() <= before + 2.0);
|
||||
}
|
||||
|
||||
/// #1433: Page Setup's Paper size shows the named size the section has, in either
|
||||
/// orientation, and Custom size (None) for anything else.
|
||||
#[test]
|
||||
@@ -1751,54 +1674,6 @@ fn word_count_shows_label_and_count_on_a_line_over_close_and_cancel() {
|
||||
assert!(!is_open(h.state(), "wordCount"), "Cancel closes Word Count");
|
||||
}
|
||||
|
||||
/// #1885: the close control is at the title bar's right end; a click in the close box
|
||||
/// closes the dialog; one just under the title bar leaves it open; a drag that starts on the box
|
||||
/// doesn't move the dialog.
|
||||
#[test]
|
||||
fn the_title_bar_close_box_is_the_whole_corner() {
|
||||
use egui::accesskit::Role;
|
||||
fn press(h: &mut egui_kittest::Harness<'_, WordApp>, from: egui::Pos2, to: egui::Pos2) {
|
||||
let button =
|
||||
|pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
|
||||
h.event(egui::Event::PointerMoved(from));
|
||||
h.step();
|
||||
h.event(button(from, true));
|
||||
h.step();
|
||||
if to != from {
|
||||
h.event(egui::Event::PointerMoved(to));
|
||||
h.step();
|
||||
}
|
||||
h.event(button(to, false));
|
||||
for _ in 0..4 {
|
||||
h.step();
|
||||
}
|
||||
}
|
||||
let mut app = app_with("Some text");
|
||||
super::open(&mut app, "wordCount", &json!({})).expect("word count opens");
|
||||
let mut h = app_harness(app);
|
||||
h.run_steps(4);
|
||||
assert!(is_open(h.state(), "wordCount"), "dialog is open");
|
||||
let before = h.get_by_role_and_label(Role::Dialog, "Word Count").rect();
|
||||
let closes: Vec<_> = h.query_all_by_role_and_label(Role::Button, "Close").filter(|n| !n.accesskit_node().is_hidden()).collect();
|
||||
let close_box = closes.into_iter().min_by(|a, b| a.rect().min.y.total_cmp(&b.rect().min.y)).expect("title bar close");
|
||||
let bx = close_box.rect();
|
||||
assert!((bx.top() - before.top()).abs() <= 10.0, "box {bx:?} is in the title bar area of {before:?}");
|
||||
assert!(
|
||||
bx.right() <= before.right() && before.right() - bx.right() <= 10.0 && bx.left() > before.center().x,
|
||||
"close button sits at the right: {bx:?} in {before:?}"
|
||||
);
|
||||
let under = egui::pos2(bx.center().x, bx.bottom() + 4.0);
|
||||
press(&mut h, under, under);
|
||||
assert!(is_open(h.state(), "wordCount"), "a click under the title bar keeps the dialog");
|
||||
let at = bx.center();
|
||||
press(&mut h, at, at + egui::vec2(-150.0, 90.0));
|
||||
assert!(is_open(h.state(), "wordCount"), "a drag from the box isn't a click");
|
||||
let after = h.get_by_role_and_label(Role::Dialog, "Word Count").rect();
|
||||
assert!((after.min - before.min).length() <= 1.0, "the box isn't a drag handle: {before:?} -> {after:?}");
|
||||
press(&mut h, at, at);
|
||||
assert!(!is_open(h.state(), "wordCount"), "a click in the box closes the dialog");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Font layout
|
||||
|
||||
/// The Font dialog stands as the old one did: the Effects check boxes two to a line (Bold beside Italic, Underline
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::behavior::overlay::MinWidth;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::{KeytipControl, Keytips, RibbonOutput};
|
||||
use craft::ui::contract::Bind;
|
||||
@@ -34,6 +33,12 @@ pub(crate) fn backstage_region() -> egui::Id {
|
||||
egui::Id::unique("wc_keytips_backstage_region")
|
||||
}
|
||||
|
||||
/// The key of the inspected region the screen bar (Focus, Full Screen View) records; the legacy hint hangs from
|
||||
/// its first element when no ribbon shows.
|
||||
pub(crate) fn screen_bar_region() -> egui::Id {
|
||||
egui::Id::unique("wc_keytips_screen_bar_region")
|
||||
}
|
||||
|
||||
/// Word's tab letters, as Word for Windows shows them after Alt (File F, Design G, References S,
|
||||
/// Review R, View W, Help Y). File opens the Backstage.
|
||||
const TAB_LETTERS: [(&str, &str); 11] = [
|
||||
@@ -412,8 +417,8 @@ fn backstage_rows() -> Vec<Row> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Shows the keytips after the shell and the regions they place badges on, and acts on what the keys chose.
|
||||
pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>, screen_bar: Option<Rect>) {
|
||||
/// Shows the keytips after the ribbon and the regions they place badges on, and acts on what the keys chose.
|
||||
pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>) {
|
||||
let ctx = ui.ctx().clone();
|
||||
// Alt during an object drag is part of the drag (Alt moves an object freely), not a keytip tap.
|
||||
// PLAN: `CanvasState::object_gesture` is canvas-w9's (cv.A10).
|
||||
@@ -466,6 +471,7 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
|
||||
}
|
||||
if let Some(pending) = &out.pending {
|
||||
// With no ribbon showing (Focus, Full Screen View) the hint hangs under the screen bar.
|
||||
let screen_bar = inspect::recorded(&ctx, screen_bar_region()).and_then(|r| r.rect_in(&ctx, 0, ui.layer_id()));
|
||||
if let Some(anchor) = ribbon.tabs.or(screen_bar) {
|
||||
legacy_hint(ui, pending, anchor);
|
||||
}
|
||||
@@ -477,11 +483,9 @@ fn legacy_hint(ui: &mut Ui, pending: &str, anchor: Rect) {
|
||||
let keys: Vec<String> = pending.chars().map(String::from).collect();
|
||||
let text = crate::i18n::fmt(tl!("Old menu keys: Alt, {keys}. Keep typing, or press Esc to cancel."), &[("keys", &keys.join(", "))]);
|
||||
let mut open = true;
|
||||
Popover::new(tl!("Old menu keys"), Bind::bound(&mut open))
|
||||
.overlay(|overlay| overlay.anchor(Anchor::Rect(anchor)).min_width(MinWidth::None))
|
||||
.show(ui, |ui, _| {
|
||||
Text::new(text.clone()).show(ui);
|
||||
});
|
||||
Popover::new(tl!("Old menu keys"), Bind::bound(&mut open)).overlay(|overlay| overlay.anchor(Anchor::Rect(anchor))).show(ui, |ui, _| {
|
||||
Text::new(text.clone()).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -96,88 +96,6 @@ fn legacy_menu_keys_stay_off_the_ribbon_letters_and_all_resolve() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #1697 review: with no ribbon showing (Focus, Full Screen View) no tab rects are recorded,
|
||||
/// so the legacy hint hangs under the slim screen bar at the top of the window instead of not
|
||||
/// showing; with the ribbon showing (normal window or dropped ribbon in Focus) it hangs under
|
||||
/// the tab row.
|
||||
#[test]
|
||||
fn the_legacy_hint_hangs_under_the_slim_bar_without_a_ribbon() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
if cfg!(target_os = "macos") {
|
||||
return;
|
||||
}
|
||||
let trigger_legacy_v = |h: &mut egui_kittest::Harness<'static, WordApp>| {
|
||||
h.input_mut().events.push(key_event(egui::Key::F10, true, egui::Modifiers::NONE));
|
||||
crate::test_harness::frame(h);
|
||||
h.input_mut().events.extend([key_event(egui::Key::V, true, egui::Modifiers::NONE), egui::Event::Text("v".into())]);
|
||||
crate::test_harness::frames(h, 2);
|
||||
};
|
||||
let cancel = |h: &mut egui_kittest::Harness<'static, WordApp>| {
|
||||
h.input_mut().events.push(key_event(egui::Key::Escape, true, egui::Modifiers::NONE));
|
||||
crate::test_harness::frames(h, 2);
|
||||
};
|
||||
|
||||
let mut h = harness(app());
|
||||
let home_tab = h.get_by_label("Home").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V enters legacy keytip wait with the ribbon showing");
|
||||
assert!(h.query_by_label("Old menu keys: Alt, V. Keep typing, or press Esc to cancel.").is_some(), "hint displays pending Alt, V sequence");
|
||||
let ribbon_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(ribbon_hint.top() >= home_tab.bottom() - 1.0, "legacy hint {ribbon_hint:?} hangs under the ribbon tab row {home_tab:?}");
|
||||
cancel(&mut h);
|
||||
assert!(!h.state().keytips_active, "Escape ends legacy keytips");
|
||||
assert!(h.query_by_role_and_label(Role::Dialog, "Old menu keys").is_none(), "hint closes on Escape");
|
||||
|
||||
// Focus hides the ribbon and shows the slim screen bar at the top.
|
||||
h.state_mut().run("view.focus", serde_json::json!({})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(h.query_by_label("Insert").is_none(), "Focus hides the ribbon");
|
||||
let focus_bar = h.get_by_label("Show the ribbon").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V activates legacy keytips in Focus mode");
|
||||
let focus_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
focus_hint.top() >= focus_bar.bottom() - 1.0 && focus_hint.top() < ribbon_hint.top(),
|
||||
"Focus legacy hint {focus_hint:?} hangs under the slim screen bar {focus_bar:?} (above ribbon hint {ribbon_hint:?})"
|
||||
);
|
||||
assert!(focus_hint.width() < 720.0, "Focus hint {focus_hint:?} sizes to its content rather than stretching across the screen bar");
|
||||
cancel(&mut h);
|
||||
assert!(!h.state().keytips_active, "Escape ends legacy keytips in Focus");
|
||||
assert!(h.state().session.view.focus_mode, "Escape cancelling legacy keytips keeps Focus active");
|
||||
|
||||
// When Focus drops the ribbon down, the tab row wins over the screen bar.
|
||||
h.state_mut().run("ui.focusRibbon", serde_json::json!({"value": true})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
let dropped_tab = h.get_by_label("Home").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
let dropped_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
dropped_hint.top() >= dropped_tab.bottom() - 1.0 && dropped_hint.top() > focus_hint.top(),
|
||||
"dropped-ribbon hint {dropped_hint:?} hangs under the dropped tab row {dropped_tab:?}"
|
||||
);
|
||||
cancel(&mut h);
|
||||
|
||||
// Full Screen View hides the ribbon and shows the slim screen bar with Search.
|
||||
h.state_mut().run("view.focus", serde_json::json!({})).unwrap();
|
||||
h.state_mut().run("view.fullScreenView", serde_json::json!({})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(h.query_by_label("Insert").is_none(), "Full Screen View hides the ribbon");
|
||||
let search_bar = h.get_by_label("Search commands and help").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V activates legacy keytips in Full Screen View");
|
||||
let fs_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
fs_hint.top() >= search_bar.bottom() - 1.0 && fs_hint.top() < ribbon_hint.top(),
|
||||
"Full Screen View legacy hint {fs_hint:?} hangs under the slim screen bar {search_bar:?} (above ribbon hint {ribbon_hint:?})"
|
||||
);
|
||||
assert!(fs_hint.width() < 720.0, "Full Screen View hint {fs_hint:?} sizes to its content rather than stretching across the screen bar");
|
||||
h.input_mut().events.extend([key_event(egui::Key::U, true, egui::Modifiers::NONE), egui::Event::Text("u".into())]);
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(!h.state().session.view.full_screen_view, "Alt/F10, V, U leaves Full Screen View");
|
||||
assert!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).is_empty(), "no letter typed into the document");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qat_keytips_follow_custom_order_and_skip_disabled_commands() {
|
||||
let mut a = app();
|
||||
|
||||
@@ -68,7 +68,7 @@ pub use tabs::{
|
||||
use view::{outlining, view};
|
||||
|
||||
/// What a pass with no ribbon reports.
|
||||
pub(crate) fn no_ribbon() -> RibbonOutput<String> {
|
||||
fn no_ribbon() -> RibbonOutput<String> {
|
||||
// PLAN: assumed `RibbonOutput::tab_ids` (S-L361) has a `Default` value; the field replaces `menu`.
|
||||
RibbonOutput { shown: None, picked: None, controls: None, tabs: None, tab_ids: Default::default() }
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use craft::behavior::{ColumnWidth, IconId};
|
||||
use craft::behavior::IconId;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::ribbon::{RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button, IconButton, ToggleButton};
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::layout::{GridFit, empty_cell};
|
||||
use craft::ui::layout_components::{Grid, Row, Stack};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::menu::MenuItem;
|
||||
use craft::ui::text::NumberField;
|
||||
|
||||
@@ -18,33 +17,25 @@ use crate::undo_marks::apply_edits;
|
||||
/// The row height and column width a Cell Size field accepts, in points (0.02 to 22 inches).
|
||||
const CELL_SIZE_RANGE: std::ops::RangeInclusive<f64> = 1.44..=1584.0;
|
||||
|
||||
/// Two checkbox columns separated by two empty gutter cells: `Grid::gap` sets both axes, so the
|
||||
/// empty gutter widens the column gap to `3 * Gap::Tight` (at least `Gap::Stack`) while keeping
|
||||
/// rows `Gap::Tight` apart inside the ribbon group.
|
||||
const TABLE_STYLE_OPTION_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content; 4];
|
||||
|
||||
pub(super) fn table_design(row: &mut RibbonRow<'_>, app: &mut WordApp) {
|
||||
let look = app.session.sel.focus.path.cell().and_then(|(tp, _, _)| app.session.doc.table(app.session.sel.focus.story, &tp).map(|t| t.props.look));
|
||||
if let Some(l) = look {
|
||||
// Row-major pairs, so Tab runs Header Row, First Column, Total Row, Last Column, Banded Rows, Banded Columns.
|
||||
// Three rows of two, so Tab runs Header Row, First Column, Total Row, Last Column, Banded Rows, Banded Columns.
|
||||
let options = [
|
||||
("Header Row", "headerRow", l.header_row),
|
||||
("First Column", "firstColumn", l.first_column),
|
||||
("Total Row", "totalRow", l.total_row),
|
||||
("Last Column", "lastColumn", l.last_column),
|
||||
("Banded Rows", "bandedRows", l.banded_rows),
|
||||
("Banded Columns", "bandedColumns", l.banded_columns),
|
||||
[("Header Row", "headerRow", l.header_row), ("First Column", "firstColumn", l.first_column)],
|
||||
[("Total Row", "totalRow", l.total_row), ("Last Column", "lastColumn", l.last_column)],
|
||||
[("Banded Rows", "bandedRows", l.banded_rows), ("Banded Columns", "bandedColumns", l.banded_columns)],
|
||||
];
|
||||
row.group(RibbonGroup::new("tableStyleOptions", tl!("Table Style Options").to_string(), IconId::new("tableStyleOptions").into()), |ui| {
|
||||
Grid::new(&TABLE_STYLE_OPTION_COLUMNS).fit(GridFit::Fixed).gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for (index, (label, key, value)) in options.into_iter().enumerate() {
|
||||
if index % 2 == 1 {
|
||||
empty_cell(ui);
|
||||
empty_cell(ui);
|
||||
}
|
||||
let out = Checkbox::new(Bind::given(value)).label(tl!(label).to_string()).show(ui);
|
||||
apply_edits(app, out.events, |app, v| {
|
||||
let _ = app.run("table.look", json!({ key: v }));
|
||||
Stack::new().gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for line in options {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
for (label, key, value) in line {
|
||||
let out = Checkbox::new(Bind::given(value)).label(tl!(label).to_string()).show(ui);
|
||||
apply_edits(app, out.events, |app, v| {
|
||||
let _ = app.run("table.look", json!({ key: v }));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -994,66 +994,3 @@ fn decorative_text_dropdown_renders_compact_wordart_tiles() {
|
||||
rect.height()
|
||||
);
|
||||
}
|
||||
|
||||
/// #7691: Table Design › Table Style Options aligns its six checkboxes in two columns with a gap
|
||||
/// between them and keeps all three rows above the group caption.
|
||||
#[test]
|
||||
fn table_style_options_align_in_two_columns() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
app.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
let h = tab_harness(app, "Table Design");
|
||||
let rect = |label: &str| h.get_by_role_and_label(Role::CheckBox, label).rect();
|
||||
let header = rect("Header Row");
|
||||
let first_col = rect("First Column");
|
||||
let total = rect("Total Row");
|
||||
let last_col = rect("Last Column");
|
||||
let banded = rect("Banded Rows");
|
||||
let banded_col = rect("Banded Columns");
|
||||
// Left column checkboxes share one left edge, and right column checkboxes share another.
|
||||
assert!(
|
||||
(header.left() - total.left()).abs() < 0.5 && (header.left() - banded.left()).abs() < 0.5,
|
||||
"left column misaligned: {header:?}, {total:?}, {banded:?}"
|
||||
);
|
||||
assert!(
|
||||
(first_col.left() - last_col.left()).abs() < 0.5 && (first_col.left() - banded_col.left()).abs() < 0.5,
|
||||
"right column misaligned: {first_col:?}, {last_col:?}, {banded_col:?}"
|
||||
);
|
||||
// Each row's pair shares the same top edge and stacks vertically with tight spacing.
|
||||
let env = craft::ui::runtime::env::Env::of_root(&h.ctx);
|
||||
let tight_gap = env.tokens.space.gap.tight;
|
||||
let min_col_gap = env.tokens.space.gap.stack;
|
||||
assert!((header.top() - first_col.top()).abs() < 0.5, "row 1 misaligned: {header:?}, {first_col:?}");
|
||||
assert!((total.top() - last_col.top()).abs() < 0.5, "row 2 misaligned: {total:?}, {last_col:?}");
|
||||
assert!((banded.top() - banded_col.top()).abs() < 0.5, "row 3 misaligned: {banded:?}, {banded_col:?}");
|
||||
assert!(header.bottom() <= total.top() && total.bottom() <= banded.top(), "rows overlap: {header:?}, {total:?}, {banded:?}");
|
||||
let row_gap_1 = total.top() - header.bottom();
|
||||
let row_gap_2 = banded.top() - total.bottom();
|
||||
assert!(
|
||||
(row_gap_1 - tight_gap).abs() <= 0.5 && (row_gap_2 - tight_gap).abs() <= 0.5,
|
||||
"rows should remain Gap::Tight ({tight_gap} pt) apart, got {row_gap_1} and {row_gap_2}"
|
||||
);
|
||||
// A horizontal gap at least `space.gap.stack` separates the widest left-column label from the second column.
|
||||
let text_rect = |label: &str| {
|
||||
h.output()
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == label => Some(egui::Rect::from_min_size(t.pos, t.galley.size())),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| panic!("painted text for {label:?}"))
|
||||
};
|
||||
let left_label_max_right =
|
||||
["Header Row", "Total Row", "Banded Rows"].into_iter().map(|label| text_rect(label).right()).fold(f32::NEG_INFINITY, f32::max);
|
||||
let col_gap = first_col.left() - left_label_max_right;
|
||||
assert!(
|
||||
col_gap >= min_col_gap,
|
||||
"column gap between widest left label and right column too narrow: got {col_gap:.2} pt, expected >= {min_col_gap:.2} pt (left_label_max_right={left_label_max_right}, first_col={first_col:?})"
|
||||
);
|
||||
// All three rows stay above the group's caption.
|
||||
let caption = text_rect("Table Style Options");
|
||||
assert!(banded.bottom() <= caption.top(), "checkboxes collide with group caption: {banded:?} vs {caption:?}");
|
||||
}
|
||||
|
||||
@@ -850,13 +850,11 @@ fn web_layout_fills_the_window_width() {
|
||||
frame(&mut a, 1400.0, tick);
|
||||
assert_eq!(a.session.view.web_width, wide, "no change without a resize");
|
||||
let page = first_page(&a).unwrap();
|
||||
// The page view keeps its `PageSpacing::side` gutter clear on both sides; the page fills the rest of the window,
|
||||
// so it uses the full room up to the PageView gutter rather than the wider rail width, without overflowing.
|
||||
let gutter = a.canvas.page_side.expect("page view records its side gutter");
|
||||
let rail = craft::ui::runtime::env::Env::of_root(&ctx).tokens.size.rail.width;
|
||||
assert!(gutter < rail, "Productivity PageView gutter ({gutter}) is narrower than the rail width ({rail})");
|
||||
assert!((page.left() - gutter).abs() <= 4.0, "page starts at the left gutter ({gutter}): {page:?}");
|
||||
assert!(page.right() >= 1400.0 - gutter - 4.0 && page.right() <= 1400.0 - gutter + 4.0, "page fills to the right gutter ({gutter}): {page:?}");
|
||||
// The page view keeps a side gutter clear (the rail width, S-L: the framework's page spacing); the page fills the
|
||||
// rest of the window, so it neither overflows to the right nor leaves more than the gutter on the left.
|
||||
let gutter = 40.0; // the `size.rail.width` token the page view keeps clear
|
||||
assert!(page.left() <= gutter + 4.0, "page starts at the left gutter: {page:?}");
|
||||
assert!(page.right() <= 1400.0 - gutter + 4.0, "page ends before the right gutter: {page:?}");
|
||||
// A window drag: the width holds while the size keeps changing, then follows once it settles.
|
||||
for w in [1300.0, 1100.0, 900.0, 700.0, 500.0] {
|
||||
frame(&mut a, w, tick);
|
||||
@@ -889,23 +887,6 @@ fn web_layout_fills_the_window_width() {
|
||||
frame(&mut a, 1400.0, tick);
|
||||
}
|
||||
assert_eq!(lines(&mut a), print_lines, "Print Layout is unchanged");
|
||||
|
||||
// Entering Web Layout before any prior PageView pass still settles to PageView's side gutter.
|
||||
let fresh_ctx = crate::test_harness::context();
|
||||
let mut fresh = app();
|
||||
fresh.run("view.webLayout", json!({})).unwrap();
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 740.0));
|
||||
for step in 1..=2 {
|
||||
let input = egui::RawInput { events: vec![], time: Some(step as f64 * tick), screen_rect: Some(screen), ..Default::default() };
|
||||
crate::test_harness::pass(&fresh_ctx, &mut fresh, input);
|
||||
}
|
||||
let fresh_gutter = fresh.canvas.page_side.expect("page view records its side gutter on first Web Layout pass");
|
||||
let fresh_page = first_page(&fresh).unwrap();
|
||||
assert!((fresh_page.left() - fresh_gutter).abs() <= 4.0, "fresh Web Layout starts at the left gutter ({fresh_gutter}): {fresh_page:?}");
|
||||
assert!(
|
||||
fresh_page.right() >= 1400.0 - fresh_gutter - 4.0 && fresh_page.right() <= 1400.0 - fresh_gutter + 4.0,
|
||||
"fresh Web Layout fills to the right gutter ({fresh_gutter}): {fresh_page:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// #688: dragging a selection past the viewport's edge scrolls the view toward the pointer, and the
|
||||
|
||||
Reference in New Issue
Block a user