From f1f12b5e217cb2cb6a941d0dbd335015358b8909 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 23 May 2023 16:40:29 -0400 Subject: [PATCH] feat: panel position on screen --- Cargo.lock | 2 +- app/src/pages/desktop/panel.rs | 64 +++++++++++++++++++++++++++------- i18n/en/cosmic_settings.ftl | 4 +++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d141c0..b985347 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#aae46287cdb349381743fe530f281333c7ebfa83" +source = "git+https://github.com/pop-os/cosmic-panel#1ef8ca7dd07bbbc6bd86ce8421dc3c759d4a837b" dependencies = [ "anyhow", "cosmic-config 0.1.0 (git+https://github.com/pop-os/libcosmic?tag=cosmic-config-derive)", diff --git a/app/src/pages/desktop/panel.rs b/app/src/pages/desktop/panel.rs index 6e43d8d..1f3f47a 100644 --- a/app/src/pages/desktop/panel.rs +++ b/app/src/pages/desktop/panel.rs @@ -1,7 +1,8 @@ use cosmic::{ iced::widget::horizontal_space, iced::Length, - widget::{settings, toggler}, + iced_widget::pick_list, + widget::{settings, text, toggler}, Element, }; @@ -11,6 +12,7 @@ use cosmic_panel_config::{AutoHide, CosmicPanelConfig, CosmicPanelOuput, PanelAn use cosmic_settings_page::Section; use cosmic_settings_page::{self as page, section}; use slotmap::SlotMap; +use std::borrow::Cow; pub struct Page { config_helper: Option, @@ -64,7 +66,11 @@ impl page::AutoBind for Page {} pub fn behavior_and_position() -> Section { Section::default() .title(fl!("panel-behavior-and-position")) - .descriptions(vec![fl!("panel-behavior-and-position", "autohide")]) + .descriptions(vec![ + fl!("panel-behavior-and-position", "autohide"), + fl!("panel-behavior-and-position", "position"), + fl!("panel-behavior-and-position", "display"), + ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; let panel_config = page.panel_config.as_ref().unwrap(); @@ -75,6 +81,20 @@ pub fn behavior_and_position() -> Section { Message::AutoHidePanel(value) }), )) + .add(settings::item( + &descriptions[1], + pick_list( + Cow::from(vec![ + Anchor(PanelAnchor::Top), + Anchor(PanelAnchor::Bottom), + Anchor(PanelAnchor::Left), + Anchor(PanelAnchor::Right), + ]), + Some(Anchor(panel_config.anchor)), + |a| Message::PanelAnchor(a.0), + ), + )) + .add(settings::item(&descriptions[2], text("todo"))) .apply(Element::from) .map(crate::pages::Message::Panel) }) @@ -82,14 +102,15 @@ pub fn behavior_and_position() -> Section { pub fn style() -> Section { Section::default() - .title(fl!("hot-corner")) - .descriptions(vec![fl!("hot-corner", "top-left-corner")]) + .title(fl!("panel-style")) + .descriptions(vec![ + fl!("panel-style", "anchor-gap"), + fl!("panel-style", "extend"), + fl!("panel-style", "appearance"), + fl!("panel-style", "size"), + fl!("panel-style", "background-opacity"), + ]) .view::(|binder, _page, section| { - let desktop = binder - .page::() - .expect("desktop page not found"); - - let descriptions = §ion.descriptions; settings::view_section(§ion.title) .apply(Element::from) .map(crate::pages::Message::Desktop) @@ -98,8 +119,8 @@ pub fn style() -> Section { pub fn configuration() -> Section { Section::default() - .title(fl!("hot-corner")) - .descriptions(vec![fl!("hot-corner", "top-left-corner")]) + .title(fl!("panel-applets")) + .descriptions(vec![fl!("panel-applets", "desc")]) .view::(|binder, _page, section| { let desktop = binder .page::() @@ -114,8 +135,11 @@ pub fn configuration() -> Section { pub fn add_panel() -> Section { Section::default() - .title(fl!("hot-corner")) - .descriptions(vec![fl!("hot-corner", "top-left-corner")]) + .title(fl!("panel-missing")) + .descriptions(vec![ + fl!("panel-missing", "desc"), + fl!("panel-missing", "fix"), + ]) .view::(|binder, _page, section| { let desktop = binder .page::() @@ -128,6 +152,20 @@ pub fn add_panel() -> Section { }) } +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct Anchor(PanelAnchor); + +impl ToString for Anchor { + fn to_string(&self) -> String { + match self.0 { + PanelAnchor::Top => fl!("panel-top"), + PanelAnchor::Bottom => fl!("panel-bottom"), + PanelAnchor::Left => fl!("panel-left"), + PanelAnchor::Right => fl!("panel-right"), + } + } +} + #[derive(Clone, Debug)] pub enum Message { // panel messages diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index 0b29707..b220782 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -57,6 +57,10 @@ panel-behavior-and-position = Behavior and Positions .autohide = Automatically hide panel .position = Position on screen .display = Show on display +panel-top = Top +panel-bottom = Bottom +panel-left = Left +panel-right = Right panel-style = Style .anchor-gap = Gap between panel and screen edges