initial global widget store
This commit is contained in:
1 parent
7f4846a2d3
commit
6156c66a20
31 files changed
+536
-352
No files matched your search
+7
-20
@@ -2,32 +2,24 @@ use image::DynamicImage;
|
||||
|
||||
use crate::{
|
||||
layout::{
|
||||
IdLike, PainterData, PixelRegion, TextureHandle, Vec2, Widget, WidgetInstance, WidgetLike,
|
||||
WidgetRef, WidgetUpdate,
|
||||
IdLike, PainterData, PixelRegion, TextureHandle, Vec2, Widget, WidgetHandle, WidgetId,
|
||||
WidgetInstance, WidgetLike, WidgetUpdate,
|
||||
},
|
||||
util::{HashSet, Id},
|
||||
util::HashSet,
|
||||
};
|
||||
use std::sync::mpsc::{Receiver, channel};
|
||||
|
||||
pub struct Ui {
|
||||
pub(crate) data: PainterData,
|
||||
root: Option<WidgetRef>,
|
||||
updates: HashSet<Id>,
|
||||
free: Vec<Id>,
|
||||
root: Option<WidgetHandle>,
|
||||
updates: HashSet<WidgetId>,
|
||||
free: Vec<WidgetId>,
|
||||
recv: Receiver<WidgetUpdate>,
|
||||
full_redraw: bool,
|
||||
resized: bool,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn add<W: Widget, Tag>(&mut self, w: impl WidgetLike<Tag, Widget = W>) -> WidgetRef<W> {
|
||||
w.add(self)
|
||||
}
|
||||
|
||||
pub fn add_widget<W: Widget>(&mut self, w: W) -> WidgetRef<W> {
|
||||
self.data.widgets.insert(w)
|
||||
}
|
||||
|
||||
pub fn set_root<Tag>(&mut self, w: impl WidgetLike<Tag>) {
|
||||
self.root = Some(w.add(self));
|
||||
self.full_redraw = true;
|
||||
@@ -97,7 +89,6 @@ impl Ui {
|
||||
for m in self.data.modules.iter_mut() {
|
||||
m.on_remove(&id);
|
||||
}
|
||||
self.data.widgets.delete(id);
|
||||
}
|
||||
self.data.textures.free();
|
||||
}
|
||||
@@ -106,10 +97,6 @@ impl Ui {
|
||||
self.full_redraw || !self.updates.is_empty()
|
||||
}
|
||||
|
||||
pub fn num_widgets(&self) -> usize {
|
||||
self.data.widgets.len()
|
||||
}
|
||||
|
||||
pub fn active_widgets(&self) -> usize {
|
||||
self.data.active.len()
|
||||
}
|
||||
@@ -133,7 +120,7 @@ impl Ui {
|
||||
|
||||
pub fn debug(&self, label: &str) -> impl Iterator<Item = &WidgetInstance> {
|
||||
self.data.active.iter().filter_map(move |(id, inst)| {
|
||||
let widget = &self.data.widgets.get(*id);
|
||||
let widget = id.strong().unwrap();
|
||||
if widget.get_label().as_str() == label {
|
||||
Some(inst)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user