refactor: remove refcells on femtovg
parent
155d4071a5
commit
0910670518
|
@ -3,12 +3,12 @@ use slint::{
|
||||||
platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent},
|
platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent},
|
||||||
PhysicalSize, Window, WindowSize,
|
PhysicalSize, Window, WindowSize,
|
||||||
};
|
};
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::Cell;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
|
|
||||||
pub struct FemtoVGWindow {
|
pub struct FemtoVGWindow {
|
||||||
window: RefCell<Window>,
|
window: Window,
|
||||||
renderer: RefCell<FemtoVGRenderer>,
|
renderer: FemtoVGRenderer,
|
||||||
is_dirty: Cell<bool>,
|
is_dirty: Cell<bool>,
|
||||||
size: Cell<PhysicalSize>,
|
size: Cell<PhysicalSize>,
|
||||||
scale_factor: Cell<f32>,
|
scale_factor: Cell<f32>,
|
||||||
|
@ -19,8 +19,8 @@ impl FemtoVGWindow {
|
||||||
Rc::new_cyclic(|weak_self| {
|
Rc::new_cyclic(|weak_self| {
|
||||||
let window = Window::new(weak_self.clone() as Weak<dyn WindowAdapter>);
|
let window = Window::new(weak_self.clone() as Weak<dyn WindowAdapter>);
|
||||||
Self {
|
Self {
|
||||||
window: RefCell::new(window),
|
window,
|
||||||
renderer: RefCell::new(renderer),
|
renderer,
|
||||||
is_dirty: Default::default(),
|
is_dirty: Default::default(),
|
||||||
size: Cell::new(PhysicalSize::default()),
|
size: Cell::new(PhysicalSize::default()),
|
||||||
scale_factor: Cell::new(1.),
|
scale_factor: Cell::new(1.),
|
||||||
|
@ -30,7 +30,7 @@ impl FemtoVGWindow {
|
||||||
|
|
||||||
pub fn render_frame_if_dirty(&self) {
|
pub fn render_frame_if_dirty(&self) {
|
||||||
if self.is_dirty.get() {
|
if self.is_dirty.get() {
|
||||||
match self.renderer.borrow_mut().render() {
|
match self.renderer.render() {
|
||||||
Ok(_) => {} //log::debug!("Frame rendered successfully"),
|
Ok(_) => {} //log::debug!("Frame rendered successfully"),
|
||||||
Err(e) => log::error!("Error rendering frame: {}", e),
|
Err(e) => log::error!("Error rendering frame: {}", e),
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,11 @@ impl FemtoVGWindow {
|
||||||
|
|
||||||
impl WindowAdapter for FemtoVGWindow {
|
impl WindowAdapter for FemtoVGWindow {
|
||||||
fn window(&self) -> &Window {
|
fn window(&self) -> &Window {
|
||||||
unsafe { self.window.as_ptr().as_ref().unwrap() }
|
&self.window
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renderer(&self) -> &dyn Renderer {
|
fn renderer(&self) -> &dyn Renderer {
|
||||||
unsafe { &*self.renderer.as_ptr() }
|
&self.renderer
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self) -> PhysicalSize {
|
fn size(&self) -> PhysicalSize {
|
||||||
|
@ -65,7 +65,7 @@ impl WindowAdapter for FemtoVGWindow {
|
||||||
|
|
||||||
fn set_size(&self, size: WindowSize) {
|
fn set_size(&self, size: WindowSize) {
|
||||||
self.size.set(size.to_physical(self.scale_factor()));
|
self.size.set(size.to_physical(self.scale_factor()));
|
||||||
self.window.borrow().dispatch_event(WindowEvent::Resized {
|
self.window.dispatch_event(WindowEvent::Resized {
|
||||||
size: size.to_logical(self.scale_factor()),
|
size: size.to_logical(self.scale_factor()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,6 @@ impl WindowAdapter for FemtoVGWindow {
|
||||||
impl core::ops::Deref for FemtoVGWindow {
|
impl core::ops::Deref for FemtoVGWindow {
|
||||||
type Target = Window;
|
type Target = Window;
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
unsafe { self.window.as_ptr().as_ref().unwrap() }
|
&self.window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue