Skip to content

Commit

Permalink
Add fill horizontal arrangement
Browse files Browse the repository at this point in the history
For #56
  • Loading branch information
kirill-grouchnikov committed Dec 14, 2022
1 parent c3bd7cc commit c6f619b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ internal open class CommandButtonLayoutManagerMedium(
when (presentationModel.horizontalAlignment) {
HorizontalAlignment.Leading ->
shiftX = 0.0f
HorizontalAlignment.Center ->

HorizontalAlignment.Center,
HorizontalAlignment.Fill ->
// shift everything to be centered horizontally
shiftX = (finalWidth - preferredSize.width) / 2

HorizontalAlignment.Trailing -> if (ltr) {
// shift everything to the right
shiftX = finalWidth - preferredSize.width
Expand Down Expand Up @@ -317,7 +320,7 @@ internal open class CommandButtonLayoutManagerMedium(
}
}

val xBorderBetweenActionAndPopup : Float
val xBorderBetweenActionAndPopup: Float
when (preLayoutInfo.commandButtonKind) {
CommandButtonKind.ActionOnly -> {
actionClickArea = Rect(
Expand All @@ -327,6 +330,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.PopupOnly -> {
popupClickArea = Rect(
left = 0.0f,
Expand All @@ -335,6 +339,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.ActionAndPopupMainAction ->
// 1. break before popup icon if button has text or icon
// 2. no break (all popup) if button has no text and no icon
Expand Down Expand Up @@ -375,6 +380,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.ActionAndPopupMainPopup ->
// 1. break after icon if button has icon
// 2. no break (all popup) if button has no icon
Expand Down Expand Up @@ -440,7 +446,7 @@ internal open class CommandButtonLayoutManagerMedium(
}

// text
val textHeight : Float
val textHeight: Float
if (hasText) {
x -= if (hasIcon) {
layoutHGap * iconTextGapFactor
Expand Down Expand Up @@ -519,7 +525,7 @@ internal open class CommandButtonLayoutManagerMedium(
}
}

val xBorderBetweenActionAndPopup : Float
val xBorderBetweenActionAndPopup: Float
when (preLayoutInfo.commandButtonKind) {
CommandButtonKind.ActionOnly -> {
actionClickArea = Rect(
Expand All @@ -529,6 +535,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.PopupOnly -> {
popupClickArea = Rect(
left = 0.0f,
Expand All @@ -537,6 +544,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.ActionAndPopupMainAction ->
// 1. break before popup icon if button has text or icon
// 2. no break (all popup) if button has no text and no icon
Expand Down Expand Up @@ -577,6 +585,7 @@ internal open class CommandButtonLayoutManagerMedium(
bottom = finalHeight
)
}

CommandButtonKind.ActionAndPopupMainPopup ->
// 1. break after icon if button has icon
// 2. no break (all popup) if button has no icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ internal open class CommandButtonLayoutManagerSmall(
when (presentationModel.horizontalAlignment) {
HorizontalAlignment.Leading ->
shiftX = 0.0f
HorizontalAlignment.Center ->
HorizontalAlignment.Center,
HorizontalAlignment.Fill ->
// shift everything to be centered horizontally
shiftX = (finalWidth - preferredSize.width) / 2
HorizontalAlignment.Trailing -> if (ltr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ internal open class CommandButtonLayoutManagerTile(
// shift everything to the right
shiftX = finalWidth - preferredSize.width
}
HorizontalAlignment.Center ->
HorizontalAlignment.Center,
HorizontalAlignment.Fill ->
// shift everything to be centered horizontally
shiftX = (finalWidth - preferredSize.width) / 2
HorizontalAlignment.Trailing -> if (ltr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,27 @@ enum class TextClick {
Popup
}

enum class HorizontalAlignment(var arrangement: Arrangement.Horizontal) {
Leading(Arrangement.Start), Center(Arrangement.Center), Trailing(Arrangement.End)
enum class HorizontalAlignment {
Leading {
override var arrangement = Arrangement.Start
},

Trailing {
override var arrangement = Arrangement.End
},

Center {
override var arrangement: Arrangement.Horizontal = Arrangement.Center
},

Fill {
override var arrangement: Arrangement.Horizontal = throw UnsupportedOperationException()
};

internal abstract var arrangement: Arrangement.Horizontal
}


/**
* Enumerates the available command button kinds.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
icon = applications_games(),
keyTip = "AG",
isResizingAware = true,
horizontalAlignment = HorizontalAlignment.Leading
horizontalAlignment = HorizontalAlignment.Fill
),
ComboBoxProjection(
contentModel = internetComboBoxContentModel,
Expand All @@ -955,7 +955,7 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
icon = applications_internet(),
keyTip = "AI",
isResizingAware = true,
horizontalAlignment = HorizontalAlignment.Leading
horizontalAlignment = HorizontalAlignment.Fill
),
ComboBoxProjection(
contentModel = multimediaComboBoxContentModel,
Expand All @@ -964,7 +964,7 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
caption = resourceBundle.getString("Multimedia.text"),
keyTip = "AM",
isResizingAware = true,
horizontalAlignment = HorizontalAlignment.Leading
horizontalAlignment = HorizontalAlignment.Fill
)
)
)
Expand Down

0 comments on commit c6f619b

Please sign in to comment.