Skip to content

Commit 6ae064e

Browse files
committed
Styled toggle button
1 parent 543ba4b commit 6ae064e

3 files changed

Lines changed: 411 additions & 0 deletions

File tree

backend-embedded-graphics/src/themes/basic/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
33
pub mod button;
44
pub mod label;
5+
pub mod toggle_button;
56

67
use crate::themes::basic::{
78
button::{
89
styled_button, styled_button_stretched, ButtonStyle, StyledButton, StyledButtonStretched,
910
},
1011
label::{styled_label, LabelStyle, StyledLabel},
12+
toggle_button::{
13+
styled_toggle_button, styled_toggle_button_stretched, StyledToggleButton,
14+
StyledToggleButtonStretched, ToggleButtonStyle,
15+
},
1116
};
1217
use embedded_graphics::prelude::PixelColor;
1318

@@ -17,6 +22,7 @@ pub trait BasicTheme: Sized {
1722
type LabelStyle: LabelStyle<Self::PixelColor>;
1823
type PrimaryButton: ButtonStyle<Self::PixelColor>;
1924
type SecondaryButton: ButtonStyle<Self::PixelColor>;
25+
type ToggleButton: ToggleButtonStyle<Self::PixelColor>;
2026

2127
fn label<S: AsRef<str>>(label: S) -> StyledLabel<S, Self::PixelColor> {
2228
styled_label::<Self, Self::LabelStyle, _>(label)
@@ -37,6 +43,16 @@ pub trait BasicTheme: Sized {
3743
fn secondary_button_stretched(label: &'static str) -> StyledButtonStretched<Self::PixelColor> {
3844
styled_button_stretched::<Self, Self::SecondaryButton>(label)
3945
}
46+
47+
fn toggle_button(label: &'static str) -> StyledToggleButton<Self::PixelColor> {
48+
styled_toggle_button::<Self, Self::ToggleButton>(label)
49+
}
50+
51+
fn toggle_button_stretched(
52+
label: &'static str,
53+
) -> StyledToggleButtonStretched<Self::PixelColor> {
54+
styled_toggle_button_stretched::<Self, Self::ToggleButton>(label)
55+
}
4056
}
4157

4258
/// This macro is used to define the theme structure.
@@ -51,6 +67,7 @@ macro_rules! impl_theme {
5167
$theme_module::$color_mod::SecondaryButton,
5268
},
5369
label::$theme_module::$color_mod::Label,
70+
toggle_button::$theme_module::$color_mod::ToggleButton,
5471
BasicTheme,
5572
};
5673

@@ -61,6 +78,7 @@ macro_rules! impl_theme {
6178
type LabelStyle = Label;
6279
type PrimaryButton = PrimaryButton;
6380
type SecondaryButton = SecondaryButton;
81+
type ToggleButton = ToggleButton;
6482
}
6583
}
6684
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//! Light theme for buttons.
2+
3+
use crate::toggle_button_style_rgb;
4+
5+
pub mod binary_color {
6+
use crate::toggle_button_style;
7+
use embedded_graphics::{
8+
mono_font::{ascii::FONT_6X10, MonoFont},
9+
pixelcolor::BinaryColor,
10+
};
11+
12+
toggle_button_style!(
13+
ToggleButton<BinaryColor, FONT_6X10> {
14+
Unchecked {
15+
Inactive {
16+
label: Off,
17+
border: On,
18+
background: On,
19+
},
20+
Idle {
21+
label: Off,
22+
border: On,
23+
background: On,
24+
},
25+
Hovered {
26+
label: On,
27+
border: On,
28+
background: Off,
29+
},
30+
Pressed {
31+
label: Off,
32+
border: On,
33+
background: On,
34+
}
35+
},
36+
Checked {
37+
Inactive {
38+
label: Off,
39+
border: On,
40+
background: On,
41+
},
42+
Idle {
43+
label: Off,
44+
border: On,
45+
background: On,
46+
},
47+
Hovered {
48+
label: On,
49+
border: On,
50+
background: Off,
51+
},
52+
Pressed {
53+
label: Off,
54+
border: On,
55+
background: On,
56+
}
57+
}
58+
}
59+
);
60+
}
61+
62+
toggle_button_style_rgb!(
63+
ToggleButton<FONT_6X10> {
64+
Unchecked {
65+
Inactive {
66+
label: CSS_LIGHT_GRAY,
67+
border: CSS_DIM_GRAY,
68+
background: CSS_DIM_GRAY,
69+
},
70+
Idle {
71+
label: WHITE,
72+
border: CSS_STEEL_BLUE,
73+
background: CSS_STEEL_BLUE,
74+
},
75+
Hovered {
76+
label: WHITE,
77+
border: CSS_DODGER_BLUE,
78+
background: CSS_DODGER_BLUE,
79+
},
80+
Pressed {
81+
label: WHITE,
82+
border: CSS_LIGHT_STEEL_BLUE,
83+
background: CSS_LIGHT_STEEL_BLUE,
84+
}
85+
},
86+
Checked {
87+
Inactive {
88+
label: CSS_LIGHT_GRAY,
89+
border: CSS_DIM_GRAY,
90+
background: CSS_DIM_GRAY,
91+
},
92+
Idle {
93+
label: WHITE,
94+
border: CSS_STEEL_BLUE,
95+
background: CSS_STEEL_BLUE,
96+
},
97+
Hovered {
98+
label: WHITE,
99+
border: CSS_DODGER_BLUE,
100+
background: CSS_DODGER_BLUE,
101+
},
102+
Pressed {
103+
label: WHITE,
104+
border: CSS_LIGHT_STEEL_BLUE,
105+
background: CSS_LIGHT_STEEL_BLUE,
106+
}
107+
}
108+
}
109+
);

0 commit comments

Comments
 (0)