feat: allow toggler to be disabled

This commit is contained in:
Antoine C 2024-09-07 01:59:45 +01:00
parent 71cd25c06d
commit 856cc5b14d
No known key found for this signature in database
GPG key ID: 452814094590F0DB
4 changed files with 27 additions and 3 deletions

2
iced

@ -1 +1 @@
Subproject commit 44407b80435788a612159613829d41a80782de9a
Subproject commit 1e48a5c8cf83bdb38d22494d46d91cac05f50a41

View file

@ -5,6 +5,7 @@
use crate::theme::{CosmicComponent, Theme, TRANSPARENT_COMPONENT};
use cosmic_theme::composite::over;
use iced::color;
use iced_core::{Background, Border, Color, Shadow, Vector};
use iced_style::application;
use iced_style::button as iced_button;
@ -858,6 +859,29 @@ impl toggler::StyleSheet for Theme {
..self.active(style, is_active)
}
}
fn disabled(&self, style: &Self::Style, is_active: bool) -> toggler::Appearance {
let theme = self.cosmic();
const HANDLE_MARGIN: f32 = 2.0;
let background: Color = if is_active {
theme.accent.base.into()
} else {
theme.palette.neutral_5.into()
};
let foreground: Color = theme.palette.neutral_2.into();
toggler::Appearance {
background: Color::from_rgba(background.r, background.g, background.b, 0.5),
background_border: None,
foreground: Color::from_rgba(foreground.r, foreground.g, foreground.b, 0.5),
foreground_border: None,
border_radius: theme.radius_xl().into(),
handle_radius: theme
.radius_xl()
.map(|x| (x - HANDLE_MARGIN).max(0.0))
.into(),
handle_margin: HANDLE_MARGIN,
}
}
}
/*

View file

@ -123,6 +123,6 @@ impl<'a, Message: 'static> Item<'a, Message> {
is_checked: bool,
message: impl Fn(bool) -> Message + 'static,
) -> Row<'a, Message> {
self.control(crate::widget::toggler(None, is_checked, message))
self.control(crate::widget::toggler(None, is_checked, Some(message)))
}
}

View file

@ -7,7 +7,7 @@ use iced_core::text;
pub fn toggler<'a, Message, Theme: iced_widget::toggler::StyleSheet, Renderer>(
label: impl Into<Option<String>>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
f: Option<impl Fn(bool) -> Message + 'a>,
) -> widget::Toggler<'a, Message, Theme, Renderer>
where
Renderer: iced_core::Renderer + text::Renderer,