Skip to content

Commit

Permalink
Fix toggle button states
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 8, 2021
1 parent e4c9d12 commit 5172342
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
38 changes: 36 additions & 2 deletions backend-embedded-graphics/src/themes/basic/toggle_button/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ toggle_button_style_binary_color!(
ToggleButton {
font: ascii::FONT_6X10,
states: {
Unchecked, Checked: {
Unchecked: {
Inactive, Idle, Pressed: {
label: On,
border: On,
background: Off,
},
Hovered: {
label: Off,
border: Off,
background: On,
}
},
Checked: {
Inactive, Idle, Pressed: {
label: Off,
border: On,
Expand All @@ -26,7 +38,29 @@ toggle_button_style_rgb!(
ToggleButton {
font: ascii::FONT_6X10,
states: {
Unchecked, Checked: {
Unchecked: {
Inactive: {
label: CSS_LIGHT_GRAY,
border: CSS_DIM_GRAY,
background: CSS_DIM_GRAY,
},
Idle: {
label: WHITE,
border: CSS_SLATE_GRAY,
background: CSS_SLATE_GRAY,
},
Hovered: {
label: WHITE,
border: CSS_LIGHT_SLATE_GRAY,
background: CSS_LIGHT_SLATE_GRAY,
},
Pressed: {
label: WHITE,
border: CSS_STEEL_BLUE,
background: CSS_STEEL_BLUE,
}
},
Checked: {
Inactive: {
label: CSS_LIGHT_GRAY,
border: CSS_DIM_GRAY,
Expand Down
19 changes: 9 additions & 10 deletions backend-embedded-graphics/src/themes/basic/toggle_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use embedded_gui::{
widgets::{
background::{Background, BackgroundProperties},
border::{Border, BorderProperties},
button::Button,
fill::{Center, FillParent, HorizontalAndVertical},
label::Label,
spacing::Spacing,
Expand Down Expand Up @@ -140,11 +139,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
where
Label<S, T>: LabelStyling<S, Color = C>,
{
if state.has_state(Button::STATE_INACTIVE) {
if state.has_state(Toggle::STATE_INACTIVE) {
Self::Inactive::apply_label(label);
} else if state.has_state(Button::STATE_HOVERED) {
} else if state.has_state(Toggle::STATE_HOVERED) {
Self::Hovered::apply_label(label);
} else if state.has_state(Button::STATE_PRESSED) {
} else if state.has_state(Toggle::STATE_PRESSED) {
Self::Pressed::apply_label(label);
} else {
Self::Idle::apply_label(label);
Expand All @@ -156,11 +155,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
T: BorderProperties<Color = C>,
W: Widget,
{
if state.has_state(Button::STATE_INACTIVE) {
if state.has_state(Toggle::STATE_INACTIVE) {
Self::Inactive::apply_border(border);
} else if state.has_state(Button::STATE_HOVERED) {
} else if state.has_state(Toggle::STATE_HOVERED) {
Self::Hovered::apply_border(border);
} else if state.has_state(Button::STATE_PRESSED) {
} else if state.has_state(Toggle::STATE_PRESSED) {
Self::Pressed::apply_border(border);
} else {
Self::Idle::apply_border(border);
Expand All @@ -172,11 +171,11 @@ pub trait ToggleButtonStateStyle<C: PixelColor> {
T: BackgroundProperties<Color = C>,
W: Widget,
{
if state.has_state(Button::STATE_INACTIVE) {
if state.has_state(Toggle::STATE_INACTIVE) {
Self::Inactive::apply_background(background);
} else if state.has_state(Button::STATE_HOVERED) {
} else if state.has_state(Toggle::STATE_HOVERED) {
Self::Hovered::apply_background(background);
} else if state.has_state(Button::STATE_PRESSED) {
} else if state.has_state(Toggle::STATE_PRESSED) {
Self::Pressed::apply_background(background);
} else {
Self::Idle::apply_background(background);
Expand Down

0 comments on commit 5172342

Please sign in to comment.