pub struct MenuBarState { /* private fields */ }Expand description
Which label’s popup is open (if any) for a MenuBar, plus that
popup’s own MenuState.
A menu bar has at most one open popup at a time, so this wraps a single MenuState rather
than one per label: switching which label is open always goes through open,
which closes whatever was open first. Holds no reference to the bar’s own titles/rows, the
same design MenuState itself uses: every method that needs to know a label’s row count
takes len and a selectable predicate rather than a concrete row type, so this stays
reusable across whatever row type a call site’s MenuBar uses.
open_label is gated on MenuState::is_open rather than tracked as an
independent flag: MenuState::handle_event (Escape) and
Menu::show (an outside click, or a row activation) already
close the inner MenuState on the caller’s behalf, and gating the getter this way means
those paths automatically clear which label reads as open too, with nothing to keep in sync
by hand.
§Examples
use retroglyph_ui::state::MenuBarState;
// Two labels, each with one selectable row.
let selectable = |_: usize| true;
let mut state = MenuBarState::new();
state.open(0, 1, selectable);
assert_eq!(state.open_label(), Some(0));
// Hovering another label while one is open switches to it (see `MenuBar::show`); modeled
// here directly as another `open` call.
state.open(1, 1, selectable);
assert_eq!(state.open_label(), Some(1));
state.close();
assert_eq!(state.open_label(), None);Implementations§
Source§impl MenuBarState
impl MenuBarState
Sourcepub const fn open_label(&self) -> Option<usize>
pub const fn open_label(&self) -> Option<usize>
The label whose popup is currently open, if any. See the type docs for why this is
derived from MenuState::is_open rather than stored independently.
The open popup’s own state, for driving it through
Menu::show.
Mutable access to the open popup’s own state, for driving it through
Menu::show.
Sourcepub fn open(
&mut self,
label: usize,
len: usize,
selectable: impl Fn(usize) -> bool,
)
pub fn open( &mut self, label: usize, len: usize, selectable: impl Fn(usize) -> bool, )
Open label’s popup, selecting its first selectable row among 0..len (skipping any
leading separators/labels), closing whatever label’s popup was open first. A no-op
(closes without opening the new label) if label has no selectable row at all, mirroring
MenuState::open.
Sourcepub fn hover(
&mut self,
label: Option<usize>,
len: usize,
selectable: impl Fn(usize) -> bool,
)
pub fn hover( &mut self, label: Option<usize>, len: usize, selectable: impl Fn(usize) -> bool, )
Switch to label’s popup, but only on the frame label first differs from what
hover resolved to last time this was called – a no-op both while a
pointer sits still over the same label across frames, and while no popup is open at all
(a cold hover; see MenuBar’s docs). See the hover field’s
own doc comment for why this edge-triggering, rather than a fresh “is label different
from what’s open” check every frame, is what keeps this from fighting a
MenuBar::handle_event keyboard switch.
Trait Implementations§
Source§impl Clone for MenuBarState
impl Clone for MenuBarState
Source§fn clone(&self) -> MenuBarState
fn clone(&self) -> MenuBarState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MenuBarState
Source§impl Debug for MenuBarState
impl Debug for MenuBarState
Source§impl Default for MenuBarState
impl Default for MenuBarState
Source§fn default() -> MenuBarState
fn default() -> MenuBarState
impl Eq for MenuBarState
Source§impl PartialEq for MenuBarState
impl PartialEq for MenuBarState
Source§fn eq(&self, other: &MenuBarState) -> bool
fn eq(&self, other: &MenuBarState) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for MenuBarState
Auto Trait Implementations§
impl Freeze for MenuBarState
impl RefUnwindSafe for MenuBarState
impl Send for MenuBarState
impl Sync for MenuBarState
impl Unpin for MenuBarState
impl UnsafeUnpin for MenuBarState
impl UnwindSafe for MenuBarState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).