Skip to main content

ButtonSkin

Struct ButtonSkin 

Source
pub struct ButtonSkin {
    pub idle: NineSliceImage,
    pub hovered: NineSliceImage,
    pub pressed: NineSliceImage,
}
Expand description

Re-exported for the same reason as Menu: MenuSkin’s buttons are a ButtonSkin drawn per ButtonState, and its insets are SkinInsets. The art a skinned button draws: one nine-sliced image per ButtonState.

   idle              hovered           pressed
  ┌──┬────────┬──┐  ┌──┬────────┬──┐  ┌──┬────────┬──┐
  │  │        │  │  │  │        │  │  │  │        │  │
  ├──┤  Play  ├──┤  ├──┤  Play  ├──┤  ├──┤  Play  ├──┤
  │  │        │  │  │  │        │  │  │  │        │  │
  └──┴────────┴──┘  └──┴────────┴──┘  └──┴────────┴──┘
   three pictures — pressing swaps art, it does not tint

Three pictures rather than one picture and three tints, because that is what the feature is for. A tint can only darken or lighten uniformly; separate frames let a pressed button have a sunken bevel, a different highlight, or a shadow that moved — none of which is a multiply.

draw emits the frame for a state into a DrawList as textured quads, so the frame and the label on it are drawn by one pass in the order they were pushed: frame first, label over it.

Fields§

§idle: NineSliceImage

The frame drawn at rest.

§hovered: NineSliceImage

The frame drawn under the cursor or the keyboard’s selection.

§pressed: NineSliceImage

The frame drawn while the button holds the press.

Implementations§

Source§

impl ButtonSkin

Source

pub const fn uniform(frame: NineSliceImage) -> ButtonSkin

One frame for every state — a skin that does not react.

Source

pub const fn frame(&self, state: ButtonState) -> &NineSliceImage

The frame state draws.

Source

pub fn insets(&self) -> SkinInsets

The insets to hand Button::with_skin, in texels.

Read off the idle frame, and off its clamped insets rather than its declared ones, so the layout agrees with the geometry that will actually be drawn. Idle specifically, and not “whichever state is current”: a button whose minimum size changed with the cursor would resize as the mouse crossed it. insets_agree is there for a skin whose frames might not.

Source

pub fn insets_agree(&self) -> bool

Whether all three frames have the same clamped insets.

Source

pub fn draw( &self, dl: &mut DrawList, state: ButtonState, min: Vec2, max: Vec2, scale: f32, )

Pushes state’s frame stretched to min..max, at scale screen pixels per texel of its fixed bands — see DrawList::nine_slice.

Trait Implementations§

Source§

impl Clone for ButtonSkin

Source§

fn clone(&self) -> ButtonSkin

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 ButtonSkin

Source§

impl Debug for ButtonSkin

Source§

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

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

impl PartialEq for ButtonSkin

Source§

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

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.