Skip to main content

Button

Struct Button 

Source
pub struct Button {
Show 29 fields pub label: Option<Text>, pub label_size: f32, pub text_alignment: Alignment, pub pos_x: usize, pub pos_y: usize, pub width: usize, pub height: usize, pub border_size_idle: usize, pub border_size_hovered: usize, pub border_size_clicked: usize, pub shadow_size_idle: usize, pub shadow_size_hovered: usize, pub shadow_size_clicked: usize, pub shadow_intensity_idle: u8, pub shadow_intensity_hovered: u8, pub shadow_intensity_clicked: u8, pub label_col_idle: Color, pub border_col_idle: Color, pub bg_col_idle: Color, pub label_col_hovered: Color, pub border_col_hovered: Color, pub bg_col_hovered: Color, pub label_col_clicked: Color, pub border_col_clicked: Color, pub bg_col_clicked: Color, pub button_type: ButtonType, pub state: ButtonState, pub toggled: bool, pub radius: usize,
}

Fields§

§label: Option<Text>§label_size: f32§text_alignment: Alignment§pos_x: usize

The Button’s horizontal position in pixels

§pos_y: usize

The Button’s vertical position in pixels

§width: usize

The Button’s width in pixels

§height: usize

The Button’s height in pixels

§border_size_idle: usize

The Button’s border size for when the Button is idle

§border_size_hovered: usize

The Button’s border size for when the Button is hovered

§border_size_clicked: usize

The Button’s border size for when the Button is clicked

§shadow_size_idle: usize

Button-wide shadow size

§shadow_size_hovered: usize

Button-wide shadow size when hoverd

§shadow_size_clicked: usize

Button-wide shadow size when clicked

§shadow_intensity_idle: u8

How intense the shadows should be

§shadow_intensity_hovered: u8

How intense the shadows should be when hovered

§shadow_intensity_clicked: u8

How intense the shadows should be when clicked

§label_col_idle: Color

The color of the Button’s label

§border_col_idle: Color

The color of the Button’s border

§bg_col_idle: Color

The color of the Button’s background

§label_col_hovered: Color

The color of the Button’s label when hovered

§border_col_hovered: Color

The color of the Button’s border when hovered

§bg_col_hovered: Color

The color of the Button’s background when hovered

§label_col_clicked: Color

The color of the Button’s label when clicked

§border_col_clicked: Color

The color of the Button’s border when clicked

§bg_col_clicked: Color

The color of the Button’s background when clicked

§button_type: ButtonType

Whether the Button is a push button or a toggle button

§state: ButtonState

The current state of the Button. Can be Idle, Hovered or Clicked

§toggled: bool

Whether the toggle button is currently toggled on (only relevant for ButtonType::Toggle)

§radius: usize

Corner radius for rounded edges

Implementations§

Source§

impl Button

Source

pub fn label(self, text: &str, font: Font, size: f32) -> Self

Sets the text to be displayed inside the button

Source

pub fn label_alignment(self, alignment: Alignment) -> Self

Determines whether the button label is left-aligned, right-aligned or centered

Source

pub fn position(self, x: usize, y: usize) -> Self

Sets the position of the button inside the window in pixel coordinates

Source

pub fn size(self, width: usize, height: usize) -> Self

Sets the size of the button in pixels

Source

pub fn border(self, size: usize) -> Self

Sets the thickness of the Button’s borders in pixels

Source

pub fn shadow(self, size: usize, intensity: u8) -> Self

Determines whether to draw shadows and how large and intense they should be Sets values for idle, hovered and clicked state

Source

pub fn idle_shadow(self, size: usize, intensity: u8) -> Self

Specifically sets the idle shadow size and intensity

Source

pub fn hover_shadow(self, size: usize, intensity: u8) -> Self

Specifically sets the shadow size and intensity for when the Button is hovered

Source

pub fn click_shadow(self, size: usize, intensity: u8) -> Self

Specifically sets the shadow size and intensity for when the Button is clicked

Source

pub fn label_color(self, color: Color) -> Self

Sets the label text color for idle, hovered and clicked state

Source

pub fn idle_label_col(self, color: Color) -> Self

Specifically sets the label color for when the Button is idle

Source

pub fn hover_label_col(self, color: Color) -> Self

Specifically sets the label color for when the Button is hovered

Source

pub fn click_label_col(self, color: Color) -> Self

Specifically sets the label color for when the Button is clicked

Source

pub fn border_color(self, color: Color) -> Self

Sets the border color for idle, hovered and clicked state

Source

pub fn background(self, color: Color) -> Self

Sets the button’s background color for idle, hovered and clicked state

Source

pub fn idle_bg(self, color: Color) -> Self

Specifically sets the background color for when the Button is idle

Source

pub fn hover_bg(self, color: Color) -> Self

Specifically sets the background color for when the Button is hovered

Source

pub fn click_bg(self, color: Color) -> Self

Specifically sets the background color for when the Button is clicked

Source

pub fn button_type(self, button_type: ButtonType) -> Self

Determines whether the button is a push button or toggle button

Source

pub fn radius(self, radius: usize) -> Self

Sets the corner radius for rounded edges

Source

pub fn is_hovered(&self, window: &Window) -> bool

Source

pub fn is_left_clicked(&self, window: &Window) -> bool

Source

pub fn is_right_clicked(&self, window: &Window) -> bool

Source

pub fn draw(&mut self, window: &mut Window)

Draws the button to a window

Trait Implementations§

Source§

impl Default for Button

Source§

fn default() -> Button

Returns the “default value” for a type. 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.