Skip to main content

MenuBarState

Struct MenuBarState 

Source
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

Source

pub const fn new() -> Self

A closed menu bar: no label open.

Source

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.

Source

pub const fn menu(&self) -> &MenuState

The open popup’s own state, for driving it through Menu::show.

Source

pub const fn menu_mut(&mut self) -> &mut MenuState

Mutable access to the open popup’s own state, for driving it through Menu::show.

Source

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.

Source

pub const fn close(&mut self)

Close whichever label’s popup is open. A no-op if none is.

Source

pub fn toggle( &mut self, label: usize, len: usize, selectable: impl Fn(usize) -> bool, )

close if label’s popup is already open, otherwise open it.

Source

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

Source§

fn clone(&self) -> MenuBarState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MenuBarState

Source§

impl Debug for MenuBarState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MenuBarState

Source§

fn default() -> MenuBarState

Returns the “default value” for a type. Read more
Source§

impl Eq for MenuBarState

Source§

impl PartialEq for MenuBarState

Source§

fn eq(&self, other: &MenuBarState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MenuBarState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).