Skip to content

Commit

Permalink
More ribbon API prototyping
Browse files Browse the repository at this point in the history
Add taskbar content

For #56
  • Loading branch information
kirill-grouchnikov committed Dec 21, 2022
1 parent fb1ac30 commit 9770540
Show file tree
Hide file tree
Showing 5 changed files with 1,182 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ data class RibbonGalleryContentModel(
) : ContentModel

data class RibbonGalleryPresentationModel(
val preferredVisibleCommandCounts: Map<PresentationPriority, Int>,
val popupLayoutSpec: MenuPopupPanelLayoutSpec,
val preferredVisibleCommandCounts: Map<PresentationPriority, Int> = emptyMap(),
val commandButtonPresentationState: CommandButtonPresentationState,
val expandKeyTip: String? = null,
) : PresentationModel
Expand Down Expand Up @@ -98,15 +98,19 @@ class RibbonApplicationMenuCommandButtonProjection(
val secondaryLevelCommandPresentationStates: Map<Command, CommandButtonPresentationState>
) : Projection<Command, RibbonApplicationMenuCommandButtonPresentationModel>()

sealed interface RibbonTaskbarElement

data class RibbonTaskbarCommandProjection(val commandProjection: BaseCommandButtonProjection<BaseCommandMenuContentModel, BaseCommand<BaseCommandMenuContentModel>>) : RibbonTaskbarElement
data class RibbonTaskbarComponentProjection(val componentProjection: Projection<ContentModel, PresentationModel>) : RibbonTaskbarElement
data class RibbonTaskbarGalleryProjection(val galleryProjection: RibbonGalleryProjection) : RibbonTaskbarElement

