mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 04:38:49 +00:00
Leave unused Escape to the window from notices
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::primitives::{HAlign, IconSpec, TextRun, Wrap};
|
||||
use crate::runtime::commands::CommandRef;
|
||||
use crate::runtime::env::{EnvView, Label};
|
||||
use crate::style::{ComponentStyle, IconLook, Insets, StyleColor, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens};
|
||||
use craft_behavior::{Flow, IconId, Intent, Metrics, NavShape, PartKey, Proposal, Roving, Sense};
|
||||
use craft_behavior::{Flow, IconId, Metrics, NavShape, PartKey, Proposal, Roving, Sense};
|
||||
use craft_i18n::Format;
|
||||
use craft_theme::{Rgba, Stateful, States, Variant, variant::Tone};
|
||||
use egui::{Align, Pos2, Rect, Response, Vec2};
|
||||
@@ -751,7 +751,7 @@ impl Component for Notice<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if cx.part_activated(DISMISS).is_some() || (self.dismiss && cx.core.intents.take(Intent::Cancel)) {
|
||||
if cx.part_activated(DISMISS).is_some() {
|
||||
self.dismissed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,27 @@ fn a_notice_reports_its_action_and_dismissal_in_a_frame_that_runs_twice() {
|
||||
assert_eq!(taken.get().1, 1, "the dismissal is reported once");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn escape_on_a_notice_action_reaches_the_window() {
|
||||
let dismissed = Rc::new(Cell::new(false));
|
||||
let cancelled = Rc::new(Cell::new(false));
|
||||
let (seen, window) = (dismissed.clone(), cancelled.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let out = Notice::new(Tone::Info, "Document repaired").dismiss().action(NoticeAction::new("Details")).show(ui);
|
||||
seen.set(seen.get() || out.dismissed);
|
||||
craft_ui::runtime::keys::with_window_intents(ui.ctx(), false, |intents| {
|
||||
let took = intents.take_exact(&craft_behavior::Intent::Cancel);
|
||||
window.set(window.get() || took);
|
||||
took
|
||||
});
|
||||
});
|
||||
fixture.settle();
|
||||
fixture.key(egui::Key::Tab, egui::Modifiers::NONE);
|
||||
fixture.key(egui::Key::Escape, egui::Modifiers::NONE);
|
||||
assert!(cancelled.get(), "Escape the notice action leaves reaches the window");
|
||||
assert!(!dismissed.get(), "Escape does not press the notice's dismiss button");
|
||||
}
|
||||
|
||||
/// A centred notice hosts the app's own leaf under its actions: the leaf sits centred under them, and a click on it
|
||||
/// reaches the app through the leaf's output.
|
||||
#[trial]
|
||||
|
||||
Reference in New Issue
Block a user