Skip to content

Commit

Permalink
Prototype for filling in a ribbon band with a gallery
Browse files Browse the repository at this point in the history
For #56
  • Loading branch information
kirill-grouchnikov committed Dec 11, 2022
1 parent 4571352 commit 0f97f24
Show file tree
Hide file tree
Showing 22 changed files with 9,833 additions and 922 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ fun PresentationModel.inRibbon(
data class RibbonGalleryContentModel(
val icon: Painter? = null,
val commandGroups: List<CommandGroup>,
val selectedCommand: Command? = null,
val extraPopupGroups: List<CommandGroup>,
val commandAction: (() -> Unit)? = null,
val commandAction: ((Command?) -> Unit)? = null,
val commandActionPreview: CommandActionPreview? = null,
) : ContentModel

data class RibbonGalleryPresentationModel(
val preferredVisibleCommandCounts: Map<PresentationPriority, Int>,
val popupLayoutSpec: MenuPopupPanelLayoutSpec,
val commandButtonPresentationState: CommandButtonPresentationState,
val expandKeyTip: String? = null,
val policies: Map<PresentationPriority, Int>
) : PresentationModel

class RibbonGalleryProjection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
package org.pushingpixels.aurora.component.ribbon

import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection
import org.pushingpixels.aurora.component.layout.CommandButtonLayoutManager
import org.pushingpixels.aurora.component.layout.CommandButtonLayoutManagerBig
import org.pushingpixels.aurora.component.model.Command
import org.pushingpixels.aurora.component.model.CommandButtonPresentationState
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizePolicies
import org.pushingpixels.aurora.component.ribbon.resize.RibbonBandResizePolicy

Expand Down Expand Up @@ -53,4 +60,29 @@ data class FlowRibbonBand(
val flowComponentProjections: List<RibbonComponentProjection> = emptyList()
) : AbstractRibbonBand

object RibbonBandCommandButtonPresentationStates {
val BigFixed: CommandButtonPresentationState =
object : CommandButtonPresentationState("Big Fixed") {
override fun createLayoutManager(
layoutDirection: LayoutDirection,
density: Density,
textStyle: TextStyle,
fontFamilyResolver: FontFamily.Resolver
): CommandButtonLayoutManager {
throw UnsupportedOperationException()
}
}

val BigFixedLandscape: CommandButtonPresentationState =
object : CommandButtonPresentationState("Big Fixed Landscape") {
override fun createLayoutManager(
layoutDirection: LayoutDirection,
density: Density,
textStyle: TextStyle,
fontFamilyResolver: FontFamily.Resolver
): CommandButtonLayoutManager {
throw UnsupportedOperationException()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ object CoreRibbonResizePolicies {
return emptyList()
}

public fun getCorePoliciesRestrictive(): List<RibbonBandResizePolicy> {
return emptyList()
}

public fun getCoreFlowPoliciesRestrictive(stepsToRepeat: Int): List<RibbonBandResizePolicy> {
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
import org.pushingpixels.aurora.demo.svg.flags.il
import org.pushingpixels.aurora.demo.svg.flags.us
import org.pushingpixels.aurora.demo.svg.tango.preferences_desktop_locale_2
import org.pushingpixels.aurora.demo.svg.tango.preferences_desktop_locale
import org.pushingpixels.aurora.window.AuroraLocaleScope
import java.awt.ComponentOrientation
import java.awt.Window
Expand Down Expand Up @@ -58,7 +58,7 @@ fun AuroraLocaleScope.AuroraLocaleSwitcher(
)
val localeCommand = Command(
text = resourceBundle.getString("Language.select"),
icon = preferences_desktop_locale_2(),
icon = preferences_desktop_locale(),
secondaryContentModel = CommandMenuContentModel(
group = CommandGroup(
commands = arrayListOf(englishLocale, hebrewLocale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.rememberWindowState
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.ribbon.*
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizePolicies
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizeSequencingPolicies
import org.pushingpixels.aurora.demo.ColorAuroraIcon
import org.pushingpixels.aurora.demo.getQuickStylesContentModel
Expand All @@ -47,9 +48,11 @@ fun main() = auroraApplication {

val builder = RibbonBuilder(resourceBundle)
val clipboardBand = builder.getClipboardBand()
val quickStylesBand = builder.getQuickStylesBand()

val pageLayoutTask = RibbonTask(
title = resourceBundle.getString("PageLayout.textTaskTitle"),
bands = listOf(clipboardBand),
bands = listOf(clipboardBand, quickStylesBand),
resizeSequencingPolicy = CoreRibbonResizeSequencingPolicies.RoundRobin(),
keyTip = "P"
)
Expand Down Expand Up @@ -134,6 +137,53 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
action = { println("Apply Styles activated") }
)

var mfButtonText = MessageFormat(
resourceBundle.getString("StylesGallery.textButton")
)
val stylesGalleryCommandList = CommandGroup(
title = resourceBundle.getString("StylesGallery.textGroupTitle1"),
commands = (0..10).map {
Command(
text = mfButtonText.format(arrayOf(it)),
icon = font_x_generic(),
isActionToggle = true
)
}
)
val stylesGalleryCommandList2 = CommandGroup(
title = resourceBundle.getString("StylesGallery.textGroupTitle1"),
commands = (11..30).map {
Command(
text = mfButtonText.format(arrayOf(it)),
icon = font_x_generic(),
isActionToggle = true
)
}
)

val styleGalleryContentModel = RibbonGalleryContentModel(
icon = font_x_generic(),
commandGroups = listOf(stylesGalleryCommandList, stylesGalleryCommandList2),
selectedCommand = stylesGalleryCommandList.commands[1],
extraPopupGroups = listOf(
CommandGroup(commands = listOf(this.menuSaveSelection, this.menuClearSelection)),
CommandGroup(commands = listOf(this.applyStyles))
),
commandAction = {
val text = it?.text ?: "[null]"
println("Command '$text' activated!")
},
commandActionPreview = object: CommandActionPreview {
override fun onCommandPreviewActivated(command: Command) {
println("Preview activated for '${command.text}'")
}

override fun onCommandPreviewCanceled(command: Command) {
println("Preview canceled for '${command.text}'")
}
}
)

fun getSimpleMenuModel(): CommandMenuContentModel {
return CommandMenuContentModel(
groups = listOf(
Expand Down Expand Up @@ -238,6 +288,56 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
)
)
}

fun getQuickStylesBand(): RibbonBand {
return RibbonBand(
title = resourceBundle.getString("QuickStyles.textBandTitle"),
icon = preferences_desktop_theme(),
collapsedStateKeyTip = "ZS",
resizePolicies = CoreRibbonResizePolicies.getCorePoliciesRestrictive(),
commandProjections = listOf(
RibbonCommandButtonProjection(
contentModel = Command(
text = resourceBundle.getString("Styles1.text"),
icon = font_x_generic(),
action = { println("Generic activated") }
),
presentationModel = RibbonCommandButtonPresentationModel(
presentationPriority = PresentationPriority.Medium,
actionKeyTip = "SA"
)
),
RibbonCommandButtonProjection(
contentModel = Command(
text = resourceBundle.getString("Styles2.text"),
icon = image_x_generic(),
action = { println("Image activated") }
),
presentationModel = RibbonCommandButtonPresentationModel(
presentationPriority = PresentationPriority.Medium,
actionKeyTip = "SB"
)
)
),
galleryProjections = listOf(
RibbonGalleryProjection(
contentModel = styleGalleryContentModel,
presentationModel = RibbonGalleryPresentationModel(
preferredVisibleCommandCounts = mapOf(
PresentationPriority.Low to 1,
PresentationPriority.Medium to 2,
PresentationPriority.Top to 2
),
popupLayoutSpec = MenuPopupPanelLayoutSpec(
columnCount = 3, visibleRowCount = 3
),
commandButtonPresentationState = RibbonBandCommandButtonPresentationStates.BigFixedLandscape,
expandKeyTip = "L"
)
)
)
)
}
}


Loading

0 comments on commit 0f97f24

Please sign in to comment.