Skip to main content

MainMenu

Struct MainMenu 

Source
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: String

Optional heading drawn above the items. Empty draws no heading.

§initial: bool

Show the menu as soon as the world loads. Off by default: the scene shows first and the toggle key opens the menu.

§toggle_key: String

InputKey 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: bool

Horizontally 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: f32

Column center x in reference-space pixels, used when centered is false.

§y: f32

Top of the first item in reference-space pixels, used when centered is false.

§button_width: f32

Width of each item’s clickable region in pixels.

§button_height: f32

Height of each item’s clickable region in pixels.

§row_gap: f32

Pixels between adjacent items.

§font: String

Font for the item text. Empty uses the built-in font.

§font_px: f32

Pixel 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: f32

Scale applied to the item text.

§hover_color: [f32; 3]

RGB color of an item’s text while it is hovered.

§hover_scale: f32

Multiplier 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: bool

Draw 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: f32

Arrow cursor height in pixels (its width follows the arrow’s shape).

§settings_profile: SettingsProfile

Which 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: String

Action 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§

Source§

impl Authored for MainMenu

Source§

const TYPE: &'static str = "MainMenu"

The registered asset type, as it appears in a world line’s type.
Source§

impl BuildOnlyAsset for MainMenu

Source§

impl Clone for MainMenu

Source§

fn clone(&self) -> MainMenu

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 MainMenu

Source§

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

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

impl Default for MainMenu

Source§

fn default() -> MainMenu

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

impl<'de> Deserialize<'de> for MainMenu

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<MainMenu, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MainMenu

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> AutoreleaseSafe for T
where T: ?Sized,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more