Skip to content

Commit

Permalink
Add Box widget schema for redwood layout
Browse files Browse the repository at this point in the history
  • Loading branch information
underscoretang committed Sep 27, 2023
1 parent 9256c31 commit bc765e8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,47 @@ 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,
)

/**
* 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,
)

/**
* 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,
)

/**
* 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,
)

/**
* 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,
)

/**
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc765e8

Please sign in to comment.