refactor(applet): move applet module to crate root

This commit is contained in:
Michael Aaron Murphy 2023-09-18 07:45:11 +02:00
parent 69cd9a3bfa
commit 8f7b400143
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
6 changed files with 20 additions and 17 deletions

View file

@ -3,5 +3,5 @@ use crate::window::Window;
mod window; mod window;
fn main() -> cosmic::iced::Result { fn main() -> cosmic::iced::Result {
cosmic::app::applet::run::<Window>(true, ()) cosmic::applet::run::<Window>(true, ())
} }

View file

@ -65,7 +65,7 @@ impl cosmic::Application for Window {
self.popup.replace(new_id); self.popup.replace(new_id);
let mut popup_settings = let mut popup_settings =
self.core self.core
.applet_helper .applet
.get_popup_settings(Id(0), new_id, None, None, None); .get_popup_settings(Id(0), new_id, None, None, None);
popup_settings.positioner.size_limits = Limits::NONE popup_settings.positioner.size_limits = Limits::NONE
.max_width(372.0) .max_width(372.0)
@ -87,7 +87,7 @@ impl cosmic::Application for Window {
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<Self::Message> {
self.core self.core
.applet_helper .applet
.icon_button(ID) .icon_button(ID)
.on_press(Message::TogglePopup) .on_press(Message::TogglePopup)
.style(Button::Text) .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<<Theme as application::StyleSheet>::Style> { fn style(&self) -> Option<<Theme as application::StyleSheet>::Style> {
Some(cosmic::app::applet::style()) Some(cosmic::applet::style())
} }
} }

View file

@ -47,9 +47,11 @@ pub struct Core {
pub(super) system_theme: Theme, pub(super) system_theme: Theme,
pub(super) title: String, pub(super) title: String,
pub window: Window, pub window: Window,
#[cfg(feature = "applet")] #[cfg(feature = "applet")]
pub applet_helper: super::applet::CosmicAppletHelper, pub applet: crate::applet::Context,
} }
impl Default for Core { impl Default for Core {
@ -78,7 +80,7 @@ impl Default for Core {
width: 0, width: 0,
}, },
#[cfg(feature = "applet")] #[cfg(feature = "applet")]
applet_helper: super::applet::CosmicAppletHelper::default(), applet: crate::applet::Context::default(),
} }
} }
} }

View file

@ -6,8 +6,6 @@
//! Check out our [application](https://github.com/pop-os/libcosmic/tree/master/examples/application) //! Check out our [application](https://github.com/pop-os/libcosmic/tree/master/examples/application)
//! example in our repository. //! example in our repository.
#[cfg(feature = "applet")]
pub mod applet;
pub mod command; pub mod command;
mod core; mod core;
pub mod cosmic; pub mod cosmic;

View file

@ -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 sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity};
use super::cosmic; use crate::app::cosmic;
const APPLET_PADDING: u32 = 8; const APPLET_PADDING: u32 = 8;
#[must_use] #[must_use]
pub fn applet_button_theme() -> Button { pub fn button_theme() -> Button {
Button::Custom { Button::Custom {
active: Box::new(|active, t| widget::button::Appearance { active: Box::new(|active, t| widget::button::Appearance {
border_radius: 0.0.into(), border_radius: 0.0.into(),
@ -46,7 +46,7 @@ pub fn applet_button_theme() -> Button {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CosmicAppletHelper { pub struct Context {
pub size: Size, pub size: Size,
pub anchor: PanelAnchor, pub anchor: PanelAnchor,
pub background: CosmicPanelBackground, pub background: CosmicPanelBackground,
@ -60,7 +60,7 @@ pub enum Size {
Hardcoded((u16, u16)), Hardcoded((u16, u16)),
} }
impl Default for CosmicAppletHelper { impl Default for Context {
fn default() -> Self { fn default() -> Self {
Self { Self {
size: Size::PanelSize( size: Size::PanelSize(
@ -82,7 +82,7 @@ impl Default for CosmicAppletHelper {
} }
} }
impl CosmicAppletHelper { impl Context {
#[must_use] #[must_use]
pub fn suggested_size(&self) -> (u16, u16) { pub fn suggested_size(&self) -> (u16, u16) {
match &self.size { match &self.size {
@ -104,11 +104,11 @@ impl CosmicAppletHelper {
#[must_use] #[must_use]
#[allow(clippy::cast_precision_loss)] #[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, height) = self.suggested_size();
let width = u32::from(width); let width = u32::from(width);
let height = u32::from(height); 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((width + APPLET_PADDING * 2, height + APPLET_PADDING * 2))
.size_limits( .size_limits(
Limits::NONE Limits::NONE
@ -225,7 +225,7 @@ impl CosmicAppletHelper {
/// ///
/// Returns error on application failure. /// Returns error on application failure.
pub fn run<App: Application>(autosize: bool, flags: App::Flags) -> iced::Result { pub fn run<App: Application>(autosize: bool, flags: App::Flags) -> iced::Result {
let helper = CosmicAppletHelper::default(); let helper = Context::default();
let mut settings = helper.window_settings(); let mut settings = helper.window_settings();
settings.autosize = autosize; settings.autosize = autosize;
if autosize { if autosize {

View file

@ -20,6 +20,9 @@ pub use apply::{Also, Apply};
pub mod app; pub mod app;
pub use app::{Application, ApplicationExt}; pub use app::{Application, ApplicationExt};
#[cfg(feature = "applet")]
pub mod applet;
pub use iced::Command; pub use iced::Command;
pub mod command; pub mod command;
pub use cosmic_config; pub use cosmic_config;