Skip to content

Add the current toggle state to toggler::Status::Disabled #2908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions widget/src/toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ where
}

let current_status = if self.on_toggle.is_none() {
Status::Disabled
Status::Disabled {
is_toggled: self.is_toggled,
}
} else if cursor.is_over(layout.bounds()) {
Status::Hovered {
is_toggled: self.is_toggled,
Expand Down Expand Up @@ -414,8 +416,12 @@ where
}

let bounds = toggler_layout.bounds();
let style = theme
.style(&self.class, self.last_status.unwrap_or(Status::Disabled));
let style = theme.style(
&self.class,
self.last_status.unwrap_or(Status::Disabled {
is_toggled: self.is_toggled,
}),
);

let border_radius = bounds.height / BORDER_RADIUS_RATIO;
let space = SPACE_RATIO * bounds.height;
Expand Down Expand Up @@ -495,7 +501,10 @@ pub enum Status {
is_toggled: bool,
},
/// The [`Toggler`] is disabled.
Disabled,
Disabled {
/// Indicates whether the [`Toggler`] is toggled.
is_toggled: bool,
},
}

/// The appearance of a toggler.
Expand Down Expand Up @@ -556,7 +565,13 @@ pub fn default(theme: &Theme, status: Status) -> Style {
palette.background.strong.color
}
}
Status::Disabled => palette.background.weak.color,
Status::Disabled { is_toggled } => {
if is_toggled {
palette.background.strong.color
} else {
palette.background.weak.color
}
}
};

let foreground = match status {
Expand All @@ -577,7 +592,7 @@ pub fn default(theme: &Theme, status: Status) -> Style {
palette.background.weak.color
}
}
Status::Disabled => palette.background.base.color,
Status::Disabled { .. } => palette.background.base.color,
};

Style {
Expand Down