Skip to content

Commit

Permalink
Merge pull request #21 from ejjonny/inline-size
Browse files Browse the repository at this point in the history
Inline size constraints, respect relative constraints in sequences, add some tests
  • Loading branch information
cyypherus authored Sep 8, 2024
2 parents 5485a21 + 8622c36 commit bf5f1c7
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 199 deletions.
5 changes: 3 additions & 2 deletions 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).size(Size::new().width(180.).x_align(XAlign::Leading)),
draw_b(ui).min_width(200.),
column_spaced(10., vec![draw_a(ui), draw_b(ui), draw_c(ui)]),
],
),
Expand Down Expand Up @@ -64,7 +64,8 @@ fn draw_label(ui: &mut Ui, text: String) -> Node<Ui> {
egui::Label::new(RichText::new(text.clone()).size(10.)),
);
})
.size(Size::new().width(text_area.width).height(text_area.height))
.width(text_area.width)
.height(text_area.height)
}

fn draw_rect(color: Color32, stroke: bool) -> Node<Ui> {
Expand Down
83 changes: 27 additions & 56 deletions examples/macroquad-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,29 @@ fn layout_for_highlight(ctx: &mut State) -> Node<State> {
text("Alignment & Offset", 15., WHITE),
stack(vec![
rect(BLUE),
rect(WHITE).size(
Size::new().height(30.).width(30.).x_align(XAlign::Leading),
),
rect(WHITE).size(
Size::new().height(30.).width(30.).x_align(XAlign::Trailing),
),
rect(WHITE).height(30.).width(30.).x_align(XAlign::Leading),
rect(WHITE).height(30.).width(30.).x_align(XAlign::Trailing),
rect(WHITE).height(30.).width(30.).y_align(YAlign::Top),
rect(WHITE).height(30.).width(30.).y_align(YAlign::Bottom),
rect(WHITE).height(30.).width(30.).align(Align::TopLeading),
rect(WHITE)
.size(Size::new().height(30.).width(30.).y_align(YAlign::Top)),
rect(WHITE).size(
Size::new().height(30.).width(30.).y_align(YAlign::Bottom),
),
rect(WHITE).size(
Size::new().height(30.).width(30.).align(Align::TopLeading),
),
rect(WHITE).size(
Size::new()
.height(30.)
.width(30.)
.align(Align::BottomLeading),
),
rect(WHITE).size(
Size::new()
.height(30.)
.width(30.)
.align(Align::BottomTrailing),
),
rect(WHITE).size(
Size::new().height(30.).width(30.).align(Align::TopTrailing),
),
.height(30.)
.width(30.)
.align(Align::BottomLeading),
rect(WHITE)
.size(
Size::new()
.height(30.)
.width(30.)
.align(Align::CenterCenter),
)
.height(30.)
.width(30.)
.align(Align::BottomTrailing),
rect(WHITE).height(30.).width(30.).align(Align::TopTrailing),
rect(WHITE)
.height(30.)
.width(30.)
.align(Align::CenterCenter)
.offset(10., 10.),
rect(WHITE)
.size(
Size::new()
.height(30.)
.width(30.)
.align(Align::CenterCenter),
)
.height(30.)
.width(30.)
.align(Align::CenterCenter)
.offset(-10., -10.),
]),
button("Fullscreen", |ctx: &mut State| {
Expand All @@ -111,7 +90,8 @@ fn layout_for_highlight(ctx: &mut State) -> Node<State> {
ctx.highlight = HighlightedCase::AlignmentOffset;
}
})
.size(Size::new().height(BTN_SIZE).y_align(YAlign::Bottom)),
.height(BTN_SIZE)
.y_align(YAlign::Bottom),
],
);
}
Expand All @@ -130,15 +110,8 @@ fn rel_abs_seq(highlight: HighlightedCase) -> Node<HighlightedCase> {
text("Mixed (rel/abs) Sequence Constraints", 15., WHITE),
stack(vec![
rect(BLUE),
column_spaced(
10.,
vec![
rect(WHITE),
rect(WHITE).size(Size::new().height(30.)),
rect(WHITE),
],
)
.pad(10.),
column_spaced(10., vec![rect(WHITE), rect(WHITE).height(30.), rect(WHITE)])
.pad(10.),
]),
button("Fullscreen", |highlight: &mut HighlightedCase| {
if *highlight == HighlightedCase::RelAbsSequence {
Expand All @@ -147,7 +120,8 @@ fn rel_abs_seq(highlight: HighlightedCase) -> Node<HighlightedCase> {
*highlight = HighlightedCase::RelAbsSequence;
}
})
.size(Size::new().height(BTN_SIZE).y_align(YAlign::Bottom)),
.height(BTN_SIZE)
.y_align(YAlign::Bottom),
],
);
}
Expand All @@ -166,11 +140,8 @@ fn text<U>(string: &'static str, font_size: f32, color: Color) -> Node<U> {
color,
);
})
.size(
Size::new()
.width(dimensions.width)
.height(dimensions.height),
)
.width(dimensions.width)
.height(dimensions.height)
}

fn rect<U>(color: Color) -> Node<U> {
Expand Down
Loading

0 comments on commit bf5f1c7

Please sign in to comment.