fix Draw (redraw)

This commit is contained in:
2026-02-21 00:19:39 -05:00
parent 426ff0adfc
commit 1aadef0e7e
3 changed files with 11 additions and 7 deletions

View File

@@ -28,7 +28,7 @@ pub trait UiRsc {
#[allow(unused_variables)] #[allow(unused_variables)]
fn on_remove(&mut self, id: WidgetId) {} fn on_remove(&mut self, id: WidgetId) {}
#[allow(unused_variables)] #[allow(unused_variables)]
fn on_draw(&mut self, active: &ActiveData) {} fn on_draw(&mut self, active: &ActiveData, redrawn: bool) {}
#[allow(unused_variables)] #[allow(unused_variables)]
fn on_undraw(&mut self, active: &ActiveData) {} fn on_undraw(&mut self, active: &ActiveData) {}

View File

@@ -81,10 +81,12 @@ impl UiRenderState {
old_children: Option<Vec<WidgetId>>, old_children: Option<Vec<WidgetId>>,
rsc: &mut dyn UiRsc, rsc: &mut dyn UiRsc,
) { ) {
let mut redrawn = old_children.is_some();
let mut old_children = old_children.unwrap_or_default(); let mut old_children = old_children.unwrap_or_default();
if let Some(active) = self.active.get_mut(&id) if let Some(active) = self.active.get_mut(&id)
&& !rsc.widgets().needs_redraw.contains(&id) && !rsc.widgets().needs_redraw.contains(&id)
{ {
redrawn = true;
// check to see if we can skip drawing first // check to see if we can skip drawing first
if active.region == region { if active.region == region {
return; return;
@@ -149,7 +151,7 @@ impl UiRenderState {
} }
} }
rsc.on_draw(&active); rsc.on_draw(&active, redrawn);
self.active.insert(id, active); self.active.insert(id, active);
} }

View File

@@ -146,12 +146,14 @@ impl<State> UiRsc for DefaultRsc<State> {
&mut self.ui &mut self.ui
} }
fn on_draw(&mut self, active: &ActiveData) { fn on_draw(&mut self, active: &ActiveData, redrawn: bool) {
self.events.draw(active); self.events.draw(active);
self.widget_events.push(WidgetEvent { if !redrawn {
id: active.id, self.widget_events.push(WidgetEvent {
ty: WidgetEventType::Draw, id: active.id,
}); ty: WidgetEventType::Draw,
});
}
} }
fn on_undraw(&mut self, active: &ActiveData) { fn on_undraw(&mut self, active: &ActiveData) {