feat: popup positioning depending on panel anchor
This commit is contained in:
parent
ac0b555946
commit
59a112523d
7 changed files with 34 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use cosmic_panel_config::{CosmicPanelConfig, PanelSize};
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*};
|
||||
use cosmic_panel_config::{PanelSize, PanelAnchor};
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*, PositionType};
|
||||
use relm4_macros::view;
|
||||
|
||||
use crate::deref_cell::DerefCell;
|
||||
|
|
@ -18,7 +18,6 @@ button.cosmic_applet_button {
|
|||
#[derive(Default)]
|
||||
pub struct AppletButtonInner {
|
||||
menu_button: DerefCell<gtk4::MenuButton>,
|
||||
panel_config: DerefCell<CosmicPanelConfig>,
|
||||
popover: DerefCell<gtk4::Popover>,
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +30,15 @@ impl ObjectSubclass for AppletButtonInner {
|
|||
|
||||
impl ObjectImpl for AppletButtonInner {
|
||||
fn constructed(&self, obj: &AppletButton) {
|
||||
let position = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||
.ok()
|
||||
.and_then(|anchor| anchor.parse::<PanelAnchor>().ok())
|
||||
.map(|anchor| match anchor {
|
||||
PanelAnchor::Left => PositionType::Right,
|
||||
PanelAnchor::Right => PositionType::Left,
|
||||
PanelAnchor::Top => PositionType::Bottom,
|
||||
PanelAnchor::Bottom => PositionType::Top,
|
||||
});
|
||||
view! {
|
||||
menu_button = gtk4::MenuButton {
|
||||
set_parent: obj,
|
||||
|
|
@ -38,7 +46,6 @@ impl ObjectImpl for AppletButtonInner {
|
|||
set_has_frame: false,
|
||||
#[wrap(Some)]
|
||||
set_popover: popover = >k4::Popover {
|
||||
// TODO: change if it can be positioned correctly?
|
||||
set_has_arrow: false,
|
||||
}
|
||||
},
|
||||
|
|
@ -46,6 +53,9 @@ impl ObjectImpl for AppletButtonInner {
|
|||
load_from_data: STYLE.as_bytes(),
|
||||
}
|
||||
}
|
||||
if let Some(position) = position {
|
||||
popover.set_position(position);
|
||||
}
|
||||
obj.set_layout_manager(Some(>k4::BinLayout::new()));
|
||||
obj.style_context()
|
||||
.add_provider(&provider, gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
use cosmic_panel_config::CosmicPanelConfig;
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*};
|
||||
use relm4_macros::view;
|
||||
|
||||
mod button;
|
||||
pub use button::AppletButton;
|
||||
mod deref_cell;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue