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: u64Names 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: StringThe label, drawn left-aligned in the button.
hint: StringThe 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: MenuItemKindWhether this row fires or carries a value.
Implementations§
Source§impl MenuItem
impl MenuItem
Sourcepub fn new(
id: u64,
label: impl Into<String>,
hint: impl Into<String>,
) -> MenuItem
pub fn new( id: u64, label: impl Into<String>, hint: impl Into<String>, ) -> MenuItem
An item with a key hint beside it.
Sourcepub fn slider(
id: u64,
label: impl Into<String>,
value: impl Into<String>,
position: f32,
) -> MenuItem
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.
Sourcepub fn cycler(
id: u64,
label: impl Into<String>,
caption: impl Into<String>,
count: usize,
chosen: usize,
) -> MenuItem
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.
Sourcepub fn caption(&self) -> Cow<'_, str>
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.