data class Ribbon(
val tasks: List<RibbonTask>,
val selectedTask: RibbonTask,
val onTaskClick: (RibbonTask) -> Unit,
val contextualTaskGroups: List<RibbonContextualTaskGroup> = emptyList(),
val anchoredCommands: List<CommandButtonProjection> = emptyList(),
val taskbarCommandProjections: List<RibbonTaskbarCommandButtonProjection> = emptyList(),
val taskbarComponentProjections: List<RibbonComponentProjection<ContentModel, PresentationModel>> = emptyList(),
val taskbarGalleryProjections: List<RibbonGalleryProjection> = emptyList(),
val taskbarElements: List<RibbonTaskbarElement> = emptyList(),
val taskbarKeyTipPolicy: RibbonTaskbarKeyTipPolicy,
val applicationMenuCommandButtonProjection: RibbonApplicationMenuCommandButtonProjection? = null,
val isMinimized: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
*/
package org.pushingpixels.aurora.component.ribbon

import org.pushingpixels.aurora.component.model.Command
import org.pushingpixels.aurora.component.model.CommandPopupMenuPresentationModel
import org.pushingpixels.aurora.component.model.PresentationModel
import org.pushingpixels.aurora.component.projection.Projection
import org.pushingpixels.aurora.theming.IconFilterStrategy

data class RibbonTaskbarCommandButtonPresentationModel(
val iconDisabledFilterStrategy: IconFilterStrategy = IconFilterStrategy.ThemedFollowColorScheme,
val iconEnabledFilterStrategy: IconFilterStrategy = IconFilterStrategy.Original,
val iconActiveFilterStrategy: IconFilterStrategy = IconFilterStrategy.Original,
val popupMenuPresentationModel: CommandPopupMenuPresentationModel = CommandPopupMenuPresentationModel()
) : PresentationModel

interface RibbonTaskbarKeyTipPolicy {
/**
* Returns the keytip for the task bar content (command, component, gallery, menu link)
Expand Down Expand Up @@ -65,9 +52,3 @@ class DefaultRibbonTaskbarKeyTipPolicy : RibbonTaskbarKeyTipPolicy {
private const val LETTERS = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
}
}

class RibbonTaskbarCommandButtonProjection(
val contentModel: Command,
val presentationModel: RibbonTaskbarCommandButtonPresentationModel
) : Projection<Command, RibbonTaskbarCommandButtonPresentationModel>()

Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import org.jetbrains.skia.Font
import org.jetbrains.skia.TextLine
import org.jetbrains.skia.Typeface
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.projection.ColorSelectorCommandButtonProjection
import org.pushingpixels.aurora.component.projection.ComboBoxProjection
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
import org.pushingpixels.aurora.component.projection.CommandButtonStripProjection
import org.pushingpixels.aurora.component.projection.*
import org.pushingpixels.aurora.component.ribbon.*
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizePolicies
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizeSequencingPolicies
Expand All @@ -63,9 +60,15 @@ fun main() = auroraApplication {
}

val builder = RibbonBuilder(resourceBundle)

var fontFamilyComboSelectedItem by remember { mutableStateOf(builder.fontFamilyComboBoxEntries[0]) }

val clipboardBand = builder.getClipboardBand()
val quickStylesBand = builder.getQuickStylesBand()
val fontBand = builder.getFontBand()
val fontBand = builder.getFontBand(
selectedFontFamily = fontFamilyComboSelectedItem,
onFontFamilySelected = { fontFamilyComboSelectedItem = it }
)
val documentBand = builder.getDocumentBand()
val findBand = builder.getFindBand()

Expand All @@ -87,12 +90,62 @@ fun main() = auroraApplication {
keyTip = "W"
)

val taskbarElements: List<RibbonTaskbarElement> =
listOf(
RibbonTaskbarCommandProjection(
CommandButtonProjection(
contentModel = builder.pasteCommand,
presentationModel = CommandButtonPresentationModel()
)
),
RibbonTaskbarCommandProjection(
CommandButtonProjection(
contentModel = Command(
text = "",
icon = edit_clear(),
action = { println("Taskbat Clear activated") },
isActionEnabled = false
),
presentationModel = CommandButtonPresentationModel()
)
),
RibbonTaskbarComponentProjection(
ComboBoxProjection(
contentModel = ComboBoxContentModel(
items = builder.fontFamilyComboBoxEntries,
selectedItem = fontFamilyComboSelectedItem,
onTriggerItemSelectedChange = {
fontFamilyComboSelectedItem = it
println("New font family selection -> $it")
},
richTooltip = RichTooltip(title = resourceBundle.getString("Fonts.tooltip.title")),
),
presentationModel = ComboBoxPresentationModel(displayConverter = { it }),
)
),
// Add the same gallery we have in the first ribbon task to the taskbar, configuring
// its popup presentation with a 4x2 grid of slightly smaller buttons (instead of a 3x3
// grid of slightly larger ones in the in-task gallery popup).
// Content preview and selection is controlled by the same model and is kept in sync
// along all usages of the gallery content model in our ribbon.
RibbonTaskbarGalleryProjection(
RibbonGalleryProjection(
contentModel = builder.styleGalleryContentModel,
presentationModel = RibbonGalleryPresentationModel(
popupLayoutSpec = MenuPopupPanelLayoutSpec(columnCount = 4, visibleRowCount = 2),
commandButtonPresentationState = RibbonBandCommandButtonPresentationStates.BigFixed
)
)
)
)

var selectedTask by remember { mutableStateOf(pageLayoutTask) }

val ribbon = Ribbon(
tasks = listOf(pageLayoutTask, writeTask),
selectedTask = selectedTask,
onTaskClick = { selectedTask = it },
taskbarElements = taskbarElements,
taskbarKeyTipPolicy = DefaultRibbonTaskbarKeyTipPolicy(),
anchoredCommands = builder.getAnchoredCommands()
)
Expand Down Expand Up @@ -533,10 +586,12 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
)
)
),
ColorSelectorPopupMenuRecentsSection(colorSectionModel = ColorSectionModel(
title = resourceBundle.getString("ColorSelector.textRecentCaption"),
colors = listOf()
)),
ColorSelectorPopupMenuRecentsSection(
colorSectionModel = ColorSectionModel(
title = resourceBundle.getString("ColorSelector.textRecentCaption"),
colors = listOf()
)
),
ColorSelectorPopupMenuCommand(
command = Command(
text = resourceBundle.getString("ColorSelector.textMoreColor"),
Expand Down Expand Up @@ -623,13 +678,15 @@ private class RibbonBuilder(val resourceBundle: ResourceBundle) {
}

@Composable
fun getFontBand(): FlowRibbonBand {
val fontFamilyComboSelectedItem = remember { mutableStateOf(this.fontFamilyComboBoxEntries[0]) }
fun getFontBand(
selectedFontFamily: String,
onFontFamilySelected: (String) -> Unit
): FlowRibbonBand {
val fontFamilyComboBoxContentModel = ComboBoxContentModel(
items = this.fontFamilyComboBoxEntries,
selectedItem = fontFamilyComboSelectedItem.value,
selectedItem = selectedFontFamily,
onTriggerItemSelectedChange = {
fontFamilyComboSelectedItem.value = it
onFontFamilySelected(it)
println("New font family selection -> $it")
},
richTooltip = RichTooltip(title = resourceBundle.getString("Fonts.tooltip.title")),
Expand Down
Loading

0 comments on commit 9770540

Please sign in to comment.