diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index cb5a98056..234daa5e3 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -483,6 +483,12 @@ pub(crate) fn run( state.end = Some(End::Rewrite { refuses: false }); } } + if commit_now { + eprintln!( + "DIAG text::number::a_window_blur_mid_typing_keeps_the_typed_draft: commit_now step={} was_focused={was_focused} left_for_part={left_for_part} holds_drafts={} end={:?}", + step.commit_now, decl.options.holds_drafts, state.end + ); + } let resolved = resolve(&mut state, cx.value(), commit_now); if resolved.refused { crate::runtime::frame::refuse(&ctx); diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index 7f0e269e3..925fb455c 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -77,7 +77,8 @@ impl ButtonStyle { let text = &cx.tokens.color.text; let (faint, off) = (cx.color(text.faint), cx.color(text.disabled)); ButtonStyle { - surface: cx.field(), + // A button carries no value, so it is never invalid: the well without the field's failure edge. + surface: cx.text_well(), metrics: field.metrics(), focus: face::focus(cx), text: TextLook::new(TypeRole::Body, Stateful::new(faint).off(States::new(faint, faint, faint, off))), diff --git a/crates/ui-widgets/src/buttons/stories.rs b/crates/ui-widgets/src/buttons/stories.rs index fe46617c8..19a7e74be 100644 --- a/crates/ui-widgets/src/buttons/stories.rs +++ b/crates/ui-widgets/src/buttons/stories.rs @@ -5,7 +5,6 @@ use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Va use crate::display::{Shade, Text}; use crate::layout_components::{Grid, Row}; use crate::primitives::IconSpec; -use crate::runtime::commands::EditCommands; use crate::runtime::env::Message; use crate::style::DataColor; use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story}; @@ -71,30 +70,37 @@ fn button_loading(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Button::new("Saving").icon(IconId::new("save")).loading(true).show(ui).into() } +/// The command the search opener stories fire: an app command, so it is enabled in a story with no focused field. +#[derive(Clone, Copy, Debug, PartialEq, Eq, craft_ui_macros::CommandSet)] +#[command(prefix = "buttonStory", story)] +enum SearchStoryCommand { + #[command(label = "Search", default = "Cmd+K")] + Open, +} /// The command-search opener: the search glyph, the placeholder and the chord of its command at the end. #[story(Button<'static>, covers = [], drive = Drive::Activate, group = "Playground", title = "Search")] fn button_search(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - Button::search(EditCommands::Undo, "Search commands and settings").show(ui).into() + Button::search(SearchStoryCommand::Open, "Search commands and settings").show(ui).into() } /// In a narrow room the chord keeps its width and the placeholder is cut; the tooltip shows it whole. #[story(Button<'static>, covers = [], drive = Drive::Never, group = "Playground", title = "Search, narrow")] fn button_search_narrow(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { ui.set_max_width(ui.available_width() * 0.3); - Button::search(EditCommands::Undo, "Search commands and settings").show(ui).into() + Button::search(SearchStoryCommand::Open, "Search commands and settings").show(ui).into() } #[story(Button<'static>, covers = [], drive = Drive::Never, group = "Playground", title = "Search, disabled")] fn button_search_disabled(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - Button::search(EditCommands::Undo, "Search commands and settings").enabled(false).show(ui).into() + Button::search(SearchStoryCommand::Open, "Search commands and settings").enabled(false).show(ui).into() } /// A right-to-left placeholder: the glyph at the reading start and the chord, which keeps its left-to-right order, at /// the reading end. #[story(Button<'static>, covers = [], drive = Drive::Never, group = "Right to left", title = "Search")] fn button_search_rtl(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - Button::search(EditCommands::Undo, "חיפוש פקודות והגדרות").show(ui).into() + Button::search(SearchStoryCommand::Open, "חיפוש פקודות והגדרות").show(ui).into() } #[story(IconButton<'static>, covers = [Default])] diff --git a/crates/ui-widgets/src/choice/swatch_table/stories.rs b/crates/ui-widgets/src/choice/swatch_table/stories.rs index 928135aa6..8ba651916 100644 --- a/crates/ui-widgets/src/choice/swatch_table/stories.rs +++ b/crates/ui-widgets/src/choice/swatch_table/stories.rs @@ -63,6 +63,7 @@ fn swatch_table_trailing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { .selection(Bind::bound(data.value("selected", Selection::single(0usize)))) .wells(true) .tips(true) + .per_row(6) .trailing("Other colour…", IconId::new("plus")) .show_all(ui); with_readout(data, shown) diff --git a/crates/ui-widgets/src/pickers/date/stories.rs b/crates/ui-widgets/src/pickers/date/stories.rs index f95c54fb7..88cf630a5 100644 --- a/crates/ui-widgets/src/pickers/date/stories.rs +++ b/crates/ui-widgets/src/pickers/date/stories.rs @@ -95,6 +95,28 @@ fn calendar_popover_at_rect(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } } +/// The calendar popover open from the first frame, hanging from its opener. +#[story(CalendarPopover<'static>, covers = [], drive = Drive::Never)] +fn calendar_popover_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let mut open = *data.value("open", true); + let mut picked = *data.value("picked", Some(today())); + let shown = Stack::new().show(ui, |ui, _| { + let opener = Button::new("Choose a date").show(ui); + open |= clicked(&opener); + CalendarPopover::new("Due date", Bind::bound(&mut open), Bind::bound(&mut picked)) + .today(today()) + .opened_by(&opener) + .show(ui, |_, _| {}) + .output + }); + *data.value("open", true) = open; + *data.value("picked", Some(today())) = picked; + match shown.inner { + Some(output) => output.into(), + None => shown.output.into(), + } +} + #[story(Calendar, covers = [Default], drive = Drive::Never)] fn calendar(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let dates = crate::runtime::env::Env::of(ui).dates(); diff --git a/crates/ui-widgets/src/text/word_run.rs b/crates/ui-widgets/src/text/word_run.rs index 475973b2a..958f5154f 100644 --- a/crates/ui-widgets/src/text/word_run.rs +++ b/crates/ui-widgets/src/text/word_run.rs @@ -279,6 +279,10 @@ impl Component for WordRun<'_, K> { fn update(&mut self, cx: &mut Cx<'_, Self>) { let Some(at) = (0..self.words.len()).find(|&at| cx.part_activated(Self::part(at)).is_some()) else { return }; let key = self.words[at].key.clone(); + eprintln!( + "DIAG suite::craft_ui_widgets::text::word_run::WordRun<'_, usize>::drives: activated word {at}, value {:?}", + cx.value().map(|value| value.is_some()) + ); self.picked = Some(key.clone()); if cx.value().and_then(Option::as_ref) != Some(&key) { cx.set(Some(key)); diff --git a/crates/ui-widgets/src/text/word_run/stories.rs b/crates/ui-widgets/src/text/word_run/stories.rs index 41e341aa4..8eac66313 100644 --- a/crates/ui-widgets/src/text/word_run/stories.rs +++ b/crates/ui-widgets/src/text/word_run/stories.rs @@ -7,7 +7,7 @@ use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story}; use egui::Ui; /// A recognised line of a scanned page. -const LINE: &str = "The quick brown fox jumps over the lazy dog near the riverbank"; +const LINE: &str = "The quick brown fox jumps over the lazy dog"; /// A width the line's words wrap in, with the longest word wider than a line. const NARROW: f32 = 120.0; @@ -54,10 +54,10 @@ fn word_run_long_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { WordRun::new("Recognised text", &line, Bind::bound(data.value("picked", None::))).show(ui).into() } - #[story(WordRun<'static, usize>, covers = [Invalid], drive = Drive::Never)] fn word_run_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let line = words(LINE, |_| WordState::Normal); - let refuse_dog = |picked: &Option| if *picked == Some(8) { Validity::Refuse(Message::new("Pick a recognised word")) } else { Validity::Ok }; + let refuse_dog = + |picked: &Option| if *picked == Some(8) { Validity::Refuse(Message::new("Pick a recognised word")) } else { Validity::Ok }; WordRun::new("Recognised text", &line, Bind::bound(data.value("refused", Some(8usize))).check(refuse_dog)).show(ui).into() } diff --git a/crates/ui-widgets/tests/it/text/rtl_paragraph.rs b/crates/ui-widgets/tests/it/text/rtl_paragraph.rs index 26f9e5b98..334d2e33e 100644 --- a/crates/ui-widgets/tests/it/text/rtl_paragraph.rs +++ b/crates/ui-widgets/tests/it/text/rtl_paragraph.rs @@ -88,6 +88,12 @@ fn wrapped_right_to_left_lines_align_to_the_right_edge() { }) .collect(); let right = spans.iter().map(|(_, right)| *right).fold(f32::NEG_INFINITY, f32::max); + for ((left, end), (top, text, glyphs)) in spans.iter().zip(&rows) { + let last = glyphs.last().map(|(chr, x, advance)| (*chr, *x, *advance)); + eprintln!( + "DIAG text::rtl_paragraph::wrapped_right_to_left_lines_align_to_the_right_edge: top {top} span {left}..{end} last glyph {last:?} text {text:?}" + ); + } for ((left, end), (_, text, _)) in spans.iter().zip(&rows) { assert!((end - right).abs() < 0.5, "{text:?} ends at the right edge {right}: {end}"); assert!(*left >= -0.5, "{text:?} stays inside the column: {left}");