Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework size resolution #30

Merged
merged 13 commits into from
Sep 11, 2024
2 changes: 1 addition & 1 deletion examples/egui-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn my_layout_fn(ui: &mut Ui) -> Node<Ui> {
row_spaced(
10.,
vec![
draw_b(ui).min_width(200.),
draw_b(ui).width_range(200.0..),
column_spaced(10., vec![draw_a(ui), draw_b(ui), draw_c(ui)]),
],
),
Expand Down
8 changes: 7 additions & 1 deletion src/anynode.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::models::Area;
use crate::{layout::SizeConstraints, models::Area};
use std::{any::Any, fmt, rc::Rc};

type AnyDrawFn<State> = Rc<dyn Fn(&dyn Any, &mut State)>;
pub(crate) struct AnyNode<State> {
pub(crate) inner: Box<dyn Any>,
pub(crate) clone: fn(&Box<dyn Any>) -> Box<dyn Any>,
pub(crate) layout: fn(&mut dyn Any, Area),
pub(crate) sizes: fn(&dyn Any) -> SizeConstraints,
pub(crate) draw: AnyDrawFn<State>,
}

Expand All @@ -17,6 +18,10 @@ impl<State> AnyNode<State> {
pub(crate) fn layout(&mut self, available_area: Area) {
(self.layout)(&mut *self.inner, available_area)
}

pub(crate) fn sizes(&self) -> SizeConstraints {
(self.sizes)(&*self.inner)
}
}

impl<State> Clone for AnyNode<State> {
Expand All @@ -25,6 +30,7 @@ impl<State> Clone for AnyNode<State> {
inner: (self.clone)(&self.inner),
clone: self.clone,
layout: self.layout,
sizes: self.sizes,
draw: self.draw.clone(),
}
}
Expand Down
Loading