framework: the dialog host refuses a parent's confirm under an open child; an app catalog's def of a registry command adds its default bindings after the registry's; PenSource::current is public; the Stroke style button stays enabled at width 0

This commit is contained in:
aiongg
2026-11-15 16:38:03 +00:00
parent 617cc04932
commit e4d727ce1d
5 changed files with 40 additions and 4 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ pub(super) fn style_button(
) {
let off = appearance.stroke_width <= 0.0;
let style = Bind::given(appearance.stroke_style.clone());
let button = StrokeButton::new(words.stroke_style.clone(), style, open.reborrowed()).corners(corners).stroked(!off).enabled(!off);
let button = StrokeButton::new(words.stroke_style.clone(), style, open.reborrowed()).corners(corners).stroked(!off);
for event in button.show(ui).events {
let width = (off && matches!(event, EditEvent::Set { .. } | EditEvent::Begin { .. })).then_some(ShapeChange::ENABLED_STROKE_WIDTH);
out.push(event.map(|style| ShapeChange::StrokeStyle { style, width }));
@@ -467,8 +467,9 @@ pub fn keymap_builds() -> u64 {
}
/// The keymap of `registry` and the app catalog `app` on `platform` under `overrides`, and the chords it binds to the
/// edit commands and to the window's keys. A catalog command whose id the registry has stays out: the registry's
/// definition is the command's.
/// edit commands and to the window's keys. A catalog command whose id the registry has keeps the registry's
/// definition, and the catalog's default bindings join the registry's after them (an app's alternate keys, such as
/// F2/F3/F4 for Cut/Copy/Paste).
///
/// A window shortcut's default chord that another command also binds is that command's: the window shortcut loses it, so the
/// app's binding beats the framework's default. A window shortcut the overrides name keeps what they give it.
@@ -486,6 +487,17 @@ fn build_keymap(registry: &registry::Registry, app: Option<&AppCatalog>, platfor
// The window-shortcut yield and the edit chords below read the registry's definitions only.
let joined = |defs: &[CommandDef]| -> Vec<CommandDef> { defs.iter().chain(&app_defs).cloned().collect() };
let mut defs = registry.defs_for(platform);
if let Some(app) = app {
for extra in app.defs() {
if let Some(def) = defs.iter_mut().find(|def| def.command == extra.command) {
for binding in &extra.defaults {
if !def.defaults.contains(binding) {
def.defaults.push(binding.clone());
}
}
}
}
}
let mut keymap = keymap_of(joined(defs.as_slice()), scopes.clone(), platform, overrides);
let overridden = |def: &CommandDef| overrides.is_some_and(|overrides| overrides.get(&def.command.id).is_some());
let yielded: Vec<(CommandRef, Trigger)> = defs
+1 -1
View File
@@ -56,7 +56,7 @@ impl PenSource {
}
/// The latest reading, if the pen is on the tablet.
pub(crate) fn current(&self) -> Option<PointerSample> {
pub fn current(&self) -> Option<PointerSample> {
self.lock().current
}
+5
View File
@@ -474,7 +474,12 @@ impl DialogHost {
}
}
/// Refuses (returns `false`) while a child is open over the dialog: the child's answer comes first, as the
/// disabled parent shows on screen.
fn confirm_at(&mut self, ctx: &Context, at: usize) -> bool {
if self.stack.has_child(self.open[at].id()) {
return false;
}
let Some(result) = self.open[at].confirm_erased(ctx) else { return false };
let id = self.open[at].id();
self.remove_tree(id);
+19
View File
@@ -43,6 +43,10 @@ impl<const N: usize> StackDialog for Probe<N> {
self.shows += 1;
self.finish.take()
}
fn confirm(&mut self, _: &egui::Context) -> Option<u32> {
Some(N as u32)
}
}
fn run(host: &mut DialogHost, frames: &mut Frames) {
@@ -75,6 +79,21 @@ fn cancelling_a_parent_cancels_its_children() {
assert_eq!(host.take::<Probe<2>>(), Some(DialogResult::Cancel));
}
/// OK on a dialog waits for the child open over it: the host refuses the parent's confirm until the child closes.
#[trial]
fn a_parent_with_an_open_child_refuses_confirm() {
let mut frames = Frames::new();
let mut host = DialogHost::new();
let parent = host.open(Probe::<1>::new("parent"));
let child = host.open_child(Probe::<2>::new("child"), parent);
run(&mut host, &mut frames);
assert!(!host.confirm_by_id(&frames.ctx, parent), "the parent's OK waits for its child");
assert!(host.is_open::<Probe<1>>() && host.is_open::<Probe<2>>());
assert!(host.confirm_by_id(&frames.ctx, child));
assert!(host.confirm_by_id(&frames.ctx, parent), "with the child closed, the parent confirms");
assert_eq!(host.take::<Probe<1>>(), Some(DialogResult::Ok(1)));
}
/// A story of a hosted alert whose title is the story's `title` knob.
fn titled_alert(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let title = *data.value("title", "Could not open");