diff --git a/src/theme_definition.rs b/src/theme_definition.rs index 97feff4..f42b252 100644 --- a/src/theme_definition.rs +++ b/src/theme_definition.rs @@ -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. diff --git a/src/widget.rs b/src/widget.rs index e5697b6..d713592 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -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, } } @@ -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; + } + } } }