pub struct MainMenu {Show 22 fields
pub items: Vec<MainMenuItem>,
pub title: String,
pub initial: bool,
pub toggle_key: String,
pub dim: [f32; 4],
pub centered: bool,
pub x: f32,
pub y: f32,
pub button_width: f32,
pub button_height: f32,
pub row_gap: f32,
pub font: String,
pub font_px: f32,
pub text_color: [f32; 3],
pub text_scale: f32,
pub hover_color: [f32; 3],
pub hover_scale: f32,
pub cursor: bool,
pub cursor_color: [f32; 4],
pub cursor_size: f32,
pub settings_profile: SettingsProfile,
pub settings_back_action: String,
}Expand description
A ready-made menu declared in a single line.
MainMenu is a build-time shorthand. It expands into the assets a menu is
built from: a Screen layer, a dim backdrop Sprite, a
TextLabel and HitRegion for each item, an
optional KeyBinding that toggles the menu, and an optional
in-engine mouse cursor Sprite. So world.jsonl stays small.
The bare form gives a centered Return / Settings / Quit menu that starts
closed, with Escape opening it, so the scene itself shows first. Set
"initial": true to show the menu as soon as the world loads:
Declaring a MainMenu also injects the StatHud (and its chip
labels) at build time when the world declares none, so the menu’s
performance-stats toggles have chips to drive.
Items. Each item has a label (the text) and an action fired on
click. action takes the same vocabulary as HitRegion
("scene:<name>", "quit", "screen:show:<name>", "screen:hide",
"screen:toggle:<name>") plus two conveniences resolved against this menu:
"return": hide this menu (the same as"screen:hide")."settings": open a generated settings sub-menu that has a Back button.
Generated names are prefixed with the menu’s name (<name>_btn_0,
<name>_label_0, <name>_cursor, …), so they never clash with
hand-authored assets and you never reference them by hand.
Fields§
§items: Vec<MainMenuItem>Menu entries, top to bottom. Each one is a clickable button.
title: StringOptional heading drawn above the items. Empty draws no heading.
initial: boolShow the menu as soon as the world loads. Off by default: the scene shows first and the toggle key opens the menu.
toggle_key: StringInputKey that toggles the menu while the cursor is free. Empty binds no key.
Only "Escape" is currently recognised by the runtime.
dim: [f32; 4]RGBA fill drawn across the whole window behind the items. Defaults to opaque black: a fully opaque alpha (1.0) hides the scene completely, which lets the renderer skip the entire world render while the menu is open, so the frame costs only the menu overlay. Lower the alpha to keep the world visible behind a translucent fade (the world then keeps rendering); an alpha of 0 draws no backdrop at all.
centered: boolHorizontally center the menu and align it to the top of the window.
When false, x is the column’s center and y is the top of the first
item.
The menu is a screen overlay laid out against a fixed reference resolution and uniformly scaled to fill the window, so it keeps the same proportions at any window size. All pixel fields below are in that reference space, not raw window pixels.
x: f32Column center x in reference-space pixels, used when centered is false.
y: f32Top of the first item in reference-space pixels, used when centered is
false.
Width of each item’s clickable region in pixels.
Height of each item’s clickable region in pixels.
row_gap: f32Pixels between adjacent items.
font: StringFont for the item text. Empty uses the built-in font.
font_px: f32Pixel size of the item text when this menu emits its own built-in font
(that is, when font is empty). Ignored when font names a
Font, which carries its own size. In reference-space pixels.
text_color: [f32; 3]Linear-space RGB color of the item text.
text_scale: f32Scale applied to the item text.
hover_color: [f32; 3]RGB color of an item’s text while it is hovered.
hover_scale: f32Multiplier applied to an item’s text size while it is hovered. The
default 1.0 keeps the size and position fixed, so only the color
changes on hover; a value like 1.1 grows the hovered text by 10%.
cursor: boolDraw an in-engine arrow cursor while the menu is shown (the system cursor is hidden). When false the system cursor is used.
cursor_color: [f32; 4]RGBA fill color of the arrow cursor. A contrasting outline is added automatically so it stays legible over any scene.
cursor_size: f32Arrow cursor height in pixels (its width follows the arrow’s shape).
settings_profile: SettingsProfileWhich settings screen the "settings" item generates. full is the
complete Video / Audio / Controls set a 3D world configures; minimal
is the trimmed Video (window mode, resolution, vsync, frame rate) and
Audio (volume) set that fits a world with nothing to render into (a
visual-novel story, say), dropping the Controls tab and every
scene-render group.
settings_back_action: StringAction fired by the settings screen’s Back button, overriding the
default (which returns to this menu). Setting it also generates the
settings screen even when no item uses the "settings" convenience, so
a caller that opens settings by its own action (a story, say) still gets
the screen. Empty keeps the default Back-to-menu behavior.
Trait Implementations§
impl BuildOnlyAsset for MainMenu
Source§impl<'de> Deserialize<'de> for MainMenu
impl<'de> Deserialize<'de> for MainMenu
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for MainMenu
impl RefUnwindSafe for MainMenu
impl Send for MainMenu
impl Sync for MainMenu
impl Unpin for MainMenu
impl UnsafeUnpin for MainMenu
impl UnwindSafe for MainMenu
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more