mistakes were fixed and sins were committed
This commit is contained in:
@@ -6,22 +6,35 @@ pub struct Sized {
|
||||
pub y: Option<Len>,
|
||||
}
|
||||
|
||||
impl Sized {
|
||||
fn apply_to_outer(&self, ctx: &mut SizeCtx) {
|
||||
if let Some(x) = self.x {
|
||||
let outer = ctx.outer.axis(Axis::X);
|
||||
ctx.outer
|
||||
.axis_mut(Axis::X)
|
||||
.set(x.apply_rest().within_len(outer));
|
||||
}
|
||||
if let Some(y) = self.y {
|
||||
let outer = ctx.outer.axis(Axis::Y);
|
||||
ctx.outer
|
||||
.axis_mut(Axis::Y)
|
||||
.set(y.apply_rest().within_len(outer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for Sized {
|
||||
fn draw(&mut self, painter: &mut Painter) {
|
||||
painter.widget(&self.inner);
|
||||
}
|
||||
|
||||
fn desired_size(&mut self, ctx: &mut SizeCtx) -> Size {
|
||||
let rel = ctx.size.rel;
|
||||
if let Some(x) = self.x {
|
||||
ctx.size.axis_mut(Axis::X).set(x.apply_rest(rel.x));
|
||||
}
|
||||
if let Some(y) = self.y {
|
||||
ctx.size.axis_mut(Axis::Y).set(y.apply_rest(rel.y));
|
||||
}
|
||||
Size {
|
||||
x: self.x.unwrap_or_else(|| ctx.size(&self.inner).x),
|
||||
y: self.y.unwrap_or_else(|| ctx.size(&self.inner).y),
|
||||
}
|
||||
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
self.apply_to_outer(ctx);
|
||||
self.x.unwrap_or_else(|| ctx.width(&self.inner))
|
||||
}
|
||||
|
||||
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
self.apply_to_outer(ctx);
|
||||
self.y.unwrap_or_else(|| ctx.height(&self.inner))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user