sensors are now normal
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
layout::{
|
||||
Active, Layers, TextAttrs, TextBuffer, TextData, TextOffset, TextureHandle, Textures,
|
||||
UiRegion, UiVec2, Vec2, WidgetId, Widgets,
|
||||
ActiveWidgets, Layers, TextAttrs, TextBuffer, TextData, TextOffset, TextureHandle,
|
||||
Textures, UiRegion, UiVec2, Vec2, WidgetId, Widgets,
|
||||
},
|
||||
render::{Primitive, PrimitiveHandle, Primitives},
|
||||
render::{Primitive, PrimitiveHandle},
|
||||
util::{HashMap, HashSet, Id, IdUtil},
|
||||
};
|
||||
|
||||
@@ -20,8 +20,8 @@ pub struct Painter<'a, 'c> {
|
||||
|
||||
pub struct PainterCtx<'a> {
|
||||
pub widgets: &'a Widgets,
|
||||
pub active: &'a mut Active,
|
||||
pub layers: &'a mut Layers<Primitives>,
|
||||
pub active: &'a mut ActiveWidgets,
|
||||
pub layers: &'a mut Layers,
|
||||
pub textures: &'a mut Textures,
|
||||
pub text: &'a mut TextData,
|
||||
pub screen_size: Vec2,
|
||||
@@ -42,8 +42,8 @@ pub struct WidgetInstance {
|
||||
impl<'a> PainterCtx<'a> {
|
||||
pub fn new(
|
||||
widgets: &'a Widgets,
|
||||
layers: &'a mut Layers<Primitives>,
|
||||
active: &'a mut Active,
|
||||
layers: &'a mut Layers,
|
||||
active: &'a mut ActiveWidgets,
|
||||
textures: &'a mut Textures,
|
||||
text: &'a mut TextData,
|
||||
screen_size: Vec2,
|
||||
@@ -61,7 +61,7 @@ impl<'a> PainterCtx<'a> {
|
||||
|
||||
pub fn redraw(&mut self, id: &Id) {
|
||||
self.drawing.clear();
|
||||
let Some(active) = self.active.widgets.get(id) else {
|
||||
let Some(active) = self.active.get(id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ impl<'a> PainterCtx<'a> {
|
||||
active.parent.duplicate(),
|
||||
Some(active.children),
|
||||
);
|
||||
self.active.widgets.get_mut(id).unwrap().resize = active.resize;
|
||||
self.active.get_mut(id).unwrap().resize = active.resize;
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, id: &Id) {
|
||||
@@ -111,7 +111,7 @@ impl<'a> PainterCtx<'a> {
|
||||
}
|
||||
let mut old_children = old_children.unwrap_or_default();
|
||||
let mut resize = None;
|
||||
if let Some(active) = self.active.widgets.get_mut(id) {
|
||||
if let Some(active) = self.active.get_mut(id) {
|
||||
if active.parent != parent {
|
||||
panic!("Cannot draw the same widget twice (2)");
|
||||
}
|
||||
@@ -155,7 +155,7 @@ impl<'a> PainterCtx<'a> {
|
||||
layer,
|
||||
};
|
||||
for (cid, size) in sized_children {
|
||||
if let Some(w) = self.active.widgets.get_mut(&cid) {
|
||||
if let Some(w) = self.active.get_mut(&cid) {
|
||||
w.resize = Some((id.duplicate(), size))
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,12 @@ impl<'a> PainterCtx<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
self.active.add(id, instance, self.widgets);
|
||||
if self.widgets.data(id).is_some_and(|w| w.sensor) {
|
||||
self.layers[layer]
|
||||
.sensors
|
||||
.insert(id.duplicate(), instance.region);
|
||||
}
|
||||
self.active.insert(id.duplicate(), instance);
|
||||
}
|
||||
|
||||
/// NOTE: instance textures are cleared and self.textures freed
|
||||
@@ -177,6 +182,7 @@ impl<'a> PainterCtx<'a> {
|
||||
}
|
||||
inst.textures.clear();
|
||||
self.textures.free();
|
||||
self.layers[inst.layer].sensors.remove(id);
|
||||
}
|
||||
inst
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user