red round 1 (fw-widgets): fixes for fw-run-2 (see runs/fw-run-2/fw-widgets.md); committed by the lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-18 08:49:42 -05:00
co-authored by Claude Opus 5.5
parent c968deda51
commit 4633efd56e
8 changed files with 55 additions and 9 deletions
+6
View File
@@ -483,6 +483,12 @@ pub(crate) fn run<C: Component>(
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);
+2 -1
View File
@@ -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))),
+11 -5
View File
@@ -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])]
@@ -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)
@@ -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();
+4
View File
@@ -279,6 +279,10 @@ impl<K: Value + 'static> 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));
@@ -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::<usize>))).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<usize>| if *picked == Some(8) { Validity::Refuse(Message::new("Pick a recognised word")) } else { Validity::Ok };
let refuse_dog =
|picked: &Option<usize>| 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()
}
@@ -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}");