1 Commits

Author SHA1 Message Date
1aadef0e7e fix Draw (redraw) 2026-02-21 00:19:39 -05:00
3 changed files with 11 additions and 7 deletions

View File

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

View File

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

View File

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