refactor: add applet button variants and a menu_button helper
This commit is contained in:
parent
f3eb41c1d2
commit
a2bda49152
2 changed files with 27 additions and 23 deletions
|
|
@ -24,28 +24,6 @@ use crate::app::cosmic;
|
|||
|
||||
const APPLET_PADDING: u32 = 8;
|
||||
|
||||
#[must_use]
|
||||
pub fn button_theme() -> Button {
|
||||
Button::Custom {
|
||||
active: Box::new(|active, t| widget::button::Appearance {
|
||||
border_radius: 0.0.into(),
|
||||
..t.active(active, &Button::Text)
|
||||
}),
|
||||
hovered: Box::new(|hovered, t| widget::button::Appearance {
|
||||
border_radius: 0.0.into(),
|
||||
..t.hovered(hovered, &Button::Text)
|
||||
}),
|
||||
pressed: Box::new(|pressed, t| widget::button::Appearance {
|
||||
border_radius: 0.0.into(),
|
||||
..t.pressed(pressed, &Button::Text)
|
||||
}),
|
||||
disabled: Box::new(|t| widget::button::Appearance {
|
||||
border_radius: 0.0.into(),
|
||||
..t.disabled(&Button::Text)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Context {
|
||||
pub size: Size,
|
||||
|
|
@ -150,7 +128,7 @@ impl Context {
|
|||
.height(Length::Fixed(suggested.1 as f32)),
|
||||
)
|
||||
.padding(APPLET_PADDING as u16)
|
||||
.style(Button::Text)
|
||||
.style(Button::AppletIcon)
|
||||
}
|
||||
|
||||
// TODO popup container which tracks the size of itself and requests the popup to resize to match
|
||||
|
|
@ -307,3 +285,12 @@ pub fn style() -> <crate::Theme as iced_style::application::StyleSheet>::Style {
|
|||
}
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn menu_button<'a, Message>(
|
||||
content: impl Into<Element<'a, Message>>,
|
||||
) -> crate::widget::Button<'a, Message, crate::Renderer> {
|
||||
crate::widget::Button::new(content)
|
||||
.style(Button::AppletMenu)
|
||||
.padding([8, 24])
|
||||
.width(Length::Fill)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ pub enum Button {
|
|||
Suggested,
|
||||
Text,
|
||||
Transparent,
|
||||
AppletMenu,
|
||||
AppletIcon,
|
||||
}
|
||||
|
||||
pub fn appearance(
|
||||
|
|
@ -86,6 +88,21 @@ pub fn appearance(
|
|||
}
|
||||
|
||||
Button::Custom { .. } => (),
|
||||
Button::AppletMenu => {
|
||||
let (background, _, _) = color(&cosmic.text_button);
|
||||
appearance.background = Some(Background::Color(background));
|
||||
|
||||
appearance.icon_color = Some(cosmic.background.on.into());
|
||||
appearance.text_color = Some(cosmic.background.on.into());
|
||||
corner_radii = &cosmic.corner_radii.radius_0;
|
||||
}
|
||||
Button::AppletIcon => {
|
||||
let (background, _, _) = color(&cosmic.text_button);
|
||||
appearance.background = Some(Background::Color(background));
|
||||
|
||||
appearance.icon_color = Some(cosmic.background.on.into());
|
||||
appearance.text_color = Some(cosmic.background.on.into());
|
||||
}
|
||||
}
|
||||
|
||||
appearance.border_radius = (*corner_radii).into();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue