update applets using latest libcosmic auto-sizing popups
This commit is contained in:
parent
a1aa87f5bd
commit
88b4a7d20b
13 changed files with 319 additions and 251 deletions
|
|
@ -9,18 +9,19 @@ use crate::upower_kbdbacklight::{
|
|||
};
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::iced::alignment::Horizontal;
|
||||
use cosmic::iced::wayland::SurfaceIdWrapper;
|
||||
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
|
||||
use cosmic::iced::wayland::SurfaceIdWrapper;
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, row, text, slider},
|
||||
widget::{button, column, row, slider, text},
|
||||
window, Alignment, Application, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_native::layout::Limits;
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::{svg, Color};
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::widget::{icon, toggler, horizontal_rule};
|
||||
use cosmic::{iced_style, settings, Element, Theme};
|
||||
use cosmic::widget::{horizontal_rule, icon, toggler};
|
||||
use cosmic::{iced_style, Element, Theme};
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
|
|
@ -139,8 +140,14 @@ impl Application for CosmicBatteryApplet {
|
|||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings =
|
||||
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None);
|
||||
let mut popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
popup_settings.positioner.size_limits = Limits::NONE.max_width(400).min_width(300).min_height(200).max_height(1080);
|
||||
return get_popup(popup_settings);
|
||||
}
|
||||
}
|
||||
|
|
@ -176,11 +183,11 @@ impl Application for CosmicBatteryApplet {
|
|||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button(
|
||||
&self.icon_name,
|
||||
)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Window(_) => self
|
||||
.applet_helper
|
||||
.icon_button(&self.icon_name)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let name = text(fl!("battery")).size(18);
|
||||
let description = text(
|
||||
|
|
@ -198,82 +205,82 @@ impl Application for CosmicBatteryApplet {
|
|||
},
|
||||
)
|
||||
.size(12);
|
||||
self.applet_helper.popup_container(
|
||||
column![
|
||||
row![
|
||||
icon(&*self.icon_name, 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
column![name, description]
|
||||
self.applet_helper
|
||||
.popup_container(
|
||||
column![
|
||||
row![
|
||||
icon(&*self.icon_name, 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
column![name, description]
|
||||
]
|
||||
.spacing(8)
|
||||
.align_items(Alignment::Center),
|
||||
horizontal_rule(1),
|
||||
toggler(fl!("max-charge"), self.charging_limit, |_| {
|
||||
Message::SetChargingLimit(!self.charging_limit)
|
||||
}).width(Length::Fill),
|
||||
horizontal_rule(1),
|
||||
row![
|
||||
icon("display-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.screen_brightness * 100.0) as i32,
|
||||
Message::SetScreenBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.screen_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
row![
|
||||
icon("keyboard-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.kbd_brightness * 100.0) as i32,
|
||||
Message::SetKbdBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.kbd_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
button(
|
||||
text(fl!("power-settings"))
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.width(Length::Fill)
|
||||
.style(theme::Text::Custom(|theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
iced_style::text::Appearance {
|
||||
color: Some(cosmic.accent.on.into()),
|
||||
}
|
||||
}))
|
||||
)
|
||||
.width(Length::Fill)
|
||||
]
|
||||
.spacing(8)
|
||||
.align_items(Alignment::Center),
|
||||
horizontal_rule(1),
|
||||
// text{"Limit Battery Charging"},
|
||||
toggler(fl!("max-charge"), self.charging_limit, |_| {
|
||||
Message::SetChargingLimit(!self.charging_limit)
|
||||
}),
|
||||
horizontal_rule(1),
|
||||
row![
|
||||
icon("display-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.screen_brightness * 100.0) as i32,
|
||||
Message::SetScreenBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.screen_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
row![
|
||||
icon("keyboard-brightness-symbolic", 24)
|
||||
.style(Svg::Custom(|theme| {
|
||||
svg::Appearance {
|
||||
color: Some(theme.palette().text),
|
||||
}
|
||||
}))
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24)),
|
||||
slider(
|
||||
0..=100,
|
||||
(self.kbd_brightness * 100.0) as i32,
|
||||
Message::SetKbdBrightness
|
||||
),
|
||||
text(format!("{:.0}%", self.kbd_brightness * 100.0))
|
||||
.width(Length::Units(40))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(12),
|
||||
button(
|
||||
text(fl!("power-settings"))
|
||||
.horizontal_alignment(Horizontal::Center)
|
||||
.width(Length::Fill)
|
||||
.style(theme::Text::Custom(|theme| {
|
||||
let cosmic = theme.cosmic();
|
||||
iced_style::text::Appearance {
|
||||
color: Some(cosmic.accent.on.into()),
|
||||
}
|
||||
}))
|
||||
)
|
||||
.width(Length::Fill)
|
||||
]
|
||||
.spacing(4)
|
||||
.padding(8),
|
||||
)
|
||||
.into()
|
||||
.spacing(4)
|
||||
.padding(8),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue