mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-10-28 05:24:23 +00:00
refactor: reduce ref count of window
This commit is contained in:
parent
0cc906c546
commit
ccf49145a0
2 changed files with 12 additions and 7 deletions
|
|
@ -2,22 +2,27 @@ use slint::{
|
|||
platform::{Platform, WindowAdapter},
|
||||
PlatformError,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::rc::{Rc, Weak};
|
||||
|
||||
use super::femtovg_window::FemtoVGWindow;
|
||||
|
||||
pub struct CustomSlintPlatform {
|
||||
window: Rc<FemtoVGWindow>,
|
||||
window: Weak<FemtoVGWindow>,
|
||||
}
|
||||
|
||||
impl CustomSlintPlatform {
|
||||
pub const fn new(window: Rc<FemtoVGWindow>) -> Self {
|
||||
Self { window }
|
||||
pub fn new(window: &Rc<FemtoVGWindow>) -> Self {
|
||||
Self {
|
||||
window: Rc::downgrade(window),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Platform for CustomSlintPlatform {
|
||||
fn create_window_adapter(&self) -> Result<Rc<dyn WindowAdapter + 'static>, PlatformError> {
|
||||
Result::Ok(Rc::clone(&self.window) as Rc<dyn WindowAdapter>)
|
||||
self.window
|
||||
.upgrade()
|
||||
.ok_or(PlatformError::NoPlatform)
|
||||
.map(|w| w as Rc<dyn WindowAdapter>)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,11 +110,11 @@ impl WindowStateBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Result<WindowState> {
|
||||
let platform = CustomSlintPlatform::new(Rc::clone(
|
||||
let platform = CustomSlintPlatform::new(
|
||||
self.window
|
||||
.as_ref()
|
||||
.ok_or_else(|| LayerShikaError::InvalidInput("Window is required".into()))?,
|
||||
));
|
||||
);
|
||||
set_platform(Box::new(platform)).map_err(|e| {
|
||||
LayerShikaError::PlatformSetup(format!("Failed to set platform: {e:?}"))
|
||||
})?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue