Skip to main content

MenuStyle

Struct MenuStyle 

Source
pub struct MenuStyle {
Show 21 fields pub scale: f32, pub panel: SkinInsets, pub button: SkinInsets, pub panel_padding: Vec2, pub button_padding: Vec2, pub item_gap: f32, pub title_gap: f32, pub title_size: f32, pub item_size: f32, pub hint_gap: f32, pub track_width: f32, pub track_height: f32, pub handle_size: Vec2, pub title_color: [f32; 4], pub label_color: [f32; 4], pub hint_color: [f32; 4], pub warning_color: [f32; 4], pub track_color: [f32; 4], pub fill_color: [f32; 4], pub handle_color: [f32; 4], pub scrim_color: [f32; 4],
}
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. Every length a menu is laid out with, in pixels.

Built from a whole-number scale by MenuStyle::pixel_art: the art is pixel art and the panel is drawn at one texel per scale device pixels, so every gap, pad and font size is a base metric times the same integer. A fractional scale would put a nine-slice’s fixed corner on a half pixel, which is the one thing SampleMode::Pixel cannot hide.

Fields§

§scale: f32

Device pixels per texel of the menu art.

§panel: SkinInsets

The window frame’s fixed corners, in pixels.

§button: SkinInsets

A button skin’s fixed corners, in pixels.

§panel_padding: Vec2

Space between the panel’s frame and its contents.

§button_padding: Vec2

Space between a button’s frame and its label.

§item_gap: f32

Vertical space between two buttons.

§title_gap: f32

Vertical space between the title and the first button.

§title_size: f32

The title’s font size.

§item_size: f32

An item label’s font size.

§hint_gap: f32

The least space between an item’s label and its key hint.

§track_width: f32

The least width a Slider row’s groove is given.

A least, not a width: Menu::layout_with stretches the groove into whatever the panel’s widest row left over, so a slider beside a long label is a long slider. This is what stops it collapsing when the slider row is the widest one.

§track_height: f32

How tall a slider’s groove is drawn.

§handle_size: Vec2

The handle’s size. Its width is also the travel the groove loses at each end, so the handle stays inside the groove at both extremes.

§title_color: [f32; 4]

The title’s colour.

This and the other colours restate default.css’s menu rules, which are what draw them: a style with different colours lays out the same menu and draws it in the sheet’s. They are here for a caller measuring what a menu drew — the scrim’s alpha over a golden image, say — and the_sheet_draws_the_colours_and_the_slices_the_style_restates holds MenuStyle::pixel_art’s to the sheet’s.

§label_color: [f32; 4]

An item label’s colour. See MenuStyle::title_color.

§hint_color: [f32; 4]

A key hint’s colour — dimmer than the label it belongs to — and a CaptionTone::Hint caption’s. See MenuStyle::title_color.

§warning_color: [f32; 4]

A CaptionTone::Warning caption’s colour: the console’s amber for a warning, so a line that warns reads as one. See MenuStyle::title_color.

§track_color: [f32; 4]

A slider groove’s colour, behind the part not filled in. See MenuStyle::title_color.

§fill_color: [f32; 4]

The colour of the groove up to the handle. See MenuStyle::title_color.

§handle_color: [f32; 4]

The handle’s colour. See MenuStyle::title_color.

§scrim_color: [f32; 4]

What the frame behind the menu is dimmed with. See MenuStyle::title_color.

Implementations§

Source§

impl MenuStyle

Source

pub const MAX_SCALE: u32 = 4

The largest scale Menu::layout will choose.

Four rather than unbounded: past it the title’s glyphs are taller than a brick and the menu stops reading as part of the game.

Source

pub const MIN_FONT_SIZE: f32 = 8.0

The smallest item font size Menu::layout_with_font_fitted shrinks to, in pixels per em.

Eight: a typical face’s x-height is about half an em, so this leaves lowercase four pixels tall — the fewest the hinter can snap e, c and o apart in. A window that needs smaller text gets a scrolled list, or a MenuFitError, rather than a menu nobody can read.

Source

pub fn pixel_art(scale: u32) -> MenuStyle

The shipped look, at scale device pixels per texel.

scale is clamped to at least one — a menu drawn at zero is not a smaller menu, it is an invisible one.

Source

pub fn panel_corners(&self) -> SkinInsets

The panel’s fixed corners, in device pixels.

MenuStyle::panel itself: pixel_art pre-multiplies the texel source figure PANEL_INSETS by the scale, so the layout reads the pixel corners through this accessor the same way it always has.

Source

pub fn button_corners(&self) -> SkinInsets

A button’s fixed corners, in device pixels.

MenuStyle::button itself — see panel_corners.

Trait Implementations§

Source§

impl Clone for MenuStyle

Source§

fn clone(&self) -> MenuStyle

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 MenuStyle

Source§

impl Debug for MenuStyle

Source§

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

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

impl Default for MenuStyle

Source§

fn default() -> MenuStyle

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

impl PartialEq for MenuStyle

Source§

fn eq(&self, other: &MenuStyle) -> 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 MenuStyle

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.