Compare commits

...
Author SHA1 Message Date
f83d554322 Pictures: an inserted or pasted picture fits the table cell, column or section it goes in (#5428) (#6903)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: D13GOOOO <106814760+D13GOOOO@users.noreply.github.com>
2026-11-27 10:07:07 +00:00
Martin BallandClaude Opus 5.5 0f4e80aedd #7165: Symbol drop-down has compact cells, and hover names the character (#7173)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 10:07:01 +00:00
Martin BallandClaude Opus 5.5 bab08b77e1 #7841: dark-mode interface text gets the lighter Gamma(0.8) curve again (#7867)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 10:06:54 +00:00
Martin BallandClaude Opus 5.5 2b407facd0 #7824: a disabled table menu button keeps its menu shut under read-only protection (#7871)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 10:02:47 +00:00
Lucas Batista Vargas b322c3d816 test(keys): restore an_unrelated_keys_modifiers_do_not_steer_a_later_paste test (#7317) (#7602) 2026-11-27 01:01:23 +00:00
Lucas Batista Vargas 64e297ca57 test(ui-egui): restore shortcuts_run_after_a_pane_resize test (#1756) (#7317) (#7579) 2026-11-27 00:59:55 +00:00
Martin BallandClaude Opus 5.5 ca8feb71aa test(engine): Copy with a bare caret beside an object is disabled, like Cut (#7892)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 00:47:48 +00:00
Lucas Batista Vargas 73f42fd607 test(ui-egui): restore drawn_buttons_fade_in_on_hover_and_darken_while_pressed test (#7317, #305) (#7580) 2026-11-27 00:25:44 +00:00
Lucas Batista Vargas ff11882e9d test(keys): restore alt_shortcuts_work_without_the_canvas_focused test (#7317) (#7583) 2026-11-27 00:25:38 +00:00
14 changed files with 641 additions and 96 deletions
+2
View File
@@ -172,6 +172,7 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
- 2026-11-15: Get the Missing Fonts. A document opened from a file that is missing fonts their publisher gives away (Microsoft's Aptos family, the default in recent Word documents; Cascadia Code and Mono) brings up a box naming each font, the font drawn instead, the publisher's download page and how to install the download, with Don't show this again. `font.missing` reports the same page, so agents get it without the box. WordCraft links to the page only; it downloads and bundles nothing.
- 2026-10-30: Track Changes: a list item deleted whole, text and paragraph mark, shows its number as deleted text, in the deletion's colour and with its mark (struck through by default, or caret, #, bold, italic, underline), and hides it with No Markup or when Track Changes Options hide deletions (#4828). Readiness unchanged.
- 2026-11-03: A picture inserted or pasted in a table cell fits the cell, as in Word, instead of running out of it; in text columns it fits the column, in a section with other margins that section's width (#5428).
- 2026-11-09: Touchpad and mouse-wheel scroll speed settings (#6146): scales Wayland touchpad point input by default (4×) so two-finger scrolling matches desktop speed rather than crawling 1:1, and scales mouse wheel line distance; File › Options › Advanced › Scrolling; commands ui.scrollSpeed and ui.touchpadScrollSpeed.
- 2026-11-15: Layout: from Word 2013's layout (compatibility mode 15), balancing the columns before a continuous break keeps the last two, three or five lines of a paragraph that began on the page before together, keeps a two- or three-line paragraph that begins the last page whole, and holds a paragraph with keep lines together (or keep with next) whole in the first column when the strict rules fit. Synthetic tests also cover a footnote and a float (#6821); mode 14 splits them as before. Readiness estimates unchanged.
@@ -993,6 +994,7 @@ MATH glyphs that reference the same construction now share its immutable variant
| 2026-11-12 | trivial | Validator: exclude every glossary-typed part from main traversal and fallback assignment; multiple content-type fallback candidates are ambiguous, with no selected anchor (#5875). Synthetic controls; no parity estimate changed. |
| 2026-11-12 | trivial | Validator: mixed Transitional/Strict entry points to the same target skip document checks with coverage in either order (#5875); distinct competing roots retain ambiguity treatment without evaluating the profile gate. No parity estimate changed. |
| 2026-11-12 | trivial | Validator: competing official role targets produce coverage and suppress dependent findings; both-order, repeated-target, malformed-source and owner-isolation controls (#5875). No parity estimate changed. |
| 2026-11-03 | trivial | Progress log: a picture inserted or pasted in a table cell fits the cell (#5428) |
| 2026-11-10 | trivial | Save As on Linux: the desktop portal's Save dialog reports the file type picked, updating the extension so saving as PDF writes a .pdf (#6180) |
| 2026-11-08 | trivial | Progress log: freestanding custom.dic dictionary file support in File › Options › Proofing (#5840) |
| 2026-11-08 | trivial | Progress log: XML line ends in text normalised (#5897) |
+2 -2
View File
@@ -117,9 +117,9 @@ fn place_picture(s: &mut Session, bytes: Vec<u8>, width: Option<f32>, alt: &str)
None => return Err(CmdError::Failed("not a supported image (PNG, JPEG, GIF, WebP, BMP, TIFF, WMF, EMF)".into())),
},
};
// Fitted to the room where it goes: the table cell, the column, its own section (#5428).
let max_w = s.room_at(&s.sel.ordered().0);
let key = s.doc.add_media(bytes, ext);
// Fitted to the text width.
let max_w = s.doc.sections().first().map(|(_, sp)| sp.text_width()).unwrap_or(468.0);
let (mut w, mut h) = (natural_w, natural_h);
if let Some(want) = width {
// At most 22 inches, as for icons: a huge width made the height of a tall picture infinite.
+16 -3
View File
@@ -499,10 +499,23 @@ pub(crate) fn unlink_sections(blocks: &mut [Block]) {
/// lists and styles it refers to (renumbered so they can't collide with ours).
fn adopt(s: &mut Session, src: Document) -> Fragment {
let mut frag = s.doc.adopt(src);
// Pasted pictures fit our text width, like Insert › Pictures (layout keeps their size).
let max_w = crate::io::text_width(&s.doc);
// Pasted pictures fit the room where they go, like Insert › Pictures: the table cell, the
// column, its own section (#5428; layout keeps their size). Measured (a layout) only when
// the fragment holds an inline picture.
let mut has_picture = false;
for b in &mut frag.blocks {
crate::io::fit_block_pictures(b, max_w);
each_para(b, 0, &mut |p| {
has_picture |= p
.objects
.iter()
.any(|o| matches!(o, wordcraft_doc::InlineObject::Image { float, .. } if float.wrap == wordcraft_doc::para::Wrap::Inline));
});
}
if has_picture {
let max_w = s.room_at(&s.sel.ordered().0);
for b in &mut frag.blocks {
crate::io::fit_block_pictures(b, max_w);
}
}
unlink_sections(&mut frag.blocks);
frag
+37
View File
@@ -204,6 +204,43 @@ impl Session {
Arc::new(wordcraft_layout::layout(doc, &mut LayoutCache::new(), &opts))
}
/// How wide a picture put in at `pos` may be, as Word fits an inserted or pasted picture
/// (#5428): the room its paragraph's lines have (the width available to its widest laid-out line,
/// so the paragraph's indents are already taken out; inside a table cell, the innermost cell's
/// text area, nested tables included; a turned cell isn't measured and falls back to the
/// column width), never wider than the column it is in, of its own section. The narrowest
/// section's text width ([`crate::io::text_width`]) when `pos` isn't laid out. It is measured on the pages, whatever the view: Web Layout and Read Mode reflow the
/// text to the window, and a picture put in there keeps the size it gets in the document.
pub(crate) fn room_at(&mut self, pos: &wordcraft_doc::Pos) -> f32 {
let first = crate::io::text_width(&self.doc);
let l =
if !self.view.read_mode && self.view.mode == ViewMode::Print { self.layout() } else { self.output_layout_of(&self.doc, false, false) };
let Some((caret, page)) = l.caret_on(pos, self.page_hint).and_then(|c| Some((c, l.pages.get(c.page)?))) else { return first };
// A page can hold several continuous sections: the body's own comes from the position.
let at = match (pos.story, pos.path.0.first()) {
(StoryRef::Body, Some(b)) => self.doc.section_index_of(*b as usize),
_ => page.section,
};
let section = self.doc.sections().get(at).map(|(_, sp)| (*sp).clone());
let column = match (&section, pos.story) {
(Some(sp), StoryRef::Body) => {
let boxes = sp.column_boxes();
let x = caret.x - page.body.x;
boxes.iter().find(|(cx, w)| x >= cx - 0.5 && x <= cx + w + 0.5).map_or_else(|| sp.text_width(), |(_, w)| *w)
}
(Some(sp), StoryRef::Part(_)) => sp.text_width(),
(None, _) => first,
};
let lines = wordcraft_layout::hit::page_lines(page, pos.story)
.iter()
.filter(|h| *h.path == pos.path)
.map(|h| h.right - h.left)
.filter(|w| w.is_finite())
.fold(0.0f32, f32::max);
let room = if lines >= 1.0 { lines.min(column) } else { column };
if room.is_finite() && room >= 1.0 { room } else { first }
}
/// Invalidate the cached layout (fonts changed etc.).
pub fn relayout(&mut self) {
self.layout = Default::default();
+141 -4
View File
@@ -6281,8 +6281,8 @@ fn cut_and_copy_with_bare_caret_beside_object_change_nothing() {
assert!(s.sel.is_collapsed());
assert!(crate::cmd::objects::object_selection(&s).is_none());
let copy_res = run(&mut s, "edit.copy", json!({}));
assert_eq!(copy_res["text"], "", "copy on bare caret returns empty text");
let copy_res = s.run("edit.copy", &json!({}));
assert!(matches!(copy_res, Err(crate::CmdError::Disabled(_))), "copy on bare caret is disabled");
assert!(s.clipboard.is_none(), "clipboard remains unset");
let cut_res = s.run("edit.cut", &json!({}));
@@ -6297,8 +6297,8 @@ fn cut_and_copy_with_bare_caret_beside_object_change_nothing() {
assert!(s.sel.is_collapsed());
assert!(crate::cmd::objects::object_selection(&s).is_none());
let copy_res = run(&mut s, "edit.copy", json!({}));
assert_eq!(copy_res["text"], "", "copy on bare caret returns empty text");
let copy_res = s.run("edit.copy", &json!({}));
assert!(matches!(copy_res, Err(crate::CmdError::Disabled(_))), "copy on bare caret is disabled");
assert!(s.clipboard.is_none(), "clipboard remains unset");
let cut_res = s.run("edit.cut", &json!({}));
@@ -14943,6 +14943,143 @@ fn page_down_extends_a_selection_that_ends_in_collapsed_outline_text() {
assert!(s.layout().caret(&s.sel.focus).is_some(), "to a place the outline shows");
}
/// #5428: an inserted or pasted picture fits where it goes, as in Word: a table cell's width
/// (a nested cell's too), a column's, not the whole page's text width.
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn an_inserted_or_pasted_picture_fits_where_it_goes() {
let png = |w: u32, h: u32| {
let mut b = Vec::new();
image::RgbaImage::from_pixel(w, h, image::Rgba([30, 90, 200, 255]))
.write_to(&mut std::io::Cursor::new(&mut b), image::ImageFormat::Png)
.unwrap();
cmd::insert::base64_encode(&b)
};
let widths = |s: &Session| {
let mut v = Vec::new();
for b in s.doc.body.iter() {
let mut b = (**b).clone();
cmd::paste::each_para(&mut b, 0, &mut |p| {
for o in &p.objects {
if let wordcraft_doc::InlineObject::Image { w, h, .. } = o {
v.push((*w, *h));
}
}
});
}
v
};
let text_w = crate::io::text_width(&Session::new(wordcraft_doc::Document::new()).doc);
let in_cell = |cols: u32| {
let mut s = Session::new(wordcraft_doc::Document::new());
run(&mut s, "insert.table", json!({"rows": 1, "cols": cols}));
assert!(s.sel.focus.path.depth() > 0, "the caret is in the first cell");
s
};
// Insert › Pictures and Paste in a cell of a three-column table.
let cell = text_w / 3.0;
let mut s = in_cell(3);
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
let mut p = in_cell(3);
let html = format!("<p><img src=\"data:image/png;base64,{}\"></p>", png(1000, 200));
run(&mut p, "edit.pasteSpecial", json!({"as": "html", "html": html}));
for (how, s) in [("inserted", &s), ("pasted", &p)] {
let got = widths(s);
let [(w, h)] = got.as_slice() else { panic!("{how}: {got:?}") };
assert!(*w <= cell && *w > cell - 20.0, "{how}: {w} fits the cell's text area ({cell} less its margins)");
assert!((h * 5.0 - w).abs() < 0.1, "{how}: proportions kept: {w} × {h}");
}
// A table in that cell: its own narrower cell.
let mut s = in_cell(2);
let outer = s.room_at(&s.sel.focus.clone());
// (A table inserted in a cell takes the page's text width for its columns, so four columns
// make its cells narrower than the outer one.)
run(&mut s, "insert.table", json!({"rows": 1, "cols": 4}));
assert!(s.sel.focus.path.depth() > 1, "the caret is in the nested cell");
let nested = s.room_at(&s.sel.focus.clone());
assert!(nested < outer - 50.0, "the nested cell ({nested}) is narrower than the outer one ({outer})");
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
let w = widths(&s)[0].0;
assert!((w - nested).abs() < 0.5 && w <= text_w / 4.0, "{w} fits the nested cell ({nested})");
// Two text columns: one column's width.
let mut s = Session::new(wordcraft_doc::Document::new());
run(&mut s, "layout.columns", json!({"count": 2}));
let column = s.doc.sections()[0].1.column_boxes()[0].1;
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
let w = widths(&s)[0].0;
assert!((w - column).abs() < 0.5, "{w} fits the column ({column})");
// Body text keeps the full text width.
let mut s = Session::new(wordcraft_doc::Document::new());
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
assert!((widths(&s)[0].0 - text_w).abs() < 0.5);
}
/// #5428 review: a page can hold several continuous sections; a picture goes by the section of the
/// position, not of the page's first one (two columns, then a continuous single-column section).
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn a_picture_after_a_continuous_break_fits_its_own_section() {
let sect = |cols: &str, kind: &str| format!(r#"<w:sectPr>{kind}<w:pgSz w:w="11906" w:h="16838"/><w:cols {cols} w:space="708"/></w:sectPr>"#);
let body = [
"<w:p><w:r><w:t>one</w:t></w:r></w:p>".to_string(),
format!("<w:p><w:pPr>{}</w:pPr></w:p>", sect(r#"w:num="2""#, "")),
"<w:p><w:r><w:t>two</w:t></w:r></w:p>".to_string(),
sect("", r#"<w:type w:val="continuous"/>"#),
]
.concat();
let mut s = Session::new(wordcraft_docx::read(&docx_with_styles(&body, "")).unwrap());
let last = s.doc.body.len() - 1;
s.sel = crate::Selection::caret(Pos::body(last, 0));
let room = s.room_at(&s.sel.focus.clone());
let column = s.doc.sections()[0].1.column_boxes()[0].1;
assert!(room > column + 50.0, "{room} is the single column's width, not the earlier two columns' ({column})");
}
/// #5428 review: Web Layout and Read Mode reflow the text to the window, but a picture put in
/// there is fitted to the page's text width, as in Print Layout: the size stays in the document.
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn a_picture_put_in_in_web_layout_fits_the_page_not_the_window() {
let png = |w: u32, h: u32| {
let mut b = Vec::new();
image::RgbaImage::from_pixel(w, h, image::Rgba([30, 90, 200, 255]))
.write_to(&mut std::io::Cursor::new(&mut b), image::ImageFormat::Png)
.unwrap();
cmd::insert::base64_encode(&b)
};
let width = |s: &Session| {
s.doc.body.iter().filter_map(|b| b.as_para()).flat_map(|p| p.objects.iter()).find_map(|o| match o {
wordcraft_doc::InlineObject::Image { w, .. } => Some(*w),
_ => None,
})
};
let text_w = crate::io::text_width(&Session::new(wordcraft_doc::Document::new()).doc);
let web = || {
let mut s = Session::new(wordcraft_doc::Document::new());
run(&mut s, "view.webLayout", json!({}));
// A narrow window, or a high zoom.
s.view.web_width = 350.0;
assert!(s.layout().pages[0].w < text_w, "the window is narrower than the page's text");
s
};
let mut s = web();
run(&mut s, "insert.picture", json!({"data": png(1000, 200)}));
let mut p = web();
let html = format!("<p><img src=\"data:image/png;base64,{}\"></p>", png(1000, 200));
run(&mut p, "edit.pasteSpecial", json!({"as": "html", "html": html}));
for (how, s) in [("inserted", &s), ("pasted", &p)] {
let w = width(s).unwrap();
assert!((w - text_w).abs() < 0.5, "{how}: {w} fits the page's text width ({text_w})");
}
// Read Mode's narrow pages don't set it either.
let mut s = Session::new(wordcraft_doc::Document::new());
run(&mut s, "text.insert", json!({"text": "Read"}));
run(&mut s, "view.readMode", json!({}));
s.view.read_width = 240.0;
let room = s.room_at(&s.sel.focus.clone());
assert!((room - text_w).abs() < 0.5, "Read Mode: {room} is the page's text width ({text_w})");
}
/// A picture an OpenDocument file gives no size is shown at its own, fitted to the text as other
/// formats' are; one with a stated size keeps it, in line too.
#[test]
+1
View File
@@ -319,6 +319,7 @@ impl WordApp {
pub fn logic(&mut self, ctx: &egui::Context) {
let lang = i18n::Lang::from_pref(&self.ui.language);
if self.ctx.is_none() {
theme::set_dark_text_curve(ctx);
self.ctx = Some(ctx.clone());
}
updates_ui::tick(self, ctx);
+49
View File
@@ -330,6 +330,25 @@ fn a_desktop_paste_after_mod_shift_v_is_not_swallowed() {
assert_eq!(body(h.state()), "source later");
}
/// #5616: Mod+Shift+C (Copy Formatting), Shift released, Mod still held or released: Mod+C's
/// chord isn't the paste's modifiers, so a subsequent Mod+V paste keeps HTML's formatting (bold).
#[test]
fn an_unrelated_keys_modifiers_do_not_steer_a_later_paste() {
for mod_still_held in [false, true] {
let mut h = alt_frame_app();
offer(&h, bold_flavours("external"));
let chord = Modifiers { shift: true, ..mod_held() };
mods_frame(&mut h, chord, vec![key_event(Key::C, true, chord)]);
let after = if mod_still_held { mod_held() } else { Modifiers::NONE };
mods_frame(&mut h, after, vec![key_event(Key::C, false, after)]);
let ctrl = mod_held();
mods_frame(&mut h, ctrl, vec![key_event(Key::V, true, ctrl)]);
mods_frame(&mut h, Modifiers::NONE, vec![key_event(Key::V, false, Modifiers::NONE)]);
assert_eq!(body(h.state()), "external");
assert!(is_bold(&mut h), "held={mod_still_held}: Mod+V keeps the HTML's bold");
}
}
/// Paste Formatting on a chord the user bound pastes the copied formatting once.
#[test]
fn paste_formatting_on_another_key_pastes_the_copied_formatting() {
@@ -422,6 +441,36 @@ fn mod_v_pastes_rich_only_clipboard_and_preserves_picture_routing() {
assert_eq!(body(h.state()), "", "picture file paste does not fall back to HTML text");
}
/// #819: Alt+Q reaches Search/commands even when the canvas does not hold focus.
#[test]
fn alt_shortcuts_work_without_the_canvas_focused() {
if cfg!(target_os = "macos") {
return;
}
let mut app = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Text")), Default::default());
app.run("view.focus", 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);
},
app,
);
crate::test_harness::frames(&mut h, 4);
if let Some(focused_id) = h.ctx.memory(|m| m.focused()) {
h.ctx.memory_mut(|m| m.surrender_focus(focused_id));
}
crate::test_harness::frames(&mut h, 1);
assert!(!h.state().canvas.focused(&h.ctx.clone()), "canvas is unfocused");
let alt = egui::Modifiers { alt: true, ..Default::default() };
mods_frame(&mut h, alt, vec![key_event(Key::Q, true, alt)]);
crate::test_harness::frames(&mut h, 2);
use egui_kittest::kittest::Queryable as _;
assert!(h.query_by_role(egui::accesskit::Role::Dialog).is_some(), "Alt+Q opens Search/commands with canvas unfocused");
}
/// Alt held, keypad 0 2 3 3, Alt released: é (й on a Russian system) is typed, the digits
/// aren't, and keytips stay off (#961). Linux sends each digit's text too; Windows may send the
/// composed character.
+64 -12
View File
@@ -8,7 +8,7 @@ use craft::ui::buttons::{Arrangement, Button, IconButton};
use craft::ui::contract::{ActivateOn, BodyCx, CollectionEvent, Gap, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::display::Divider;
use craft::ui::layout_components::Stack;
use craft::ui::list::ThumbAspect;
use craft::ui::list::{ThumbAspect, ThumbSize};
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::primitives::{HAlign, TextRun};
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
@@ -286,17 +286,69 @@ pub(super) fn insert(row: &mut RibbonRow<'_>, app: &mut WordApp) {
});
}
/// The recent and common characters as a grid of six per row; a click inserts the character, remembers it and closes
/// The characters the grid offers after the recent ones, with their Unicode names (UnicodeData.txt). No Unicode-names
/// crate is installed, and the one on crates.io is under Unicode-DFS-2016, which the licence allowlist lacks.
const DEFAULT_SYMBOLS: &[(char, &str)] = &[
('\u{A9}', "COPYRIGHT SIGN"),
('\u{AE}', "REGISTERED SIGN"),
('\u{2122}', "TRADE MARK SIGN"),
('\u{A7}', "SECTION SIGN"),
('\u{B6}', "PILCROW SIGN"),
('\u{20AC}', "EURO SIGN"),
('\u{A3}', "POUND SIGN"),
('\u{A5}', "YEN SIGN"),
('\u{B0}', "DEGREE SIGN"),
('\u{B1}', "PLUS-MINUS SIGN"),
('\u{2260}', "NOT EQUAL TO"),
('\u{2264}', "LESS-THAN OR EQUAL TO"),
('\u{2265}', "GREATER-THAN OR EQUAL TO"),
('\u{F7}', "DIVISION SIGN"),
('\u{D7}', "MULTIPLICATION SIGN"),
('\u{221E}', "INFINITY"),
('\u{B5}', "MICRO SIGN"),
('\u{3B1}', "GREEK SMALL LETTER ALPHA"),
('\u{3B2}', "GREEK SMALL LETTER BETA"),
('\u{3C0}', "GREEK SMALL LETTER PI"),
('\u{3A9}', "GREEK CAPITAL LETTER OMEGA"),
('\u{2211}', "N-ARY SUMMATION"),
('\u{221A}', "SQUARE ROOT"),
('\u{2192}', "RIGHTWARDS ARROW"),
('\u{2190}', "LEFTWARDS ARROW"),
('\u{2713}', "CHECK MARK"),
('\u{2605}', "BLACK STAR"),
('\u{2665}', "BLACK HEART SUIT"),
('\u{2014}', "EM DASH"),
('\u{2026}', "HORIZONTAL ELLIPSIS"),
];
/// A symbol's hover text: its Unicode name and code point (the code point alone, with its block, for a character
/// not named above), then its font when it has one.
pub(super) fn symbol_tip(glyph: &str, font: &str) -> String {
let mut chars = glyph.chars();
let tip = match (chars.next(), chars.next()) {
(Some(c), None) => {
let name = DEFAULT_SYMBOLS.iter().find(|(n, _)| *n == c).map(|(_, name)| *name);
let block = crate::dialogs_insert::subset_of(c);
match (name, block) {
(Some(name), _) => format!("{name} (U+{:04X})", c as u32),
(None, Some(block)) => format!("U+{:04X} ({block})", c as u32),
(None, None) => format!("U+{:04X}", c as u32),
}
}
_ => glyph.to_string(),
};
if font.is_empty() { tip } else { format!("{tip}, {font}") }
}
/// The recent and common characters as a compact grid; a click inserts the character, remembers it and closes
/// the menu.
fn symbol_grid(ui: &mut Ui, cx: &mut BodyCx<'_>, app: &mut WordApp) {
// Recently used symbols first (their font on hover), then common ones.
let mut items: Vec<(String, String)> = app.ui.recent_symbols.iter().map(|r| (r.ch.clone(), r.font.clone())).collect();
for c in [
"©", "®", "™", "§", "", "€", "£", "¥", "°", "±", "≠", "≤", "≥", "÷", "×", "∞", "µ", "α", "β", "π", "Ω", "∑", "√", "→", "←", "✓", "★", "♥",
"—", "…",
] {
if !items.iter().any(|(ch, f)| ch == c && f.is_empty()) {
items.push((c.to_string(), String::new()));
for (c, _) in DEFAULT_SYMBOLS {
let c = c.to_string();
if !items.iter().any(|(ch, f)| *ch == c && f.is_empty()) {
items.push((c, String::new()));
}
}
items.truncate(30);
@@ -304,20 +356,20 @@ fn symbol_grid(ui: &mut Ui, cx: &mut BodyCx<'_>, app: &mut WordApp) {
.select(SelectMode::None)
.activate(ActivateOn::Click)
.caption(CaptionPlace::None)
.card_columns(6)
.content_cells()
// Small cells (#7165): a glyph needs no more room than the small thumbnail step.
.thumb_size(ThumbSize::Small)
// At most thirty symbols, all shown; the menu's body is the one scroll.
.natural_height(true)
.show_items(ui, &SymbolCells(items.len()), &mut |key, _| {
let (c, font) = items.get(*key).cloned().unwrap_or_default();
let glyph = c.clone();
let (glyph, tip) = (c.clone(), symbol_tip(&c, &font));
let tile = Tile::new(c).thumb(ThumbAspect::SQUARE, move |cx, rect| {
let run = TextRun::new(glyph.as_str()).align(HAlign::Center);
cx.with_draw(|d| {
d.text_on_centre_line(rect, &run);
});
});
if font.is_empty() { tile } else { tile.tooltip(font) }
tile.tooltip(tip)
});
for event in &out.response.events {
if let CollectionEvent::Activate(key) = event
+124 -73
View File
@@ -959,92 +959,109 @@ fn unimplemented_stub_ribbon_buttons_are_disabled() {
}
}
/// #7324, #7457: Table ribbon menu buttons (Styles, Borders, Select, Delete, AutoFit) bind their command IDs
/// so they disable when editing is protected or when no table is active.
#[test]
fn table_ribbon_menu_buttons_disable_when_unselected_or_protected() {
/// Is the ribbon button `name` disabled? (helpers for the table ribbon gate tests below.)
fn table_button_disabled(h: &Harness, name: &str) -> bool {
use egui::accesskit::Role;
h.query_all(By::new().role(Role::Button).label(name)).next().unwrap_or_else(|| panic!("button {name} not found")).accesskit_node().is_disabled()
}
let is_disabled = |h: &Harness, name: &str| {
h.query_all(By::new().role(Role::Button).label(name))
.next()
.unwrap_or_else(|| panic!("button {name} not found"))
.accesskit_node()
.is_disabled()
};
fn table_button_hint(h: &Harness, name: &str) -> String {
use egui::accesskit::Role;
h.query_all(By::new().role(Role::Button).label(name))
.next()
.unwrap_or_else(|| panic!("button {name} not found"))
.accesskit_node()
.description()
.map(|s| s.to_string())
.unwrap_or_default()
}
let description = |h: &Harness, name: &str| {
h.query_all(By::new().role(Role::Button).label(name))
.next()
.unwrap_or_else(|| panic!("button {name} not found"))
.accesskit_node()
.description()
.map(|s| s.to_string())
};
/// A 2x2 table app on `tab`; `protected` sets read-only protection.
fn table_tab_harness(tab: &str, protected: bool) -> Harness {
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
app.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
if protected {
app.session.doc.settings.protection = Some("readOnly".into());
}
tab_harness(app, tab)
}
// Configure Table Design & Table Layout as explicit ribbon tabs so they can be
// displayed even when the cursor is outside a table.
let make_table_tabs_app = |mut app: WordApp| {
/// #7324, #7457: without an active table the Table ribbon menu buttons disable. The Table tabs are
/// configured explicitly so they show with the cursor outside a table.
#[test]
fn table_ribbon_menu_buttons_disable_when_unselected() {
for tab in ["Table Design", "Table Layout"] {
let mut app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default());
app.session.ribbon.tabs = vec![
wordcraft_engine::ribbon::TabEntry { name: "Table Design".to_string(), custom: false, hidden: false, groups: Vec::new() },
wordcraft_engine::ribbon::TabEntry { name: "Table Layout".to_string(), custom: false, hidden: false, groups: Vec::new() },
];
app
};
let h = tab_harness(app, tab);
if tab == "Table Design" {
assert!(table_button_disabled(&h, "Styles"), "Styles button should be disabled when not in table");
assert!(table_button_disabled(&h, "Borders"), "Borders button should be disabled when not in table");
} else {
assert!(table_button_disabled(&h, "Select"), "Select button should be disabled when not in table");
assert!(table_button_disabled(&h, "Delete"), "Delete button should be disabled when not in table");
assert!(table_button_disabled(&h, "AutoFit"), "AutoFit button should be disabled when not in table");
assert!(
table_button_hint(&h, "Select").to_ascii_lowercase().contains("the cursor isn't in a table"),
"Select should indicate outside table in disabled hint"
);
}
}
}
// 1. Without a table active:
let app_no_table = make_table_tabs_app(WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default()));
let h_design_empty = tab_harness(app_no_table, "Table Design");
assert!(is_disabled(&h_design_empty, "Styles"), "Styles button should be disabled when not in table");
assert!(is_disabled(&h_design_empty, "Borders"), "Borders button should be disabled when not in table");
/// With an active, unprotected table the Table Design buttons are enabled.
#[test]
fn table_design_menu_buttons_enabled_in_table() {
let h = table_tab_harness("Table Design", false);
assert!(!table_button_disabled(&h, "Styles"), "Styles button should be enabled in table");
assert!(!table_button_disabled(&h, "Borders"), "Borders button should be enabled in table");
}
let app_no_table2 = make_table_tabs_app(WordApp::new(Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default()));
let h_layout_empty = tab_harness(app_no_table2, "Table Layout");
assert!(is_disabled(&h_layout_empty, "Select"), "Select button should be disabled when not in table");
assert!(is_disabled(&h_layout_empty, "Delete"), "Delete button should be disabled when not in table");
assert!(is_disabled(&h_layout_empty, "AutoFit"), "AutoFit button should be disabled when not in table");
assert!(
description(&h_layout_empty, "Select").as_deref().unwrap_or("").to_ascii_lowercase().contains("the cursor isn't in a table"),
"Select should indicate outside table in disabled hint"
);
/// With an active, unprotected table the Table Layout buttons are enabled and open their menus
/// (the controls for the shut-menu checks under protection).
#[test]
fn table_layout_menu_buttons_enabled_in_table() {
let mut h = table_tab_harness("Table Layout", false);
assert!(!table_button_disabled(&h, "Select"), "Select button should be enabled in table");
assert!(!table_button_disabled(&h, "Delete"), "Delete button should be enabled in table");
assert!(!table_button_disabled(&h, "AutoFit"), "AutoFit button should be enabled in table");
click_button(&mut h, "Delete");
assert!(h.query_all(menu_row("Delete Rows")).next().is_some(), "an enabled Delete opens its menu");
}
// 2. With an active table and no protection: buttons are enabled:
let mut app_table = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
app_table.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
let h_design = tab_harness(app_table, "Table Design");
assert!(!is_disabled(&h_design, "Styles"), "Styles button should be enabled in table");
assert!(!is_disabled(&h_design, "Borders"), "Borders button should be enabled in table");
/// Positive control for the AutoFit shut-menu check under protection: an enabled AutoFit opens its menu.
#[test]
fn table_layout_autofit_opens_menu_in_table() {
let mut h = table_tab_harness("Table Layout", false);
click_button(&mut h, "AutoFit");
assert!(h.query_all(menu_row("AutoFit Window")).next().is_some(), "an enabled AutoFit opens its menu");
}
let mut app_table2 = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
app_table2.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
let h_layout = tab_harness(app_table2, "Table Layout");
assert!(!is_disabled(&h_layout, "Select"), "Select button should be enabled in table");
assert!(!is_disabled(&h_layout, "Delete"), "Delete button should be enabled in table");
assert!(!is_disabled(&h_layout, "AutoFit"), "AutoFit button should be enabled in table");
/// Under read-only protection the Table Design buttons disable and say why.
#[test]
fn table_design_menu_buttons_disable_when_protected() {
let h = table_tab_harness("Table Design", true);
assert!(table_button_disabled(&h, "Styles"), "Styles button should be disabled under protection");
assert!(table_button_disabled(&h, "Borders"), "Borders button should be disabled under protection");
assert!(table_button_hint(&h, "Styles").contains("protected"), "Styles should indicate protection in disabled hint");
}
// 3. With an active table under document protection (read-only): mutating buttons are disabled:
let mut app_protected_design = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
app_protected_design.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
app_protected_design.session.doc.settings.protection = Some("readOnly".into());
let h_prot_design = tab_harness(app_protected_design, "Table Design");
assert!(is_disabled(&h_prot_design, "Styles"), "Styles button should be disabled under protection");
assert!(is_disabled(&h_prot_design, "Borders"), "Borders button should be disabled under protection");
assert!(
description(&h_prot_design, "Styles").as_deref().unwrap_or("").contains("protected"),
"Styles should indicate protection in disabled hint"
);
let mut app_protected_layout = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
app_protected_layout.run("insert.table", json!({"rows": 2, "cols": 2})).unwrap();
app_protected_layout.session.doc.settings.protection = Some("readOnly".into());
let h_prot_layout = tab_harness(app_protected_layout, "Table Layout");
assert!(!is_disabled(&h_prot_layout, "Select"), "Select button should remain enabled under protection");
assert!(is_disabled(&h_prot_layout, "Delete"), "Delete button should be disabled under protection");
assert!(is_disabled(&h_prot_layout, "AutoFit"), "AutoFit button should be disabled under protection");
assert!(
description(&h_prot_layout, "Delete").as_deref().unwrap_or("").contains("protected"),
"Delete should indicate protection in disabled hint"
);
/// Under read-only protection the mutating Table Layout buttons disable, say why, and stay shut
/// when clicked (C2-5, #7824).
#[test]
fn table_layout_menu_buttons_disable_when_protected() {
let mut h = table_tab_harness("Table Layout", true);
assert!(!table_button_disabled(&h, "Select"), "Select button should remain enabled under protection");
assert!(table_button_disabled(&h, "Delete"), "Delete button should be disabled under protection");
assert!(table_button_disabled(&h, "AutoFit"), "AutoFit button should be disabled under protection");
assert!(table_button_hint(&h, "Delete").contains("protected"), "Delete should indicate protection in disabled hint");
click_button(&mut h, "Delete");
assert!(h.query_all(menu_row("Delete Rows")).next().is_none(), "a disabled Delete opens no menu");
click_button(&mut h, "AutoFit");
assert!(h.query_all(menu_row("AutoFit Window")).next().is_none(), "a disabled AutoFit opens no menu");
}
/// #7374: the Decorative Text / WordArt Styles dropdown menu renders compact tiles (~40×36 pt)
@@ -1322,3 +1339,37 @@ fn a_combo_field_reached_with_tab_shows_its_hint_after_a_delay() {
}
assert!(h.query_all_by_label("Font Size").count() >= 2, "hint must show after tooltip delay");
}
/// #7165: the Symbol drop-down's cells are compact (a thumbnail-small step, not a card) and the hover text names
/// the character, not just the glyph.
#[test]
fn symbol_menu_cells_are_compact_and_the_tooltip_names_the_character() {
let app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Text")), crate::Services::default());
let mut h = tab_harness(app, "Insert");
click_button(&mut h, "Symbol");
let cell_y = |h: &Harness| h.get_by_label("\u{A9}").rect().min.y;
let cell = h.get_by_label("\u{A9}").rect();
assert!(cell.width() <= 80.0 && cell.height() <= 80.0, "a symbol cell is compact, got {:?}", cell.size());
// Eight symbols fit one row, so the menu does not cover the page.
assert_eq!(h.get_by_label("\u{A5}").rect().min.y, cell_y(&h), "the eighth symbol is on the first row");
h.get_by_label("\u{A9}").hover();
crate::test_harness::frames(&mut h, 40);
assert!(h.query_by_label_contains("COPYRIGHT SIGN (U+00A9)").is_some(), "the tooltip names the character");
// A screen reader gets the name without hovering: the tile's label is the glyph, its description the name.
let desc = h.get_by_label("\u{A9}").accesskit_node().description().map(|d| d.to_string()).unwrap_or_default();
assert!(desc.contains("COPYRIGHT SIGN"), "the tile's accessible description names the character, got {desc:?}");
}
/// Characters outside the common list still say what they are: code point and block.
#[test]
fn symbol_tip_names_known_characters_and_falls_back_to_the_code_point() {
use super::insert::symbol_tip;
let named = symbol_tip("\u{A9}", "");
assert!(named.contains("COPYRIGHT SIGN") && named.contains("00A9"), "named character: {named}");
let with_font = symbol_tip("\u{3B1}", "Symbol");
assert!(with_font.contains("GREEK SMALL LETTER ALPHA") && with_font.contains("03B1") && with_font.contains("Symbol"), "{with_font}");
assert!(!named.contains("Symbol"), "no font, none named");
let unnamed = symbol_tip("\u{2602}", "");
assert!(unnamed.contains("2602") && unnamed.contains("Miscellaneous Symbols"), "unnamed character: {unnamed}");
assert_eq!(symbol_tip("", ""), "");
}
+73
View File
@@ -2080,6 +2080,57 @@ fn title_and_account_buttons_work() {
assert!(h.query_by_label("User name:").is_some());
}
/// A pointer drag on a pane's resize edge leaves no keyboard focus behind, so Ctrl and
/// F-key shortcuts run right after it, docked or floating (#1756).
#[test]
fn shortcuts_run_after_a_pane_resize() {
use egui::accesskit::Role;
use egui_kittest::kittest::{By, Queryable};
type H = egui_kittest::Harness<'static, WordApp>;
fn key(h: &mut H, key: egui::Key, modifiers: egui::Modifiers) {
h.key_press_modifiers(modifiers, key);
h.step();
}
fn drag(h: &mut H, from: egui::Pos2, by: egui::Vec2) {
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
h.event(egui::Event::PointerMoved(from));
h.event(button(from, true));
h.step();
h.event(egui::Event::PointerMoved(from + by));
h.step();
h.event(button(from + by, false));
h.step();
}
let find_open = |h: &H| h.state().dialog_host.open_dialogs().iter().any(|d| d.key.as_deref() == Some("find"));
let styles_pane =
|h: &H| h.query_all(By::new().role(Role::Group).label("Styles")).map(|n| n.rect()).find(|r| r.height() > 300.0).expect("Styles pane frame");
let mut a = app();
a.run("view.stylesPane", json!({"value": true})).unwrap();
let mut h = harness(a);
h.step();
let pane = styles_pane(&h);
// On the pane's inner edge: drag left by 40 px to widen it.
drag(&mut h, egui::pos2(pane.left() + 1.0, pane.center().y), egui::vec2(-40.0, 0.0));
let width = h.state().ui.styles_pane_width.unwrap_or_default();
assert!((width - 290.0).abs() <= 2.0, "the drag widened the docked pane: {width}");
key(&mut h, egui::Key::H, egui::Modifiers::COMMAND);
assert!(find_open(&h), "Ctrl+H runs after the docked drag");
key(&mut h, egui::Key::Escape, egui::Modifiers::NONE);
assert!(h.state().dialog_host.open_dialogs().is_empty(), "Escape closes Replace");
h.state_mut().run("view.stylesPaneDock", json!({"dock": "float"})).unwrap();
h.step();
let float_pane = styles_pane(&h);
let before = h.state().ui.styles_pane_float;
// Drag the bottom-right corner.
drag(&mut h, float_pane.max - egui::vec2(2.0, 2.0), egui::vec2(30.0, 30.0));
assert_ne!(h.state().ui.styles_pane_float, before, "the drag resized the floating pane");
key(&mut h, egui::Key::H, egui::Modifiers::COMMAND);
assert!(find_open(&h), "Ctrl+H runs after the floating pane's resize");
}
/// #3172: the Paste button is named "Paste": its tooltip adds the key as the platform writes it,
/// so its name no longer carries macOS's "⌘V", which screen readers read on Windows as "Paste (⌘V)".
#[test]
@@ -3342,6 +3393,28 @@ fn check_spelling_off_in_a_second_window_stays_off_in_every_window() {
assert!(!b.session.view.proofing && !b.session.prefs.check_spelling, "saved off, whichever window was drawn");
}
/// #7841: in dark mode the app draws its interface text with its own lighter curve, not egui's dark default, and
/// light mode keeps egui's light one.
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn dark_interface_text_uses_the_app_s_lighter_curve() {
let ctx = crate::test_harness::context();
let mut a = app();
let curve = |a: &mut WordApp, theme: theme::Appearance| {
a.ui.theme = theme;
for _ in 0..2 {
crate::test_harness::pass(&ctx, a, egui::RawInput::default());
}
ctx.global_style().visuals.text_options.color_transfer_function
};
let dark = curve(&mut a, theme::Appearance::Dark);
let light = curve(&mut a, theme::Appearance::Light);
let lighter = egui::epaint::FontColorTransferFunction::Gamma(0.8);
assert_eq!(dark, lighter, "dark mode draws with the app's curve");
assert_eq!(light, egui::Visuals::light().text_options.color_transfer_function, "light mode keeps egui's");
assert_eq!(curve(&mut a, theme::Appearance::Dark), lighter, "back to dark gets the app's curve again");
}
/// #1861: the registered Interface Theme command drives the same setting as Options:
/// searchable in the registry, settable, toggling without a value, and surviving a restart.
#[test]
+10
View File
@@ -712,6 +712,16 @@ pub fn apply_animations(ctx: &egui::Context, on: bool) {
/// Coverage exponent for light-on-dark interface text on Linux and the BSDs (see [`visuals`]).
const DARK_TEXT_GAMMA: f32 = 0.8;
/// Gives egui's dark style our lighter light-on-dark text curve on Linux and the BSDs (see [`visuals`]). The craft
/// runtime's mode sync keeps an app's own curve for each mode (craft-libs#3589), so setting it once is enough (#7841).
pub fn set_dark_text_curve(ctx: &egui::Context) {
if cfg!(all(unix, not(target_os = "macos"))) {
ctx.style_mut_of(egui::Theme::Dark, |s| {
s.visuals.text_options.color_transfer_function = egui::epaint::FontColorTransferFunction::Gamma(DARK_TEXT_GAMMA);
});
}
}
/// egui's visuals for one of our palettes.
fn visuals(t: &Tokens) -> Visuals {
let mut v = if t.dark { Visuals::dark() } else { Visuals::light() };
+118
View File
@@ -1,5 +1,7 @@
use craft::font_manager::Catalog;
use craft::font_manager::craft_font_catalog::{Limits, Source};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Props as _, Show as _};
use egui::Key;
use egui::accesskit::Role;
use egui_kittest::kittest::{NodeT, Queryable};
@@ -104,3 +106,119 @@ fn font_list_sections_skip_their_headings() {
h.run_steps(2);
assert_eq!(current_font(&mut h).as_deref(), Some(first_all.as_str()));
}
fn to_color32(rgba: craft::theme::Rgba) -> egui::Color32 {
egui::Color32::from(craft::theme::Srgba::from(rgba))
}
fn collect_shapes<'a>(shapes: &'a [egui::epaint::ClippedShape], out: &mut Vec<&'a egui::Shape>) {
for clipped in shapes {
fn walk<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::Shape>) {
match shape {
egui::Shape::Vec(children) => {
for child in children {
walk(child, out);
}
}
other => out.push(other),
}
}
walk(&clipped.shape, out);
}
}
fn find_button_fill(shapes: &[egui::epaint::ClippedShape], rect: egui::Rect) -> Option<(egui::Color32, egui::CornerRadius)> {
let mut flattened = Vec::new();
collect_shapes(shapes, &mut flattened);
flattened.into_iter().find_map(|s| match s {
egui::Shape::Rect(r)
if (r.rect.min.x - rect.min.x).abs() <= 1.5
&& (r.rect.max.x - rect.max.x).abs() <= 1.5
&& (r.rect.min.y - rect.min.y).abs() <= 1.5
&& (r.rect.max.y - rect.max.y).abs() <= 1.5
&& r.fill != egui::Color32::TRANSPARENT
&& r.corner_radius != egui::CornerRadius::ZERO =>
{
Some((r.fill, r.corner_radius))
}
_ => None,
})
}
/// #305: drawn buttons must react like standard buttons — resting at idle without a fill plate,
/// fading in through an intermediate fill on pointer hover, settling on the theme's hover state
/// token, darkening/transitioning to the pressed state token while held down, and clearing when
/// unhovered.
#[test]
fn drawn_buttons_fade_in_on_hover_and_darken_while_pressed() {
use egui::accesskit::Role;
let mut h = crate::test_harness::builder().with_size(egui::vec2(200.0, 100.0)).with_step_dt(0.04).build_ui(|ui| {
ui.horizontal(|ui| {
let _ = IconButton::new(crate::icons::id("save")).label("Save").show(ui);
});
});
h.ctx.all_styles_mut(|s| s.animation_time = egui::Style::default().animation_time);
h.step();
let env = craft::ui::runtime::env::Env::of_root(&h.ctx);
let expected_hover = to_color32(env.tokens.color.state.hover);
let expected_pressed = to_color32(env.tokens.color.state.pressed);
let node = h.get_by_role_and_label(Role::Button, "Save");
let rect = node.rect();
assert!(rect.is_positive(), "Save button must have positive rect");
// 1. Idle state: no hover or pressed fill plate
let fill_before = find_button_fill(&h.output().shapes, rect);
assert_eq!(fill_before, None, "Save button must have no hover fill before hover");
// 2. Hover state: fades in through an intermediate fill, then settles on the hover token
node.hover();
h.run_steps(2);
let fill_mid = find_button_fill(&h.output().shapes, rect);
assert!(fill_mid.is_some(), "Save button must paint an intermediate fill while fading in");
let (mid_fill, _) = fill_mid.unwrap();
assert!(
mid_fill != expected_hover && mid_fill.a() > 0 && mid_fill.a() < expected_hover.a(),
"Save button hover should fade in through an intermediate alpha: got {mid_fill:?}, expected settled {expected_hover:?}"
);
h.run_steps(3);
let fill_hovered = find_button_fill(&h.output().shapes, rect);
assert!(fill_hovered.is_some(), "Save button must produce settled hover shape");
let (hover_fill, radius) = fill_hovered.unwrap();
assert_eq!(hover_fill, expected_hover, "Save button settled hover fill must match theme hover token");
assert!(
radius.nw > 0 && radius.nw == radius.ne && radius.nw == radius.sw && radius.nw == radius.se,
"Save button corner radius must be uniformly rounded: {:?}",
radius
);
// 3. Pressed state: pressing pointer button darkens/transitions to theme's pressed state token
h.event(egui::Event::PointerButton { pos: rect.center(), button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });
h.run_steps(4);
let fill_pressed = find_button_fill(&h.output().shapes, rect);
assert!(fill_pressed.is_some(), "Save button must have fill while pressed");
let (pressed_fill, _) = fill_pressed.unwrap();
assert_eq!(pressed_fill, expected_pressed, "Save button pressed fill must match theme pressed token");
// 4. Release: releasing pointer button transitions back to hover state
h.event(egui::Event::PointerButton {
pos: rect.center(),
button: egui::PointerButton::Primary,
pressed: false,
modifiers: egui::Modifiers::NONE,
});
h.run_steps(4);
let fill_released = find_button_fill(&h.output().shapes, rect);
assert!(fill_released.is_some(), "Save button must remain filled upon release");
let (released_fill, _) = fill_released.unwrap();
assert_eq!(released_fill, expected_hover, "Save button fill after release should return to hover token");
// 5. Unhover: pointer leaving the button clears the fill plate
h.event(egui::Event::PointerMoved(egui::pos2(0.0, 0.0)));
h.run_steps(4);
let fill_after = find_button_fill(&h.output().shapes, rect);
assert_eq!(fill_after, None, "Save button must clear hover fill after unhovering");
}
+2 -1
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
File diff suppressed because one or more lines are too long