mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-02 01:45:54 +00:00
feat: add popup sizing
This commit is contained in:
parent
3aff50f38d
commit
d646306a7a
4 changed files with 62 additions and 7 deletions
|
|
@ -7,7 +7,8 @@ pub mod wayland;
|
||||||
pub use rendering::femtovg::popup_window::PopupWindow;
|
pub use rendering::femtovg::popup_window::PopupWindow;
|
||||||
pub use rendering::slint_integration::platform::{
|
pub use rendering::slint_integration::platform::{
|
||||||
clear_popup_position_override, close_current_popup, get_popup_position_override,
|
clear_popup_position_override, close_current_popup, get_popup_position_override,
|
||||||
set_popup_position_override,
|
set_popup_position_override, clear_popup_size_override, get_popup_size_override,
|
||||||
|
set_popup_size_override,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod platform {
|
pub mod platform {
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,11 @@ pub fn set_popup_position_override(x: f32, y: f32) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn get_popup_position_override() -> Option<(f32, f32)> {
|
pub fn get_popup_position_override() -> Option<(f32, f32)> {
|
||||||
CURRENT_PLATFORM.with(|platform| {
|
CURRENT_PLATFORM.with(|platform| {
|
||||||
platform.borrow().as_ref()
|
platform
|
||||||
|
.borrow()
|
||||||
|
.as_ref()
|
||||||
.and_then(Weak::upgrade)
|
.and_then(Weak::upgrade)
|
||||||
.and_then(|strong| strong.get_popup_position())
|
.and_then(|strong| strong.get_popup_position())
|
||||||
})
|
})
|
||||||
|
|
@ -53,12 +54,43 @@ pub fn clear_popup_position_override() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_popup_size_override(width: f32, height: f32) {
|
||||||
|
CURRENT_PLATFORM.with(|platform| {
|
||||||
|
if let Some(weak_platform) = platform.borrow().as_ref() {
|
||||||
|
if let Some(strong_platform) = weak_platform.upgrade() {
|
||||||
|
strong_platform.set_popup_size(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_popup_size_override() -> Option<(f32, f32)> {
|
||||||
|
CURRENT_PLATFORM.with(|platform| {
|
||||||
|
platform
|
||||||
|
.borrow()
|
||||||
|
.as_ref()
|
||||||
|
.and_then(Weak::upgrade)
|
||||||
|
.and_then(|strong| strong.get_popup_size())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_popup_size_override() {
|
||||||
|
CURRENT_PLATFORM.with(|platform| {
|
||||||
|
if let Some(weak_platform) = platform.borrow().as_ref() {
|
||||||
|
if let Some(strong_platform) = weak_platform.upgrade() {
|
||||||
|
strong_platform.clear_popup_size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CustomSlintPlatform {
|
pub struct CustomSlintPlatform {
|
||||||
main_window: Weak<FemtoVGWindow>,
|
main_window: Weak<FemtoVGWindow>,
|
||||||
popup_creator: RefCell<Option<Rc<PopupCreator>>>,
|
popup_creator: RefCell<Option<Rc<PopupCreator>>>,
|
||||||
first_call: Cell<bool>,
|
first_call: Cell<bool>,
|
||||||
last_popup: RefCell<Option<Weak<PopupWindow>>>,
|
last_popup: RefCell<Option<Weak<PopupWindow>>>,
|
||||||
popup_position: RefCell<Option<(f32, f32)>>,
|
popup_position: RefCell<Option<(f32, f32)>>,
|
||||||
|
popup_size: RefCell<Option<(f32, f32)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomSlintPlatform {
|
impl CustomSlintPlatform {
|
||||||
|
|
@ -70,6 +102,7 @@ impl CustomSlintPlatform {
|
||||||
first_call: Cell::new(true),
|
first_call: Cell::new(true),
|
||||||
last_popup: RefCell::new(None),
|
last_popup: RefCell::new(None),
|
||||||
popup_position: RefCell::new(None),
|
popup_position: RefCell::new(None),
|
||||||
|
popup_size: RefCell::new(None),
|
||||||
});
|
});
|
||||||
|
|
||||||
CURRENT_PLATFORM.with(|current| {
|
CURRENT_PLATFORM.with(|current| {
|
||||||
|
|
@ -112,6 +145,18 @@ impl CustomSlintPlatform {
|
||||||
pub fn clear_popup_position(&self) {
|
pub fn clear_popup_position(&self) {
|
||||||
*self.popup_position.borrow_mut() = None;
|
*self.popup_position.borrow_mut() = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_popup_size(&self, width: f32, height: f32) {
|
||||||
|
*self.popup_size.borrow_mut() = Some((width, height));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_popup_size(&self) -> Option<(f32, f32)> {
|
||||||
|
*self.popup_size.borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_popup_size(&self) {
|
||||||
|
*self.popup_size.borrow_mut() = None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform for CustomSlintPlatform {
|
impl Platform for CustomSlintPlatform {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use crate::rendering::egl::context::EGLContext;
|
||||||
use crate::rendering::femtovg::popup_window::PopupWindow;
|
use crate::rendering::femtovg::popup_window::PopupWindow;
|
||||||
use crate::rendering::slint_integration::platform::{
|
use crate::rendering::slint_integration::platform::{
|
||||||
clear_popup_position_override, get_popup_position_override,
|
clear_popup_position_override, get_popup_position_override,
|
||||||
|
clear_popup_size_override, get_popup_size_override,
|
||||||
};
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
@ -112,10 +113,17 @@ impl PopupManager {
|
||||||
);
|
);
|
||||||
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
#[allow(clippy::cast_precision_loss)]
|
||||||
let logical_size = slint::LogicalSize::new(
|
let logical_size = if let Some((width, height)) = get_popup_size_override() {
|
||||||
|
info!("Using explicit popup size: ({}, {})", width, height);
|
||||||
|
clear_popup_size_override();
|
||||||
|
slint::LogicalSize::new(width, height)
|
||||||
|
} else {
|
||||||
|
info!("No popup size override - using full output size");
|
||||||
|
slint::LogicalSize::new(
|
||||||
output_size.width as f32 / scale_factor,
|
output_size.width as f32 / scale_factor,
|
||||||
output_size.height as f32 / scale_factor,
|
output_size.height as f32 / scale_factor,
|
||||||
);
|
)
|
||||||
|
};
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
#[allow(clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
let popup_size = PhysicalSize::new(
|
let popup_size = PhysicalSize::new(
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ pub use layer_shika_adapters::close_current_popup;
|
||||||
pub use layer_shika_adapters::platform::{calloop, slint, slint_interpreter};
|
pub use layer_shika_adapters::platform::{calloop, slint, slint_interpreter};
|
||||||
pub use layer_shika_adapters::{
|
pub use layer_shika_adapters::{
|
||||||
clear_popup_position_override, get_popup_position_override, set_popup_position_override,
|
clear_popup_position_override, get_popup_position_override, set_popup_position_override,
|
||||||
|
clear_popup_size_override, get_popup_size_override, set_popup_size_override,
|
||||||
};
|
};
|
||||||
pub use layer_shika_domain::value_objects::anchor::AnchorEdges;
|
pub use layer_shika_domain::value_objects::anchor::AnchorEdges;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue