Skip to main content

MenuItem

Struct MenuItem 

Source
pub struct MenuItem {
    pub id: u64,
    pub label: String,
    pub hint: String,
    pub kind: MenuItemKind,
}
Expand description

Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. One line of a menu: what it says, what key does it, and what it is called.

Fields§

§id: u64

Names this item to the caller — what Menu::activate hands back.

A WidgetId rather than an index, so a menu that grows an entry does not silently re-number what the loop is matching on.

§label: String

The label, drawn left-aligned in the button.

§hint: String

The key that also does this, drawn right-aligned and dimmer. Empty for an item with no keyboard shortcut of its own.

A hint, not a binding. This type does not read the keyboard; the game loop already owns its key handling and this is what tells the player what it is.

A MenuItemKind::Slider row has no key of its own to advertise, so this is where its value goes — the formatted number the caller refreshes as the handle moves. Right-aligned either way. A MenuItemKind::Cycler row’s is the caption of the choice it holds, which the caller refreshes as the choice changes; it is drawn between chevrons — see MenuItem::caption.

§kind: MenuItemKind

Whether this row fires or carries a value.

Implementations§

Source§

impl MenuItem

Source

pub fn new( id: u64, label: impl Into<String>, hint: impl Into<String>, ) -> MenuItem

An item with a key hint beside it.

Source

pub fn slider( id: u64, label: impl Into<String>, value: impl Into<String>, position: f32, ) -> MenuItem

A slider row: a label, a groove with its handle position of the way along, and value drawn where a key hint would be.

Source

pub fn cycler( id: u64, label: impl Into<String>, caption: impl Into<String>, count: usize, chosen: usize, ) -> MenuItem

A cycler row: a label, one of count choices with chosen picked, and that choice’s caption drawn where a key hint would be.

Source

pub fn caption(&self) -> Cow<'_, str>

What this row draws where a key hint goes.

The hint itself for a button or a slider. For a cycler, the hint between a < and a > — each present only on the side a step without a wrap would go, and replaced by blank of the same width on the side it would not, so the caption does not shift as they come and go.

Trait Implementations§

Source§

impl Clone for MenuItem

Source§

fn clone(&self) -> MenuItem

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 Debug for MenuItem

Source§

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

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

impl PartialEq for MenuItem

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MenuItem

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> HalThreadSafe for T
where T: Send + Sync,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.