Skip to content

Commit

Permalink
Add spacing between buttons in button panels
Browse files Browse the repository at this point in the history
For #11
  • Loading branch information
kirill-grouchnikov committed Feb 1, 2022
1 parent 4582d80 commit edf3813
Showing 1 changed file with 29 additions and 13 deletions.
Expand Up @@ -53,10 +53,12 @@ import kotlin.math.max
@OptIn(AuroraInternalApi::class)
private fun LazyListScope.rowOfItems(
composeWindow: ComposeWindow,
backgroundColor: Color, gap: Dp,
backgroundColor: Color,
gap: Dp,
commandGroup: CommandGroup,
extraAction: (() -> Unit)? = null,
indexRowStart: Int, indexRowEnd: Int,
indexRowStart: Int,
indexRowEnd: Int,
itemWidth: Dp,
commandActionPreview: CommandActionPreview?,
baseCommandButtonPresentationModel: CommandButtonPresentationModel,
Expand Down Expand Up @@ -89,6 +91,9 @@ private fun LazyListScope.rowOfItems(
presentationModel = commandPresentation,
overlays = overlays
)
if (index != (indexRowEnd - 1)) {
Spacer(modifier = Modifier.width(gap))
}
}
}
}
Expand All @@ -97,10 +102,12 @@ private fun LazyListScope.rowOfItems(
@OptIn(AuroraInternalApi::class)
private fun LazyListScope.columnOfItems(
composeWindow: ComposeWindow,
backgroundColor: Color, gap: Dp,
backgroundColor: Color,
gap: Dp,
commandGroup: CommandGroup,
extraAction: (() -> Unit)? = null,
indexRowStart: Int, indexRowEnd: Int,
indexColumnStart: Int,
indexColumnEnd: Int,
itemHeight: Dp,
commandActionPreview: CommandActionPreview?,
baseCommandButtonPresentationModel: CommandButtonPresentationModel,
Expand All @@ -112,7 +119,7 @@ private fun LazyListScope.columnOfItems(
.background(backgroundColor)
.padding(horizontal = gap / 2.0f, vertical = gap)
) {
for (index in indexRowStart until indexRowEnd) {
for (index in indexColumnStart until indexColumnEnd) {
val command = commandGroup.commands[index]
// Apply overlay if we have one registered for the current command
val commandPresentation = if (overlays.containsKey(command))
Expand All @@ -133,6 +140,9 @@ private fun LazyListScope.columnOfItems(
presentationModel = commandPresentation,
overlays = overlays
)
if (index != (indexColumnEnd - 1)) {
Spacer(modifier = Modifier.height(gap))
}
}
}
}
Expand Down Expand Up @@ -261,10 +271,13 @@ internal fun AuroraCommandButtonPanel(
is PanelLayoutSpec.RowFill -> {
val columnCount: Int = when (presentationModel.layoutSpec.rowFillSpec) {
is PanelRowFillSpec.Fixed -> presentationModel.layoutSpec.rowFillSpec.columnCount
is PanelRowFillSpec.Adaptive -> (constraints.maxWidth - gapPx) /
(presentationModel.layoutSpec.rowFillSpec.minColumnWidth.roundToPx() + gapPx)
is PanelRowFillSpec.Adaptive ->
(constraints.maxWidth - contentStartPadding.roundToPx()
- contentEndPadding.roundToPx() - gapPx) /
(presentationModel.layoutSpec.rowFillSpec.minColumnWidth.roundToPx() + gapPx)
}
val itemWidth = (constraints.maxWidth - gapPx * (columnCount + 1)) / columnCount
val itemWidth = (constraints.maxWidth - contentStartPadding.roundToPx()
- contentEndPadding.roundToPx() - gapPx * (columnCount + 1)) / columnCount

panelPlaceable = subcompose(0) {
Box(modifier = modifier.fillMaxSize()) {
Expand Down Expand Up @@ -325,10 +338,13 @@ internal fun AuroraCommandButtonPanel(
is PanelLayoutSpec.ColumnFill -> {
val rowCount: Int = when (presentationModel.layoutSpec.columnFillSpec) {
is PanelColumnFillSpec.Fixed -> presentationModel.layoutSpec.columnFillSpec.rowCount
is PanelColumnFillSpec.Adaptive -> (constraints.maxHeight - gapPx) /
(presentationModel.layoutSpec.columnFillSpec.minRowHeight.roundToPx() + gapPx)
is PanelColumnFillSpec.Adaptive ->
(constraints.maxHeight - contentTopPadding.roundToPx() -
contentBottomPadding.roundToPx() - gapPx) /
(presentationModel.layoutSpec.columnFillSpec.minRowHeight.roundToPx() + gapPx)
}
val itemHeight = (constraints.maxHeight - gapPx * (rowCount + 1)) / rowCount
val itemHeight = (constraints.maxHeight - contentTopPadding.roundToPx()
- contentBottomPadding.roundToPx() - gapPx * (rowCount + 1)) / rowCount

panelPlaceable = subcompose(0) {
Box(modifier = modifier.fillMaxSize()) {
Expand All @@ -354,8 +370,8 @@ internal fun AuroraCommandButtonPanel(
gap = gap,
commandGroup = commandGroup,
extraAction = extraAction,
indexRowStart = indexColumnStart,
indexRowEnd = indexColumnEnd,
indexColumnStart = indexColumnStart,
indexColumnEnd = indexColumnEnd,
itemHeight = itemHeight.toDp(),
commandActionPreview = commandPreviewListener,
baseCommandButtonPresentationModel = baseCommandButtonPresentationModel,
Expand Down

0 comments on commit edf3813

Please sign in to comment.