learn how workspaces + proc macros work & restructure everything
This commit is contained in:
34
src/widget/position/sized.rs
Normal file
34
src/widget/position/sized.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Sized {
|
||||
pub inner: WidgetRef,
|
||||
pub x: Option<Len>,
|
||||
pub y: Option<Len>,
|
||||
}
|
||||
|
||||
impl Sized {
|
||||
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 Sized {
|
||||
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);
|
||||
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