diff --git a/src/rendering/femtovg_window.rs b/src/rendering/femtovg_window.rs index e65acac..46644a4 100644 --- a/src/rendering/femtovg_window.rs +++ b/src/rendering/femtovg_window.rs @@ -6,10 +6,16 @@ use slint::{ use std::cell::Cell; use std::rc::{Rc, Weak}; +#[derive(Clone, Copy)] +pub enum RenderState { + Clean, + Dirty, +} + pub struct FemtoVGWindow { window: Window, renderer: FemtoVGRenderer, - is_dirty: Cell, + render_state: Cell, size: Cell, scale_factor: Cell, } @@ -21,7 +27,7 @@ impl FemtoVGWindow { Self { window, renderer, - is_dirty: Cell::default(), + render_state: Cell::new(RenderState::Clean), size: Cell::new(PhysicalSize::default()), scale_factor: Cell::new(1.), } @@ -29,12 +35,13 @@ impl FemtoVGWindow { } pub fn render_frame_if_dirty(&self) { - if self.is_dirty.get() { - match self.renderer.render() { - Ok(()) => {} //log::debug!("Frame rendered successfully"), - Err(e) => log::error!("Error rendering frame: {}", e), + if matches!( + self.render_state.replace(RenderState::Clean), + RenderState::Dirty + ) { + if let Err(e) = self.renderer.render() { + log::error!("Error rendering frame: {}", e); } - self.is_dirty.set(false); } } @@ -71,7 +78,7 @@ impl WindowAdapter for FemtoVGWindow { } fn request_redraw(&self) { - self.is_dirty.set(true); + self.render_state.set(RenderState::Dirty); } } diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index 51f7fec..8a5e873 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -291,6 +291,7 @@ impl WindowingSystem { .component_definition .as_ref() .ok_or_else(|| anyhow::anyhow!("Component definition not set"))?; + let (window, component_instance) = self.initialize_slint_ui(renderer, component_definition)?;