I love control flow
This commit is contained in:
@@ -29,19 +29,20 @@ pub struct PainterCtx<'a> {
|
||||
pub textures: &'a mut Textures,
|
||||
pub masks: &'a mut TrackedArena<Mask, u32>,
|
||||
pub text: &'a mut TextData,
|
||||
pub screen_size: Vec2,
|
||||
pub output_size: Vec2,
|
||||
pub modules: &'a mut Modules,
|
||||
pub cache_width: HashMap<Id, (UiVec2, Len)>,
|
||||
pub cache_height: HashMap<Id, (UiVec2, Len)>,
|
||||
draw_started: HashSet<Id>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct ResizeRef {
|
||||
x: Option<(Id, (UiVec2, Len))>,
|
||||
y: Option<(Id, (UiVec2, Len))>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WidgetInstance {
|
||||
pub id: Id,
|
||||
pub region: UiRegion,
|
||||
@@ -75,7 +76,7 @@ impl<'a> PainterCtx<'a> {
|
||||
layers: &mut data.layers,
|
||||
textures: &mut data.textures,
|
||||
text: &mut data.text,
|
||||
screen_size: data.output_size,
|
||||
output_size: data.output_size,
|
||||
modules: &mut data.modules,
|
||||
masks: &mut data.masks,
|
||||
cache_width: Default::default(),
|
||||
@@ -91,9 +92,16 @@ impl<'a> PainterCtx<'a> {
|
||||
let Some(active) = self.active.get(&id) else {
|
||||
return;
|
||||
};
|
||||
let mut resize = active.resize;
|
||||
|
||||
// TODO: this is stupid having 2 of these
|
||||
if let Some((rid, (outer, old_desired))) = active.resize.x {
|
||||
let finish = |s: &mut Self, resize| {
|
||||
if let Some(active) = s.active.get_mut(&id) {
|
||||
active.resize = resize;
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: this is stupid having 2 of these, don't ask me what the consequences are
|
||||
if let Some((rid, (outer, old_desired))) = &mut resize.x {
|
||||
let new_desired = SizeCtx {
|
||||
source: id,
|
||||
cache_width: &mut self.cache_width,
|
||||
@@ -101,25 +109,23 @@ impl<'a> PainterCtx<'a> {
|
||||
text: self.text,
|
||||
textures: self.textures,
|
||||
widgets: self.widgets,
|
||||
outer,
|
||||
output_size: self.screen_size,
|
||||
outer: *outer,
|
||||
output_size: self.output_size,
|
||||
checked_width: &mut Default::default(),
|
||||
checked_height: &mut Default::default(),
|
||||
id,
|
||||
}
|
||||
.width_inner(id);
|
||||
if new_desired != old_desired {
|
||||
self.redraw(rid);
|
||||
if new_desired != *old_desired {
|
||||
self.redraw(*rid);
|
||||
*old_desired = new_desired;
|
||||
if self.draw_started.contains(&id) {
|
||||
return;
|
||||
return finish(self, resize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let Some(active) = self.active.get(&id) else {
|
||||
return;
|
||||
};
|
||||
if let Some((rid, (outer, old_desired))) = active.resize.y {
|
||||
if let Some((rid, (outer, old_desired))) = &mut resize.y {
|
||||
let new_desired = SizeCtx {
|
||||
source: id,
|
||||
cache_width: &mut self.cache_width,
|
||||
@@ -127,17 +133,18 @@ impl<'a> PainterCtx<'a> {
|
||||
text: self.text,
|
||||
textures: self.textures,
|
||||
widgets: self.widgets,
|
||||
outer,
|
||||
output_size: self.screen_size,
|
||||
outer: *outer,
|
||||
output_size: self.output_size,
|
||||
checked_width: &mut Default::default(),
|
||||
checked_height: &mut Default::default(),
|
||||
id,
|
||||
}
|
||||
.height_inner(id);
|
||||
if new_desired != old_desired {
|
||||
self.redraw(rid);
|
||||
if new_desired != *old_desired {
|
||||
self.redraw(*rid);
|
||||
*old_desired = new_desired;
|
||||
if self.draw_started.contains(&id) {
|
||||
return;
|
||||
return finish(self, resize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +161,7 @@ impl<'a> PainterCtx<'a> {
|
||||
active.mask,
|
||||
Some(active.children),
|
||||
);
|
||||
self.active.get_mut(&id).unwrap().resize = active.resize;
|
||||
finish(self, resize);
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, id: Id) {
|
||||
@@ -399,7 +406,7 @@ impl<'a, 'c> Painter<'a, 'c> {
|
||||
text: self.ctx.text,
|
||||
textures: self.ctx.textures,
|
||||
widgets: self.ctx.widgets,
|
||||
output_size: self.ctx.screen_size,
|
||||
output_size: self.ctx.output_size,
|
||||
checked_width: &mut self.children_width,
|
||||
checked_height: &mut self.children_height,
|
||||
cache_width: &mut self.ctx.cache_width,
|
||||
@@ -410,8 +417,12 @@ impl<'a, 'c> Painter<'a, 'c> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn output_size(&self) -> Vec2 {
|
||||
self.ctx.output_size
|
||||
}
|
||||
|
||||
pub fn px_size(&mut self) -> Vec2 {
|
||||
self.region.size().to_abs(self.ctx.screen_size)
|
||||
self.region.size().to_abs(self.ctx.output_size)
|
||||
}
|
||||
|
||||
pub fn text_data(&mut self) -> &mut TextData {
|
||||
|
||||
Reference in New Issue
Block a user