This commit is contained in:
Antoine Colombier 2024-09-19 20:41:13 +03:30 • committed by GitHub
commit 7da3dbb490
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 3 deletions

2
iced

@ -1 +1 @@
Subproject commit 23397f6fc541d8d6b98b56999a59ad4f4255be95 Subproject commit 1e48a5c8cf83bdb38d22494d46d91cac05f50a41

View file

@ -5,6 +5,7 @@
use crate::theme::{CosmicComponent, Theme, TRANSPARENT_COMPONENT}; use crate::theme::{CosmicComponent, Theme, TRANSPARENT_COMPONENT};
use cosmic_theme::composite::over; use cosmic_theme::composite::over;
use iced::color;
use iced_core::{Background, Border, Color, Shadow, Vector}; use iced_core::{Background, Border, Color, Shadow, Vector};
use iced_style::application; use iced_style::application;
use iced_style::button as iced_button; use iced_style::button as iced_button;
@ -858,6 +859,29 @@ impl toggler::StyleSheet for Theme {
..self.active(style, is_active) ..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

@ -122,6 +122,6 @@ impl<'a, Message: 'static> Item<'a, Message> {
is_checked: bool, is_checked: bool,
message: impl Fn(bool) -> Message + 'static, message: impl Fn(bool) -> Message + 'static,
) -> Row<'a, Message> { ) -> 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>( pub fn toggler<'a, Message, Theme: iced_widget::toggler::StyleSheet, Renderer>(
label: impl Into<Option<String>>, label: impl Into<Option<String>>,
is_checked: bool, is_checked: bool,
f: impl Fn(bool) -> Message + 'a, f: Option<impl Fn(bool) -> Message + 'a>,
) -> widget::Toggler<'a, Message, Theme, Renderer> ) -> widget::Toggler<'a, Message, Theme, Renderer>
where where
Renderer: iced_core::Renderer + text::Renderer, Renderer: iced_core::Renderer + text::Renderer,