move widgets on draw if region size is same

This commit is contained in:
2025-09-27 16:11:30 -04:00
parent 5f2dffc189
commit 95f049acb4
13 changed files with 204 additions and 176 deletions

View File

@@ -59,12 +59,12 @@ impl Ui {
pub fn push<W: Widget>(&mut self, w: W) -> WidgetId<W> {
let id = self.id();
self.widgets.insert(id.id.duplicate(), w);
self.widgets.insert(id.id, w);
id
}
pub fn set<W: Widget>(&mut self, id: &WidgetId<W>, w: W) {
self.widgets.insert(id.id.duplicate(), w);
self.widgets.insert(id.id, w);
}
pub fn set_root<Tag>(&mut self, w: impl WidgetLike<Tag>) {
@@ -120,7 +120,7 @@ impl Ui {
self.size,
);
if let Some(root) = &self.root {
ctx.draw(&root.id);
ctx.draw(root.id);
}
}
@@ -144,7 +144,7 @@ impl Ui {
self.size,
);
for id in self.updates.drain(..) {
ctx.redraw(&id);
ctx.redraw(id);
}
self.free();
}
@@ -173,7 +173,7 @@ impl Ui {
}
pub fn text(&mut self, id: &WidgetId<TextEdit>) -> TextEditCtx<'_> {
self.updates.push(id.id.duplicate());
self.updates.push(id.id);
TextEditCtx {
text: self.widgets.get_mut(id).unwrap(),
font_system: &mut self.text.font_system,
@@ -191,7 +191,7 @@ impl<W: Widget> Index<&WidgetId<W>> for Ui {
impl<W: Widget> IndexMut<&WidgetId<W>> for Ui {
fn index_mut(&mut self, id: &WidgetId<W>) -> &mut Self::Output {
self.updates.push(id.id.duplicate());
self.updates.push(id.id);
self.get_mut(id).unwrap()
}
}
@@ -206,7 +206,7 @@ impl<W: Widget> Index<StaticWidgetId<W>> for Ui {
impl<W: Widget> IndexMut<StaticWidgetId<W>> for Ui {
fn index_mut(&mut self, id: StaticWidgetId<W>) -> &mut Self::Output {
self.updates.push(id.id.id());
self.updates.push(id.id);
self.widgets.get_static_mut(&id).unwrap()
}
}