ui-panels: the dialog trials keep the dialog inside the window's rect, not the root's allocation, and report the window's focus before the armed answer's wait

This commit is contained in:
bflatastic
2026-11-22 08:26:13 +07:00
parent 70bb11ab70
commit fa3548d4ca
2 changed files with 48 additions and 39 deletions
+44 -37
View File
@@ -12,7 +12,7 @@ use craft_keymap::{Binding, CommandDef, CommandRef, ImportPlan, ImportReport};
use craft_theme::variant::Tone;
use craft_ui::buttons::Button;
use craft_ui::choice::{Checkbox, Radio, RadioGroup};
use craft_ui::contract::{Animate as _, Bind, BodyCx, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
use craft_ui::contract::{Animate as _, Bind, BodyCx, Entry, FieldLayout, Lazy, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
use craft_ui::display::{Shade, Text};
use craft_ui::layout_components::{Row, Stack};
use craft_ui::notices::Notice;
@@ -132,9 +132,13 @@ fn section(ui: &mut Ui, say: &Say, title: &str, lines: &[Line]) {
return;
}
heading(ui, say, title, lines.len());
let estimate = UiEnv::of(ui).tokens.size.row.text;
for (at, line) in lines.iter().enumerate() {
let shade = if line.to { Shade::Normal } else { Shade::Muted };
Text::new(line.text(say)).shade(shade).id_salt((title, at)).show(ui);
// A line out of view does not run: a review can list thousands.
Lazy::new((title, at), estimate).show(ui, |ui| {
let shade = if line.to { Shade::Normal } else { Shade::Muted };
Text::new(line.text(say)).shade(shade).id_salt((title, at)).show(ui);
});
}
}
@@ -401,41 +405,44 @@ fn plan_view(ui: &mut Ui, now: f64, env: &mut Env<'_>, state: &mut DialogState,
heading(ui, say, title, lines.len());
for (at, line) in lines.iter().enumerate() {
let marks = entry_of(&line.item, line.line);
Row::new().id_salt((tag, at)).show(ui, |ui, _| {
if let Some((entry, on)) = marks {
let label = format!("{}: {}", w.include_entry.as_str(), line.item);
let check = Checkbox::new(Bind::given(on)).label(label).show(ui);
if let Some(on) = check.value().copied() {
*act = Some(Act::Include(entry, on));
// A line out of view does not run: a review can list thousands.
Lazy::new((tag, at), ui_env.tokens.size.control.md).show(ui, |ui| {
Row::new().id_salt((tag, at)).show(ui, |ui, _| {
if let Some((entry, on)) = marks {
let label = format!("{}: {}", w.include_entry.as_str(), line.item);
let check = Checkbox::new(Bind::given(on)).label(label).show(ui);
if let Some(on) = check.value().copied() {
*act = Some(Act::Include(entry, on));
}
}
}
let shade = if line.to { Shade::Normal } else { Shade::Muted };
Text::new(line.text(say)).shade(shade).id_salt("text").show(ui);
let Some((entry, _)) = marks.filter(|_| pick) else { return };
let candidates: &[CommandRef] =
suggestions.iter().find(|s| s.item == line.item && s.line == line.line).map(|s| s.candidates.as_slice()).unwrap_or_default();
let own: Vec<Entry<usize>>;
let entries: &[Entry<usize>] = if candidates.is_empty() {
shared_entries()
} else {
let first = catalog.len() + 1;
own = candidates
.iter()
.enumerate()
.map(|(ci, c)| Entry::new(first + ci, say.label_of(env.keymap, c)))
.chain(shared_entries().iter().cloned())
.collect();
&own
};
let mut chosen = usize::MAX;
Select::new(w.command_for_item.fill(&[("item", line.item.as_str())]), Bind::bound(&mut chosen), entries)
.placeholder(w.choose_a_command_more.clone())
.searchable()
.id_salt("target")
.show(ui);
if let Some(target) = target_of(catalog, candidates, chosen) {
*act = Some(Act::Target(entry, target));
}
let shade = if line.to { Shade::Normal } else { Shade::Muted };
Text::new(line.text(say)).shade(shade).id_salt("text").show(ui);
let Some((entry, _)) = marks.filter(|_| pick) else { return };
let candidates: &[CommandRef] =
suggestions.iter().find(|s| s.item == line.item && s.line == line.line).map(|s| s.candidates.as_slice()).unwrap_or_default();
let own: Vec<Entry<usize>>;
let entries: &[Entry<usize>] = if candidates.is_empty() {
shared_entries()
} else {
let first = catalog.len() + 1;
own = candidates
.iter()
.enumerate()
.map(|(ci, c)| Entry::new(first + ci, say.label_of(env.keymap, c)))
.chain(shared_entries().iter().cloned())
.collect();
&own
};
let mut chosen = usize::MAX;
Select::new(w.command_for_item.fill(&[("item", line.item.as_str())]), Bind::bound(&mut chosen), entries)
.placeholder(w.choose_a_command_more.clone())
.searchable()
.id_salt("target")
.show(ui);
if let Some(target) = target_of(catalog, candidates, chosen) {
*act = Some(Act::Target(entry, target));
}
});
});
}
};
+4 -2
View File
@@ -399,7 +399,7 @@ fn a_dialog_moves_by_its_title_band_stays_on_screen_and_reopens_where_left() {
let title = band(&fixture);
fixture.drag(&title, egui::vec2(5000.0, 5000.0)).settle();
let screen = fixture.shown();
let screen = fixture.ctx().content_rect();
assert!(screen.contains_rect(dialog(&fixture)), "a drag past the edge stops at it: {:?} in {screen:?}", dialog(&fixture));
for _ in 0..8 {
@@ -429,7 +429,7 @@ fn a_tall_body_scrolls_under_a_footer_that_stays_in_view() {
fixture.settle();
let first = |fixture: &Fixture| fixture.by_label("Line 0").map(|target| target.rect);
let at_top = first(&fixture).expect("the first line is shown");
let screen = fixture.shown();
let screen = fixture.ctx().content_rect();
let ok = fixture.by_label("OK").expect("the footer is shown").rect;
assert!(screen.contains_rect(ok), "the footer stays inside the short window: {ok:?} in {screen:?}");
assert!(fixture.by_label("Line 59").is_none_or(|last| !screen.contains_rect(last.rect)), "the body does not all fit: it scrolls");
@@ -468,6 +468,8 @@ fn an_armed_answer_waits_until_its_prompt_was_seen() {
}
shown.set(now);
});
// The wait counts while the window has the focus, which the fixture's window has once it reports it.
fixture.frame(vec![egui::Event::WindowFocused(true)]);
fixture.settle();
let press = |fixture: &mut Fixture| {
let delete = fixture.by_label("Delete").expect("the armed button is shown");