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

@ -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(),
}
}
}

View file

@ -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;

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 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<App: Application>(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 {

View file

@ -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;