diff --git a/Cargo.toml b/Cargo.toml index a5ba4c90..ed0917e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" name = "cosmic" [features] -default = ["iced_winit", "wgpu"] +default = ["wayland"] debug = ["iced/debug"] wayland = ["iced/wayland"] wgpu = ["iced/wgpu"] diff --git a/examples/cosmic-applet-graphics/src/window.rs b/examples/cosmic-applet-graphics/src/window.rs index d4926565..7ba05654 100644 --- a/examples/cosmic-applet-graphics/src/window.rs +++ b/examples/cosmic-applet-graphics/src/window.rs @@ -1,6 +1,6 @@ use crate::dbus::{self, PowerDaemonProxy}; use crate::graphics::{get_current_graphics, set_graphics, Graphics}; -use cosmic::applet::{get_popup_settings, icon_button}; +use cosmic::applet::{get_popup_settings, icon_button, popup_container}; use cosmic::iced_style::application::{self, Appearance}; use cosmic::separator; use cosmic::theme::Container; @@ -13,9 +13,9 @@ use cosmic::{ Element, }; use cosmic_panel_config::{PanelAnchor, PanelSize}; -use iced_sctk::Color; use iced_sctk::alignment::{Horizontal, Vertical}; use iced_sctk::commands::popup::{destroy_popup, get_popup}; +use iced_sctk::Color; use zbus::Connection; #[derive(Clone, Copy)] @@ -214,25 +214,19 @@ impl Application for Window { .into() } }; - container(column(vec![ - text("Graphics Mode") - .width(Length::Fill) - .horizontal_alignment(Horizontal::Center) - .size(24) - .into(), - separator!(1).into(), - content, + popup_container( + column(vec![ + text("Graphics Mode") + .width(Length::Fill) + .horizontal_alignment(Horizontal::Center) + .size(24) + .into(), + separator!(1).into(), + content, ]) .padding(4) - .spacing(4)) - .style(Container::Custom(|theme| container::Appearance { - text_color: Some(theme.cosmic().on_bg_color().into()), - background: Some(theme.extended_palette().background.base.color.into()), - border_radius: 12.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - })) - .align_y(Vertical::Center) + .spacing(4), + ) .into() } @@ -253,7 +247,10 @@ impl Application for Window { } fn style(&self) -> ::Style { - ::Style::Custom(|theme| Appearance { background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0), text_color: theme.cosmic().on_bg_color().into() }) + ::Style::Custom(|theme| Appearance { + background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0), + text_color: theme.cosmic().on_bg_color().into(), + }) } fn view_window(&self, _: window::Id) -> Element { diff --git a/src/applet/mod.rs b/src/applet/mod.rs index bd444f8c..14ba6f13 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -1,10 +1,18 @@ -use cosmic_panel_config::{PanelSize, PanelAnchor}; -use iced::{widget::{Button, self}, Rectangle, alignment::{Vertical, Horizontal}, Color, Element}; -use iced_native::{command::platform_specific::wayland::popup::{SctkPopupSettings, SctkPositioner}}; +use cosmic_panel_config::{PanelAnchor, PanelSize}; +use iced::{ + alignment::{Horizontal, Vertical}, + widget::{self, Button}, + Color, Element, Length, Rectangle, +}; +use iced_native::command::platform_specific::wayland::popup::{SctkPopupSettings, SctkPositioner}; use iced_style::container::Appearance; use sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity}; -use crate::{button, widget::icon, theme::{Container, self}}; +use crate::{ + button, + theme::{self, Container}, + widget::icon, +}; pub fn icon_button<'a, M: 'a, Renderer>() -> Button<'a, M, Renderer> where @@ -25,14 +33,19 @@ where button!(icon("input-gaming-symbolic", pixels)) } -pub fn get_popup_settings(parent: iced_native::window::Id, id: iced_native::window::Id, width_padding: Option, height_padding: Option) -> SctkPopupSettings { +pub fn get_popup_settings( + parent: iced_native::window::Id, + id: iced_native::window::Id, + width_padding: Option, + height_padding: Option, +) -> SctkPopupSettings { let anchor = std::env::var("COSMIC_PANEL_ANCHOR") - .ok() - .map(|size| match size.parse::() { - Ok(p) => p, - Err(_) => PanelAnchor::Top, - }) - .unwrap_or(PanelAnchor::Top); + .ok() + .map(|size| match size.parse::() { + Ok(p) => p, + Err(_) => PanelAnchor::Top, + }) + .unwrap_or(PanelAnchor::Top); let pixels = std::env::var("COSMIC_PANEL_SIZE") .ok() .and_then(|size| match size.parse::() { @@ -50,32 +63,44 @@ pub fn get_popup_settings(parent: iced_native::window::Id, id: iced_native::wind PanelAnchor::Top => (Anchor::Bottom, Gravity::Bottom), PanelAnchor::Bottom => (Anchor::Top, Gravity::Top), }; - SctkPopupSettings { parent, id, positioner: SctkPositioner { - anchor, - gravity, - size: (200, 200), - anchor_rect: Rectangle { - x: 0, - y: 0, - width: width_padding.unwrap_or(16) * 2 + pixels as i32, - height: height_padding.unwrap_or(8) * 2 + pixels as i32, + SctkPopupSettings { + parent, + id, + positioner: SctkPositioner { + anchor, + gravity, + size: (200, 200), + anchor_rect: Rectangle { + x: 0, + y: 0, + width: width_padding.unwrap_or(16) * 2 + pixels as i32, + height: height_padding.unwrap_or(8) * 2 + pixels as i32, + }, + reactive: true, + ..Default::default() }, - reactive: true, - ..Default::default() - }, parent_size: None, grab: true } + parent_size: None, + grab: true, + } } -pub fn popup_container<'a, Message, Renderer>(content: impl Into>,) -> crate::widget::widget::Container<'a, Message, Renderer> +// TODO popup container which tracks the size of itself and requests the popup to resize to match +pub fn popup_container<'a, Message, Renderer>( + content: impl Into>, +) -> crate::widget::widget::Container<'a, Message, Renderer> where - Renderer: iced_native::Renderer, - <::Theme as iced_style::container::StyleSheet>::Style: From, Renderer::Theme: widget::container::StyleSheet, + Renderer: iced_native::Renderer + 'a, + Message: 'a, + <::Theme as iced_style::container::StyleSheet>::Style: + From, + Renderer::Theme: widget::container::StyleSheet, { let anchor = std::env::var("COSMIC_PANEL_ANCHOR") - .ok() - .map(|size| match size.parse::() { - Ok(p) => p, - Err(_) => PanelAnchor::Top, - }) + .ok() + .map(|size| match size.parse::() { + Ok(p) => p, + Err(_) => PanelAnchor::Top, + }) .unwrap_or(PanelAnchor::Top); let (valign, halign) = match anchor { PanelAnchor::Left => (Vertical::Center, Horizontal::Left), @@ -83,14 +108,18 @@ where PanelAnchor::Top => (Vertical::Top, Horizontal::Center), PanelAnchor::Bottom => (Vertical::Bottom, Horizontal::Center), }; - crate::widget::widget::container(content) - .style(Container::Custom(|theme| Appearance { - text_color: Some(theme.cosmic().on_bg_color().into()), - background: Some(theme.extended_palette().background.base.color.into()), - border_radius: 12.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - })) + crate::widget::widget::container(crate::widget::widget::container(content).style( + Container::Custom(|theme| Appearance { + text_color: Some(theme.cosmic().on_bg_color().into()), + background: Some(theme.extended_palette().background.base.color.into()), + border_radius: 12.0, + border_width: 0.0, + border_color: Color::TRANSPARENT, + }), + )) + .width(Length::Fill) + .height(Length::Fill) .align_x(halign) .align_y(valign) -} \ No newline at end of file +} +