sized spans!
This commit is contained in:
@@ -10,7 +10,7 @@ impl Widget for Image {
|
||||
painter.draw_texture(&self.handle);
|
||||
}
|
||||
|
||||
fn size(&mut self, _: SizeCtx) -> Vec2 {
|
||||
fn size(&mut self, _: &mut SizeCtx) -> Vec2 {
|
||||
self.handle.size()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct Span {
|
||||
|
||||
impl Widget for Span {
|
||||
fn draw(&mut self, painter: &mut Painter) {
|
||||
let total = self.setup(painter);
|
||||
let total = self.setup(&mut painter.size_ctx());
|
||||
let mut start = UIScalar::min();
|
||||
for (child, length) in &self.children {
|
||||
let mut child_region = UiRegion::full();
|
||||
@@ -44,6 +44,17 @@ impl Widget for Span {
|
||||
painter.draw_within(child, child_region);
|
||||
}
|
||||
}
|
||||
|
||||
fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 {
|
||||
let total = self.setup(ctx);
|
||||
let axis = self.dir.axis;
|
||||
let dir_len = if total.ratio != 0.0 {
|
||||
ctx.size.axis(axis)
|
||||
} else {
|
||||
total.fixed + total.relative * ctx.screen_size.axis(axis)
|
||||
};
|
||||
Vec2::from_axis(axis, dir_len, total.max_sized)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -51,6 +62,7 @@ pub struct SpanLenSums {
|
||||
pub fixed: f32,
|
||||
pub ratio: f32,
|
||||
pub relative: f32,
|
||||
pub max_sized: f32,
|
||||
}
|
||||
|
||||
impl Span {
|
||||
@@ -61,7 +73,7 @@ impl Span {
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(&mut self, painter: &mut Painter) -> SpanLenSums {
|
||||
fn setup(&mut self, ctx: &mut SizeCtx) -> SpanLenSums {
|
||||
self.children
|
||||
.iter_mut()
|
||||
.fold(SpanLenSums::default(), |mut s, (id, l)| {
|
||||
@@ -70,8 +82,9 @@ impl Span {
|
||||
SpanLen::Ratio(v) => s.ratio += *v,
|
||||
SpanLen::Relative(v) => s.relative += *v,
|
||||
SpanLen::Sized(v) => {
|
||||
let size = painter.size(id);
|
||||
let size = ctx.size(id);
|
||||
let len = size.axis(self.dir.axis);
|
||||
s.max_sized = s.max_sized.max(size.axis(!self.dir.axis));
|
||||
*v = size;
|
||||
s.fixed += len;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Widget for Text {
|
||||
// reuse TextureHandle
|
||||
}
|
||||
|
||||
fn size(&mut self, ctx: SizeCtx) -> Vec2 {
|
||||
fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 {
|
||||
let (handle, offset) =
|
||||
ctx.text
|
||||
.draw(&mut self.buf, &self.content, &self.attrs, ctx.textures);
|
||||
|
||||
Reference in New Issue
Block a user