bevy_ui_builders/styles/
button_styles.rs1use bevy::prelude::*;
4use super::colors;
5use super::dimensions;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ButtonStyle {
10 Primary,
12 Secondary,
14 Danger,
16 Success,
18 Warning,
20 Ghost,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum ButtonSize {
27 Small,
29 Medium,
31 Large,
33 XLarge,
35}
36
37impl ButtonStyle {
38 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 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 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 pub fn text_color(&self) -> Color {
76 match self {
77 ButtonStyle::Ghost => colors::TEXT_SECONDARY,
78 _ => Color::WHITE,
79 }
80 }
81
82 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 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 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 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}