refactor: improve match on femtovg
parent
22cf1c8b70
commit
f89eea5f77
|
@ -6,10 +6,16 @@ use slint::{
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub enum RenderState {
|
||||||
|
Clean,
|
||||||
|
Dirty,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FemtoVGWindow {
|
pub struct FemtoVGWindow {
|
||||||
window: Window,
|
window: Window,
|
||||||
renderer: FemtoVGRenderer,
|
renderer: FemtoVGRenderer,
|
||||||
is_dirty: Cell<bool>,
|
render_state: Cell<RenderState>,
|
||||||
size: Cell<PhysicalSize>,
|
size: Cell<PhysicalSize>,
|
||||||
scale_factor: Cell<f32>,
|
scale_factor: Cell<f32>,
|
||||||
}
|
}
|
||||||
|
@ -21,7 +27,7 @@ impl FemtoVGWindow {
|
||||||
Self {
|
Self {
|
||||||
window,
|
window,
|
||||||
renderer,
|
renderer,
|
||||||
is_dirty: Cell::default(),
|
render_state: Cell::new(RenderState::Clean),
|
||||||
size: Cell::new(PhysicalSize::default()),
|
size: Cell::new(PhysicalSize::default()),
|
||||||
scale_factor: Cell::new(1.),
|
scale_factor: Cell::new(1.),
|
||||||
}
|
}
|
||||||
|
@ -29,12 +35,13 @@ impl FemtoVGWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_frame_if_dirty(&self) {
|
pub fn render_frame_if_dirty(&self) {
|
||||||
if self.is_dirty.get() {
|
if matches!(
|
||||||
match self.renderer.render() {
|
self.render_state.replace(RenderState::Clean),
|
||||||
Ok(()) => {} //log::debug!("Frame rendered successfully"),
|
RenderState::Dirty
|
||||||
Err(e) => log::error!("Error rendering frame: {}", e),
|
) {
|
||||||
|
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) {
|
fn request_redraw(&self) {
|
||||||
self.is_dirty.set(true);
|
self.render_state.set(RenderState::Dirty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,7 @@ impl WindowingSystem {
|
||||||
.component_definition
|
.component_definition
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| anyhow::anyhow!("Component definition not set"))?;
|
.ok_or_else(|| anyhow::anyhow!("Component definition not set"))?;
|
||||||
|
|
||||||
let (window, component_instance) =
|
let (window, component_instance) =
|
||||||
self.initialize_slint_ui(renderer, component_definition)?;
|
self.initialize_slint_ui(renderer, component_definition)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue