SENSORS
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
use crate::{
|
||||
UiRegion, WidgetId, Widgets,
|
||||
SenseFn, SenseTrigger, Sensors, UiRegion, WidgetId, Widgets,
|
||||
primitive::{PrimitiveData, PrimitiveInstance, Primitives},
|
||||
};
|
||||
|
||||
pub struct Painter<'a, Ctx> {
|
||||
nodes: &'a Widgets<Ctx>,
|
||||
ctx: &'a mut Ctx,
|
||||
sensors: &'a mut Sensors<Ctx>,
|
||||
primitives: Primitives,
|
||||
pub region: UiRegion,
|
||||
}
|
||||
|
||||
impl<'a, Ctx> Painter<'a, Ctx> {
|
||||
pub fn new(nodes: &'a Widgets<Ctx>, ctx: &'a mut Ctx) -> Self {
|
||||
pub fn new(nodes: &'a Widgets<Ctx>, ctx: &'a mut Ctx, sensors: &'a mut Sensors<Ctx>) -> Self {
|
||||
Self {
|
||||
nodes,
|
||||
ctx,
|
||||
sensors,
|
||||
primitives: Primitives::default(),
|
||||
region: UiRegion::full(),
|
||||
}
|
||||
@@ -31,17 +33,27 @@ impl<'a, Ctx> Painter<'a, Ctx> {
|
||||
.extend_from_slice(bytemuck::cast_slice::<_, u32>(&[data]));
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, id: &WidgetId) where Ctx: 'static {
|
||||
pub fn draw(&mut self, id: &WidgetId)
|
||||
where
|
||||
Ctx: 'static,
|
||||
{
|
||||
self.nodes.get_dyn(id).draw(self);
|
||||
}
|
||||
|
||||
pub fn draw_within(&mut self, node: &WidgetId, region: UiRegion) where Ctx: 'static {
|
||||
pub fn draw_within(&mut self, node: &WidgetId, region: UiRegion)
|
||||
where
|
||||
Ctx: 'static,
|
||||
{
|
||||
let old = self.region;
|
||||
self.region.select(®ion);
|
||||
self.draw(node);
|
||||
self.region = old;
|
||||
}
|
||||
|
||||
pub fn sense(&mut self, trigger: SenseTrigger, f: Box<dyn SenseFn<Ctx>>) {
|
||||
self.sensors.push((trigger, f));
|
||||
}
|
||||
|
||||
pub fn finish(self) -> Primitives {
|
||||
self.primitives
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user