refactor project structure (start of redoing atomic branch without atomics)
This commit is contained in:
48
src/widget/position/max_size.rs
Normal file
48
src/widget/position/max_size.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct MaxSize {
|
||||
pub inner: WidgetId,
|
||||
pub x: Option<Len>,
|
||||
pub y: Option<Len>,
|
||||
}
|
||||
|
||||
impl MaxSize {
|
||||
fn apply_to_outer(&self, ctx: &mut SizeCtx) {
|
||||
if let Some(x) = self.x {
|
||||
ctx.outer.x.select_len(x.apply_rest());
|
||||
}
|
||||
if let Some(y) = self.y {
|
||||
ctx.outer.y.select_len(y.apply_rest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for MaxSize {
|
||||
fn draw(&mut self, painter: &mut Painter) {
|
||||
painter.widget(&self.inner);
|
||||
}
|
||||
|
||||
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
self.apply_to_outer(ctx);
|
||||
let width = ctx.width(&self.inner);
|
||||
if let Some(x) = self.x {
|
||||
let width_px = width.apply_rest().to_abs(ctx.output_size().x);
|
||||
let x_px = x.apply_rest().to_abs(ctx.output_size().x);
|
||||
if width_px > x_px { x } else { width }
|
||||
} else {
|
||||
width
|
||||
}
|
||||
}
|
||||
|
||||
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||
self.apply_to_outer(ctx);
|
||||
let height = ctx.height(&self.inner);
|
||||
if let Some(y) = self.y {
|
||||
let height_px = height.apply_rest().to_abs(ctx.output_size().y);
|
||||
let y_px = y.apply_rest().to_abs(ctx.output_size().y);
|
||||
if height_px > y_px { y } else { height }
|
||||
} else {
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user