From a2bda491520093c3343018204bfc8c4169b5e3b9 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 19 Oct 2023 14:35:46 -0400 Subject: [PATCH] refactor: add applet button variants and a menu_button helper --- src/applet/mod.rs | 33 ++++++++++----------------------- src/theme/style/button.rs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/applet/mod.rs b/src/applet/mod.rs index ae8dc7c3674..83c6c0cb61e 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -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() -> ::Style { } })) } + +pub fn menu_button<'a, Message>( + content: impl Into>, +) -> crate::widget::Button<'a, Message, crate::Renderer> { + crate::widget::Button::new(content) + .style(Button::AppletMenu) + .padding([8, 24]) + .width(Length::Fill) +} diff --git a/src/theme/style/button.rs b/src/theme/style/button.rs index 76ce451e7b5..13110b3295c 100644 --- a/src/theme/style/button.rs +++ b/src/theme/style/button.rs @@ -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();