diff --git a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt index 3e99464ee5..3a1e39624b 100644 --- a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt +++ b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt @@ -46,7 +46,7 @@ public data class Shrink( /** * Add additional space around the item. */ -@Modifier(3, RowScope::class, ColumnScope::class) +@Modifier(3, RowScope::class, ColumnScope::class, BoxScope::class) public data class Margin( val margin: app.cash.redwood.ui.Margin, ) @@ -54,7 +54,7 @@ public data class Margin( /** * Set the alignment for an item along the horizontal axis. */ -@Modifier(4, ColumnScope::class) +@Modifier(4, ColumnScope::class, BoxScope::class) public data class HorizontalAlignment( val alignment: CrossAxisAlignment, ) @@ -62,7 +62,7 @@ public data class HorizontalAlignment( /** * Set the alignment for an item along the vertical axis. */ -@Modifier(5, RowScope::class) +@Modifier(5, RowScope::class, BoxScope::class) public data class VerticalAlignment( val alignment: CrossAxisAlignment, ) @@ -70,7 +70,7 @@ public data class VerticalAlignment( /** * Set a required width for an item. */ -@Modifier(6, RowScope::class, ColumnScope::class) +@Modifier(6, RowScope::class, ColumnScope::class, BoxScope::class) public data class Width( val width: Dp, ) @@ -78,7 +78,7 @@ public data class Width( /** * Set a required height for an item. */ -@Modifier(7, RowScope::class, ColumnScope::class) +@Modifier(7, RowScope::class, ColumnScope::class, BoxScope::class) public data class Height( val height: Dp, ) @@ -86,7 +86,7 @@ public data class Height( /** * Set a required width and height for an item. */ -@Modifier(8, RowScope::class, ColumnScope::class) +@Modifier(8, RowScope::class, ColumnScope::class, BoxScope::class) public data class Size( val width: Dp, val height: Dp, diff --git a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt index 035e8e6b1f..1e100e5742 100644 --- a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt +++ b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt @@ -19,17 +19,23 @@ import app.cash.redwood.schema.Schema @Schema( [ - Row::class, + // Widgets + Box::class, Column::class, + Row::class, Spacer::class, + // Next tag: 5 + + // Modifiers Grow::class, - Shrink::class, - Margin::class, + Height::class, HorizontalAlignment::class, + Margin::class, + Shrink::class, + Size::class, VerticalAlignment::class, Width::class, - Height::class, - Size::class, + // Next tag: 9 ], ) public interface RedwoodLayout diff --git a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/widgets.kt b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/widgets.kt index d8868e4a88..7a37dd3f36 100644 --- a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/widgets.kt +++ b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/widgets.kt @@ -169,3 +169,59 @@ public data class Spacer( @Default("Dp(0.0)") val height: Dp, ) + +/** + * Lays out widgets along the z-axis in a column. + * + * Minimum and maximum heights do not include margins. + */ +@Widget(4) +public data class Box( + /** + * Sets whether the box's width will match its widest child ([Constraint.Wrap]) or match the width + * of its parent ([Constraint.Fill]). + */ + @Property(1) + @Default("Constraint.Wrap") + val width: Constraint, + + @Property(2) + @Default("Dp(0.0)") + val minWidth: Dp, + + @Property(3) + @Default("Dp(Double.MAX_VALUE)") + val maxWidth: Dp, + + /** + * Sets whether the box's height will match its tallest child ([Constraint.Wrap]) or match the + * height of its parent ([Constraint.Fill]). + */ + @Property(4) + @Default("Constraint.Wrap") + val height: Constraint, + + @Property(5) + @Default("Dp(0.0)") + val minHeight: Dp, + + @Property(6) + @Default("Dp(Double.MAX_VALUE)") + val maxHeight: Dp, + + /** + * Applies margin (space) around the box. + * + * This can also be applied to an individual widget using `Modifier.margin`. + */ + @Property(7) + @Default("Margin.Zero") + val margin: Margin, + + /** + * A slot to add widgets in. + */ + @Children(1) val children: BoxScope.() -> Unit, +) + +public object BoxScope