Skip to content

Commit

Permalink
refactor: add applet button variants and a menu_button helper
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Oct 19, 2023
1 parent f3eb41c commit a2bda49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/applet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions src/theme/style/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Button {
Suggested,
Text,
Transparent,
AppletMenu,
AppletIcon,
}

pub fn appearance(
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a2bda49

Please sign in to comment.