From 8f7b400143b290c4d2aaeb9b9caf65dfc9976766 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 18 Sep 2023 07:45:11 +0200 Subject: [PATCH] refactor(applet): move applet module to crate root --- examples/applet/src/main.rs | 2 +- examples/applet/src/window.rs | 8 ++++---- src/app/core.rs | 6 ++++-- src/app/mod.rs | 2 -- src/{app => }/applet/mod.rs | 16 ++++++++-------- src/lib.rs | 3 +++ 6 files changed, 20 insertions(+), 17 deletions(-) rename src/{app => }/applet/mod.rs (96%) diff --git a/examples/applet/src/main.rs b/examples/applet/src/main.rs index 5863415..28e893a 100644 --- a/examples/applet/src/main.rs +++ b/examples/applet/src/main.rs @@ -3,5 +3,5 @@ use crate::window::Window; mod window; fn main() -> cosmic::iced::Result { - cosmic::app::applet::run::(true, ()) + cosmic::applet::run::(true, ()) } diff --git a/examples/applet/src/window.rs b/examples/applet/src/window.rs index d027ad6..9562412 100644 --- a/examples/applet/src/window.rs +++ b/examples/applet/src/window.rs @@ -65,7 +65,7 @@ impl cosmic::Application for Window { self.popup.replace(new_id); let mut popup_settings = self.core - .applet_helper + .applet .get_popup_settings(Id(0), new_id, None, None, None); popup_settings.positioner.size_limits = Limits::NONE .max_width(372.0) @@ -87,7 +87,7 @@ impl cosmic::Application for Window { fn view(&self) -> Element { self.core - .applet_helper + .applet .icon_button(ID) .on_press(Message::TogglePopup) .style(Button::Text) @@ -102,10 +102,10 @@ impl cosmic::Application for Window { }), )); - self.core.applet_helper.popup_container(content_list).into() + self.core.applet.popup_container(content_list).into() } fn style(&self) -> Option<::Style> { - Some(cosmic::app::applet::style()) + Some(cosmic::applet::style()) } } diff --git a/src/app/core.rs b/src/app/core.rs index 8423271..92b68dd 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -47,9 +47,11 @@ pub struct Core { pub(super) system_theme: Theme, pub(super) title: String, + pub window: Window, + #[cfg(feature = "applet")] - pub applet_helper: super::applet::CosmicAppletHelper, + pub applet: crate::applet::Context, } impl Default for Core { @@ -78,7 +80,7 @@ impl Default for Core { width: 0, }, #[cfg(feature = "applet")] - applet_helper: super::applet::CosmicAppletHelper::default(), + applet: crate::applet::Context::default(), } } } diff --git a/src/app/mod.rs b/src/app/mod.rs index f046b63..070e909 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -6,8 +6,6 @@ //! Check out our [application](https://github.com/pop-os/libcosmic/tree/master/examples/application) //! example in our repository. -#[cfg(feature = "applet")] -pub mod applet; pub mod command; mod core; pub mod cosmic; diff --git a/src/app/applet/mod.rs b/src/applet/mod.rs similarity index 96% rename from src/app/applet/mod.rs rename to src/applet/mod.rs index 0594e3c..277b32c 100644 --- a/src/app/applet/mod.rs +++ b/src/applet/mod.rs @@ -19,12 +19,12 @@ use iced_widget::runtime::command::platform_specific::wayland::popup::{ }; use sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity}; -use super::cosmic; +use crate::app::cosmic; const APPLET_PADDING: u32 = 8; #[must_use] -pub fn applet_button_theme() -> Button { +pub fn button_theme() -> Button { Button::Custom { active: Box::new(|active, t| widget::button::Appearance { border_radius: 0.0.into(), @@ -46,7 +46,7 @@ pub fn applet_button_theme() -> Button { } #[derive(Debug, Clone)] -pub struct CosmicAppletHelper { +pub struct Context { pub size: Size, pub anchor: PanelAnchor, pub background: CosmicPanelBackground, @@ -60,7 +60,7 @@ pub enum Size { Hardcoded((u16, u16)), } -impl Default for CosmicAppletHelper { +impl Default for Context { fn default() -> Self { Self { size: Size::PanelSize( @@ -82,7 +82,7 @@ impl Default for CosmicAppletHelper { } } -impl CosmicAppletHelper { +impl Context { #[must_use] pub fn suggested_size(&self) -> (u16, u16) { match &self.size { @@ -104,11 +104,11 @@ impl CosmicAppletHelper { #[must_use] #[allow(clippy::cast_precision_loss)] - pub fn window_settings(&self) -> super::Settings { + pub fn window_settings(&self) -> crate::app::Settings { let (width, height) = self.suggested_size(); let width = u32::from(width); let height = u32::from(height); - let mut settings = super::Settings::default() + let mut settings = crate::app::Settings::default() .size((width + APPLET_PADDING * 2, height + APPLET_PADDING * 2)) .size_limits( Limits::NONE @@ -225,7 +225,7 @@ impl CosmicAppletHelper { /// /// Returns error on application failure. pub fn run(autosize: bool, flags: App::Flags) -> iced::Result { - let helper = CosmicAppletHelper::default(); + let helper = Context::default(); let mut settings = helper.window_settings(); settings.autosize = autosize; if autosize { diff --git a/src/lib.rs b/src/lib.rs index 043de14..5c06353 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,9 @@ pub use apply::{Also, Apply}; pub mod app; pub use app::{Application, ApplicationExt}; +#[cfg(feature = "applet")] +pub mod applet; + pub use iced::Command; pub mod command; pub use cosmic_config;