Openers show open while the container they opened shows

A control from which a click, press or held press opened a menu or popover
takes Flags::OPEN while it is open, and OPEN now drives the press blend it
counts as, so the control draws its pressed plate and reports expanded. A
part whose popup is open (a split button's arrow) does the same. Context
menus, hover cards and bound containers leave their host unmarked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-29 21:46:40 +00:00
1 parent f37e93403a
commit e3614bb25b
5 files changed
+43 -4

No files matched your search

+7 -2
View File
@@ -81,12 +81,16 @@ impl CxCore<'_> {
flags |= Flags::FOCUS_VISIBLE;
}
}
// A part whose popup is open (a split button's arrow while its menu shows) shows open, as a control does.
if self.toggles.iter().any(|toggle| toggle.part == part && toggle.open) {
flags |= Flags::OPEN;
}
let pressed = result.pressed();
let state = if !self.looks_enabled() || result.inactive {
craft_theme::State::Disabled
} else if !self.resolved.enabled {
craft_theme::State::Rest
} else if pressed {
} else if pressed || flags.contains(Flags::OPEN) {
craft_theme::State::Pressed
} else if hovered {
craft_theme::State::Hover
@@ -94,7 +98,8 @@ impl CxCore<'_> {
craft_theme::State::Rest
};
let on = flags.intersects(Flags::ON);
let t = craft_theme::StateMix::new(f32::from(u8::from(hovered)), f32::from(u8::from(pressed)), f32::from(u8::from(on)));
let shows_pressed = pressed || state == craft_theme::State::Pressed;
let t = craft_theme::StateMix::new(f32::from(u8::from(hovered)), f32::from(u8::from(shows_pressed)), f32::from(u8::from(on)));
StateSet::new(state, flags, t)
}
}
@@ -69,6 +69,14 @@ pub fn opened_from(ctx: &egui::Context, opener: Id) -> bool {
MemoryStage::peek_session::<OpenerOpen>(ctx, sub(opener, "opens")).open
}
/// Whether the opener `opener` shows the container hung from it as open (`Flags::OPEN`, drawn pressed): the container
/// is open and a click, press or held press of this opener opened it. A context menu, a hover card and a container
/// only its binding opens leave the control they hang from unmarked.
pub(crate) fn shows_open(ctx: &egui::Context, opener: Id) -> bool {
let slot = MemoryStage::peek_session::<OpenerOpen>(ctx, sub(opener, "opens"));
slot.open && slot.by.is_some_and(|(by, trigger, _)| by == opener && matches!(trigger, Trigger::Click | Trigger::Press | Trigger::Hold))
}
/// Writes the opener's slot: the container closed itself (Escape, a press outside, a row ran).
pub(crate) fn set_opener_open(stage: &mut MemoryStage, opener: &Opener, open: bool) {
stage.session::<OpenerOpen>(sub(opener.id, "opens")).open = open;
+2 -1
View File
@@ -1257,7 +1257,8 @@ fn state_steps(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, env: &Env, h: &HostStep) {
e.register_reset();
// 12 state
p.trace.mark(Step::State);
let open = facts.overlays && overlay::popup_shown(&h.ctx, h.id);
// A control shows open while one of its own popups shows, or while a container hung from it is open.
let open = (facts.overlays && overlay::popup_shown(&h.ctx, h.id)) || crate::contract::overlay::container_open::shows_open(&h.ctx, h.id);
let expanded = e.expanded() == Some(true);
steps::state(e, style, open, expanded, env.ink);
if e.core_ref().state.flags.contains(crate::style::Flags::FOCUSED) {
@@ -117,7 +117,8 @@ pub(crate) fn state(p: &mut dyn ErasedPass<'_>, style: &dyn StyleView, open: boo
let core = p.core();
*core.memory.shown::<Hover>(super::ShownState::hover_slot(core.id)) = report;
}
let t = ease(p, [hovered, pressed, flags.intersects(Flags::ON)]);
// An open control (`Flags::OPEN`) shows the press it counts as.
let t = ease(p, [hovered, pressed || state == State::Pressed, flags.intersects(Flags::ON)]);
let core = p.core();
core.state = StateSet::new(state, flags, t);
core.ink = surface_ink(style.surface(), &core.state, inherited);
+24
View File
@@ -386,6 +386,30 @@ fn a_filled_value_menu_fills_the_current_row_and_draws_no_radio_marks() {
assert!(fills_in(&shapes, fit).is_empty(), "another row paints no fill");
}
/// A button whose menu is open shows it: it paints the pressed plate while the menu shows, with the pointer away, and
/// none once the menu has closed.
#[trial]
fn a_button_shows_open_while_the_menu_it_opened_shows() {
let mut fixture = Fixture::new(|ui| {
let opener = Button::new("Effects").show(ui);
Menu::new("Effects").opened_by(&opener, Trigger::Click).show(ui, |ui, _| {
MenuItem::new("Glow").show(ui);
});
});
fixture.settle();
let opener = fixture.by_label("Effects").expect("the opener").rect;
let away = opener.right_bottom() + egui::vec2(200.0, 200.0);
let rest = fills_in(&fixture.frame_shapes_with(vec![pointer::moved(away)]), opener);
fixture.click_at(opener.center()).settle();
fixture.frame(vec![pointer::moved(fixture.by_label("Glow").expect("the menu is open").rect.center())]);
fixture.settle();
let open = fills_in(&fixture.frame_shapes(), opener);
assert!(open.len() > rest.len(), "the opener paints a plate while its menu is open: {open:?} against {rest:?}");
fixture.key(egui::Key::Escape, egui::Modifiers::NONE).settle();
let closed = fills_in(&fixture.frame_shapes_with(vec![pointer::moved(away)]), opener);
assert_eq!(closed, rest, "the plate goes with the menu");
}
/// A label long enough that a menu of it is wider than a popup's least width, so a sample column shows in the width.
const LONG: &str = "Neue Grotesk Display Condensed Extra Light Italic";