Skip to content

Commit 5172342

Browse files
committed
Fix toggle button states
1 parent e4c9d12 commit 5172342

2 files changed

Lines changed: 45 additions & 12 deletions

File tree

  • backend-embedded-graphics/src/themes/basic/toggle_button

backend-embedded-graphics/src/themes/basic/toggle_button/light.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ toggle_button_style_binary_color!(
66
ToggleButton {
77
font: ascii::FONT_6X10,
88
states: {
9-
Unchecked, Checked: {
9+
Unchecked: {
10+
Inactive, Idle, Pressed: {
11+
label: On,
12+
border: On,
13+
background: Off,
14+
},
15+
Hovered: {
16+
label: Off,
17+
border: Off,
18+
background: On,
19+
}
20+
},
21+
Checked: {
1022
Inactive, Idle, Pressed: {
1123
label: Off,
1224
border: On,
@@ -26,7 +38,29 @@ toggle_button_style_rgb!(
2638
ToggleButton {
2739
font: ascii::FONT_6X10,
2840
states: {
29-
Unchecked, Checked: {
41+
Unchecked: {
42+
Inactive: {
43+
label: CSS_LIGHT_GRAY,
44+
border: CSS_DIM_GRAY,
45+
background: CSS_DIM_GRAY,
46+
},
47+
Idle: {
48+
label: WHITE,
49+
border: CSS_SLATE_GRAY,
50+
background: CSS_SLATE_GRAY,
51+
},
52+
Hovered: {
53+
label: WHITE,
54+
border: CSS_LIGHT_SLATE_GRAY,
55+
background: CSS_LIGHT_SLATE_GRAY,
56+
},
57+
Pressed: {
58+
label: WHITE,
59+
border: CSS_STEEL_BLUE,
60+
background: CSS_STEEL_BLUE,
61+
}
62+
},
63+
Checked: {
3064
Inactive: {
3165
label: CSS_LIGHT_GRAY,
3266
border: CSS_DIM_GRAY,

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use embedded_gui::{
2020
widgets::{
2121
background::{Background, BackgroundProperties},
2222
border::{Border, BorderProperties},
23-
button::Button,
2423
fill::{Center, FillParent, HorizontalAndVertical},
2524
label::Label,
2625
spacing::Spacing,
@@ -140,11 +139,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
140139
where
141140
Label<S, T>: LabelStyling<S, Color = C>,
142141
{
143-
if state.has_state(Button::STATE_INACTIVE) {
142+
if state.has_state(Toggle::STATE_INACTIVE) {
144143
Self::Inactive::apply_label(label);
145-
} else if state.has_state(Button::STATE_HOVERED) {
144+
} else if state.has_state(Toggle::STATE_HOVERED) {
146145
Self::Hovered::apply_label(label);
147-
} else if state.has_state(Button::STATE_PRESSED) {
146+
} else if state.has_state(Toggle::STATE_PRESSED) {
148147
Self::Pressed::apply_label(label);
149148
} else {
150149
Self::Idle::apply_label(label);
@@ -156,11 +155,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
156155
T: BorderProperties<Color = C>,
157156
W: Widget,
158157
{
159-
if state.has_state(Button::STATE_INACTIVE) {
158+
if state.has_state(Toggle::STATE_INACTIVE) {
160159
Self::Inactive::apply_border(border);
161-
} else if state.has_state(Button::STATE_HOVERED) {
160+
} else if state.has_state(Toggle::STATE_HOVERED) {
162161
Self::Hovered::apply_border(border);
163-
} else if state.has_state(Button::STATE_PRESSED) {
162+
} else if state.has_state(Toggle::STATE_PRESSED) {
164163
Self::Pressed::apply_border(border);
165164
} else {
166165
Self::Idle::apply_border(border);
@@ -172,11 +171,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
172171
T: BackgroundProperties<Color = C>,
173172
W: Widget,
174173
{
175-
if state.has_state(Button::STATE_INACTIVE) {
174+
if state.has_state(Toggle::STATE_INACTIVE) {
176175
Self::Inactive::apply_background(background);
177-
} else if state.has_state(Button::STATE_HOVERED) {
176+
} else if state.has_state(Toggle::STATE_HOVERED) {
178177
Self::Hovered::apply_background(background);
179-
} else if state.has_state(Button::STATE_PRESSED) {
178+
} else if state.has_state(Toggle::STATE_PRESSED) {
180179
Self::Pressed::apply_background(background);
181180
} else {
182181
Self::Idle::apply_background(background);

0 commit comments

Comments
 (0)