TAG TECHNOLOGY

This commit is contained in:
2025-08-14 12:21:26 -04:00
parent 4d68fa476d
commit e41970287d
19 changed files with 267 additions and 165 deletions

View File

@@ -1,20 +1,22 @@
use crate::{
UIRegion, WidgetId, Widgets,
UiRegion, WidgetId, Widgets,
primitive::{PrimitiveData, PrimitiveInstance, Primitives},
};
pub struct Painter<'a> {
nodes: &'a Widgets,
pub struct Painter<'a, Ctx> {
nodes: &'a Widgets<Ctx>,
ctx: &'a mut Ctx,
primitives: Primitives,
pub region: UIRegion,
pub region: UiRegion,
}
impl<'a> Painter<'a> {
pub fn new(nodes: &'a Widgets) -> Self {
impl<'a, Ctx> Painter<'a, Ctx> {
pub fn new(nodes: &'a Widgets<Ctx>, ctx: &'a mut Ctx) -> Self {
Self {
nodes,
ctx,
primitives: Primitives::default(),
region: UIRegion::full(),
region: UiRegion::full(),
}
}
pub fn write<Data: PrimitiveData>(&mut self, data: Data) {
@@ -28,10 +30,12 @@ impl<'a> Painter<'a> {
.data
.extend_from_slice(bytemuck::cast_slice::<_, u32>(&[data]));
}
pub fn draw(&mut self, node: &WidgetId) {
self.nodes.get_dyn(node).draw(self);
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) {
pub fn draw_within(&mut self, node: &WidgetId, region: UiRegion) where Ctx: 'static {
let old = self.region;
self.region.select(&region);
self.draw(node);
@@ -41,4 +45,8 @@ impl<'a> Painter<'a> {
pub fn finish(self) -> Primitives {
self.primitives
}
pub fn ctx_mut(&mut self) -> &mut Ctx {
&mut self.ctx
}
}