Skip to content

Commit

Permalink
Merge pull request #30 from ejjonny/rework
Browse files Browse the repository at this point in the history
Rework size resolution
  • Loading branch information
cyypherus authored Sep 11, 2024
2 parents 05db101 + 1548b9c commit 67558fb
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 122 deletions.
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

0 comments on commit 67558fb

Please sign in to comment.