initial text wrapping impl (resizing will break)
This commit is contained in:
@@ -14,6 +14,9 @@ pub struct Painter<'a, 'c> {
|
||||
primitives: Vec<PrimitiveHandle>,
|
||||
children: Vec<Id>,
|
||||
sized_children: HashMap<Id, UiVec2>,
|
||||
/// whether this widget depends on region's final pixel size or not
|
||||
/// TODO: decide if point (pt) should be used here instead of px
|
||||
px_dependent: bool,
|
||||
pub layer: usize,
|
||||
id: Id,
|
||||
}
|
||||
@@ -75,8 +78,10 @@ impl<'a> PainterCtx<'a> {
|
||||
text: self.text,
|
||||
textures: self.textures,
|
||||
widgets: self.widgets,
|
||||
region: UiRegion::full(),
|
||||
screen_size: self.screen_size,
|
||||
};
|
||||
let desired = ctx.size_inner(id);
|
||||
let desired = ctx.size_inner(id, active.region);
|
||||
if size != desired {
|
||||
self.redraw(rid);
|
||||
if self.drawing.contains(&id) {
|
||||
@@ -152,6 +157,7 @@ impl<'a> PainterCtx<'a> {
|
||||
ctx: self,
|
||||
children: Vec::new(),
|
||||
sized_children: Default::default(),
|
||||
px_dependent: false,
|
||||
};
|
||||
|
||||
// draw widgets
|
||||
@@ -305,9 +311,16 @@ impl<'a, 'c> Painter<'a, 'c> {
|
||||
textures: self.ctx.textures,
|
||||
widgets: self.ctx.widgets,
|
||||
checked: &mut self.sized_children,
|
||||
screen_size: self.ctx.screen_size,
|
||||
region: self.region,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn px_size(&mut self) -> Vec2 {
|
||||
self.px_dependent = true;
|
||||
self.region.in_size(self.ctx.screen_size)
|
||||
}
|
||||
|
||||
pub fn text_data(&mut self) -> &mut TextData {
|
||||
self.ctx.text
|
||||
}
|
||||
@@ -326,11 +339,16 @@ pub struct SizeCtx<'a> {
|
||||
pub textures: &'a mut Textures,
|
||||
widgets: &'a Widgets,
|
||||
checked: &'a mut HashMap<Id, UiVec2>,
|
||||
region: UiRegion,
|
||||
screen_size: Vec2,
|
||||
}
|
||||
|
||||
impl SizeCtx<'_> {
|
||||
fn size_inner(&mut self, id: Id) -> UiVec2 {
|
||||
fn size_inner(&mut self, id: Id, region: UiRegion) -> UiVec2 {
|
||||
let self_region = self.region;
|
||||
self.region = region;
|
||||
let size = self.widgets.get_dyn_dynamic(id).desired_size(self);
|
||||
self.region = self_region;
|
||||
self.checked.insert(id, size);
|
||||
size
|
||||
}
|
||||
@@ -339,7 +357,13 @@ impl SizeCtx<'_> {
|
||||
// if let Some(size) = self.checked.get(&id.id) {
|
||||
// return Some(*size);
|
||||
// }
|
||||
self.size_inner(id.id)
|
||||
self.size_inner(id.id, self.region)
|
||||
}
|
||||
pub fn size_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) -> UiVec2 {
|
||||
self.size_inner(id.id, region.within(&self.region))
|
||||
}
|
||||
pub fn px_size(&self) -> Vec2 {
|
||||
self.region.in_size(self.screen_size)
|
||||
}
|
||||
pub fn draw_text(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user