bevy_ui_builders/styles/
button_styles.rs

1//! Button style definitions
2
3use bevy::prelude::*;
4use super::colors;
5use super::dimensions;
6
7/// Button style variants for consistent theming
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ButtonStyle {
10    /// Primary action buttons (blue)
11    Primary,
12    /// Secondary action buttons (gray)
13    Secondary,
14    /// Destructive action buttons (red)
15    Danger,
16    /// Positive action buttons (green)
17    Success,
18    /// Cautionary action buttons (yellow)
19    Warning,
20    /// Transparent with border only
21    Ghost,
22}
23
24/// Button size variants
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum ButtonSize {
27    /// Small buttons for compact UI
28    Small,
29    /// Default button size
30    Medium,
31    /// Large buttons for prominent actions
32    Large,
33    /// Extra large buttons for hero sections
34    XLarge,
35}
36
37impl ButtonStyle {
38    /// Get the base color for this button style
39    pub fn base_color(&self) -> Color {
40        match self {
41            ButtonStyle::Primary => colors::PRIMARY,
42            ButtonStyle::Secondary => colors::SECONDARY,
43            ButtonStyle::Danger => colors::DANGER,
44            ButtonStyle::Success => colors::SUCCESS,
45            ButtonStyle::Warning => colors::WARNING,
46            ButtonStyle::Ghost => Color::NONE,
47        }
48    }
49
50    /// Get the hover color for this button style
51    pub fn hover_color(&self) -> Color {
52        match self {
53            ButtonStyle::Primary => colors::PRIMARY_HOVER,
54            ButtonStyle::Secondary => colors::SECONDARY_HOVER,
55            ButtonStyle::Danger => colors::DANGER_HOVER,
56            ButtonStyle::Success => colors::SUCCESS_HOVER,
57            ButtonStyle::Warning => colors::WARNING_HOVER,
58            ButtonStyle::Ghost => colors::GHOST_HOVER,
59        }
60    }
61
62    /// Get the pressed color for this button style
63    pub fn pressed_color(&self) -> Color {
64        match self {
65            ButtonStyle::Primary => colors::PRIMARY_PRESSED,
66            ButtonStyle::Secondary => colors::SECONDARY_PRESSED,
67            ButtonStyle::Danger => colors::DANGER_PRESSED,
68            ButtonStyle::Success => colors::SUCCESS_PRESSED,
69            ButtonStyle::Warning => colors::WARNING_PRESSED,
70            ButtonStyle::Ghost => colors::GHOST_PRESSED,
71        }
72    }
73
74    /// Get the text color for this button style
75    pub fn text_color(&self) -> Color {
76        match self {
77            ButtonStyle::Ghost => colors::TEXT_SECONDARY,
78            _ => Color::WHITE,
79        }
80    }
81
82    /// Get the border color for this button style
83    pub fn border_color(&self) -> Color {
84        match self {
85            ButtonStyle::Primary => colors::PRIMARY_DARK,
86            ButtonStyle::Secondary => colors::BORDER_DEFAULT,
87            ButtonStyle::Danger => colors::DANGER_DARK,
88            ButtonStyle::Success => colors::SUCCESS_DARK,
89            ButtonStyle::Warning => colors::WARNING_PRESSED,
90            ButtonStyle::Ghost => colors::BORDER_DEFAULT,
91        }
92    }
93}
94
95impl ButtonSize {
96    /// Get the width for this button size
97    pub fn width(&self) -> Val {
98        match self {
99            ButtonSize::Small => Val::Px(dimensions::BUTTON_WIDTH_SMALL),
100            ButtonSize::Medium => Val::Px(dimensions::BUTTON_WIDTH_MEDIUM),
101            ButtonSize::Large => Val::Px(dimensions::BUTTON_WIDTH_LARGE),
102            ButtonSize::XLarge => Val::Px(dimensions::BUTTON_WIDTH_XLARGE),
103        }
104    }
105
106    /// Get the height for this button size
107    pub fn height(&self) -> Val {
108        match self {
109            ButtonSize::Small => Val::Px(dimensions::BUTTON_HEIGHT_SMALL),
110            ButtonSize::Medium => Val::Px(dimensions::BUTTON_HEIGHT_MEDIUM),
111            ButtonSize::Large => Val::Px(dimensions::BUTTON_HEIGHT_LARGE),
112            ButtonSize::XLarge => Val::Px(dimensions::BUTTON_HEIGHT_XLARGE),
113        }
114    }
115
116    /// Get the font size for this button size
117    pub fn font_size(&self) -> f32 {
118        match self {
119            ButtonSize::Small => dimensions::FONT_SIZE_SMALL,
120            ButtonSize::Medium => dimensions::FONT_SIZE_MEDIUM,
121            ButtonSize::Large => dimensions::FONT_SIZE_LARGE,
122            ButtonSize::XLarge => dimensions::FONT_SIZE_XLARGE,
123        }
124    }
125}