A command-bound component drops its click only on a pass where the command fired; the clicked-under-pointer story words the hold in its readout, not its data

This commit is contained in:
Martin Ball
2026-11-18 21:33:25 +00:00
parent 799b873ea5
commit a5dfccb1a4
3 changed files with 8 additions and 6 deletions
@@ -14,7 +14,7 @@ use egui::{Context, Id, Response, Ui, Vec2};
/// `changed` is `value_changed` of the pass's events.
pub(crate) fn before_finish(core: &mut CxCore<'_>, activated: bool, injected: Option<FireSource>, changed: bool) {
let by_key = activated && core.activation.is_some_and(|activation| activation.by_key);
response::rewrite_clicks(&mut core.response, by_key || core.part_clicked, core.command.is_some());
response::rewrite_clicks(&mut core.response, by_key || core.part_clicked, core.command.is_some() && activated);
if changed {
response::mark_changed(&mut core.response);
}
@@ -150,13 +150,13 @@ pub(crate) fn press_flags(response: &mut Response, view: PressView) {
/// Rewrites the click flags of the root's `Response` at step 17: egui's fake click on Enter, Space or AccessKit
/// `Click` is cleared, and set again only when the pipeline activated the component by key or by an AccessKit click on a part. A command-bound
/// component reports no click, because the command fires instead.
pub(crate) fn rewrite_clicks(response: &mut Response, activated_by_key: bool, command_bound: bool) {
/// component reports no click on a pass where its command fired, because the command fires instead.
pub(crate) fn rewrite_clicks(response: &mut Response, activated_by_key: bool, command_fired: bool) {
response.flags.remove(Flags::FAKE_PRIMARY_CLICKED);
if activated_by_key {
response.flags.insert(Flags::FAKE_PRIMARY_CLICKED);
}
if command_bound {
if command_fired {
response.flags.remove(Flags::CLICKED | Flags::FAKE_PRIMARY_CLICKED);
}
}
+4 -2
View File
@@ -233,8 +233,10 @@ fn click_and_stay(fixture: &mut Fixture) {
#[story(ToggleButton<'static>, covers = [], drive = Drive::Custom(click_and_stay), title = "Clicked under the pointer")]
fn toggle_button_clicked_under_pointer(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let shown = ToggleButton::new("Snap to grid", Bind::bound(data.value("snap_hover", false))).icon(IconId::new("eye")).show(ui);
*data.value("clicked_over", false) = shown.hover.clicked;
shown.into()
// The hold is the component's own state, which a measuring run does not carry: the story words it in its readout,
// not in its data, which the purity probe compares.
let clicked = shown.hover.clicked;
StoryOutput::from(shown).readout(if clicked { "Clicked, pointer still over" } else { "Not clicked" })
}
#[story(ToggleButton<'static>, covers = [Mixed], drive = Drive::Never)]