Skip to content

Commit

Permalink
simple grid layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Grokmoo committed Jan 17, 2024
1 parent c1fb6f0 commit d07f648
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/theme_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ pub enum Layout {
/// Don't layout children in any order. Children must specify manual alignments to
/// avoid overlap.
Free,

/// Layout children in grid rows, left to right, starting a new row
/// to prevent placing children outside the parent inner bounds.
Grid,
}

/// Widget or text horizontal and vertical alignment.
Expand Down
8 changes: 8 additions & 0 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl Widget {
Layout::Horizontal => self.cursor.x += gap,
Layout::Vertical => self.cursor.y += gap,
Layout::Free => (),
Layout::Grid => self.cursor.x += gap,
}
}

Expand Down Expand Up @@ -1260,6 +1261,13 @@ impl<'a> WidgetBuilder<'a> {
Horizontal => parent.cursor.x += x + parent.layout_spacing.x,
Vertical => parent.cursor.y += y + parent.layout_spacing.y,
Free => (),
Grid => {
parent.cursor.x += x + parent.layout_spacing.x;
if parent.cursor.x + size.x > parent.inner_size().x {
parent.cursor.x = 0.0;
parent.cursor.y += y + parent.layout_spacing.y;
}
}
}
}

Expand Down

0 comments on commit d07f648

Please sign in to comment.