Skip to content

Commit

Permalink
More rework of ribbon galleries and task bar content
Browse files Browse the repository at this point in the history
* Rename `RibbonGalleryMetaPresentationModel` to `RibbonGalleryPresentationModel`
* Rename ribbon taskbar element classes to remove the word "projection" from them as they wrap projections, but are not projections themselves
* Change `RibbonTaskbarGallery` to work directly with `RibbonGalleryProjection`
* `BoundsTracker.getGalleryProjectionUnder` now returns the original gallery projection used for the command button that "represents" a pinned ribbon gallery

For #56
  • Loading branch information
kirill-grouchnikov committed Sep 2, 2023
1 parent 828752d commit ffe7ffb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object RibbonGallerySizingConstants {
val DefaultContentLayoutGap: Dp = 4.dp
}

data class RibbonGalleryMetaPresentationModel(
data class RibbonGalleryPresentationModel(
val commandButtonPresentationState: CommandButtonPresentationState,
val commandButtonTextOverflow: TextOverflow = TextOverflow.Clip,
val commandPopupFireTrigger: PopupFireTrigger = PopupFireTrigger.OnRollover,
Expand All @@ -84,7 +84,7 @@ data class RibbonGalleryMetaPresentationModel(

class RibbonGalleryInlineState(
val contentModel: RibbonGalleryContentModel,
val presentationModel: RibbonGalleryMetaPresentationModel,
val presentationModel: RibbonGalleryPresentationModel,
) {
private val fullCount: Int
get() = contentModel.commandGroups.sumOf { it.commands.size }
Expand Down Expand Up @@ -130,10 +130,10 @@ class RibbonGalleryInlineState(

class RibbonGalleryProjection(
override val contentModel: RibbonGalleryContentModel,
override val presentationModel: RibbonGalleryMetaPresentationModel,
override val presentationModel: RibbonGalleryPresentationModel,
val secondaryOverlays: Map<Command, BaseCommandButtonPresentationModel.Overlay>? = null,
val inlineState: RibbonGalleryInlineState
) : Projection<RibbonGalleryContentModel, RibbonGalleryMetaPresentationModel>() {
) : Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>() {
@Composable
fun project(modifier: Modifier = Modifier) {
require(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@
*/
package org.pushingpixels.aurora.component.ribbon

import org.pushingpixels.aurora.component.model.BaseCommandButtonPresentationModel
import org.pushingpixels.aurora.component.model.Command
import org.pushingpixels.aurora.component.model.ContentModel
import org.pushingpixels.aurora.component.model.PresentationModel
import org.pushingpixels.aurora.component.projection.BaseCommandButtonProjection
import org.pushingpixels.aurora.component.projection.Projection

sealed interface RibbonTaskbarElement

data class RibbonTaskbarCommandProjection(val commandProjection: BaseCommandButtonProjection<*, *, *>) :
data class RibbonTaskbarCommand(val commandProjection: BaseCommandButtonProjection<*, *, *>) :
RibbonTaskbarElement

data class RibbonTaskbarComponentProjection(val componentProjection: Projection<ContentModel, PresentationModel>) :
data class RibbonTaskbarComponent(val componentProjection: Projection<ContentModel, PresentationModel>) :
RibbonTaskbarElement

data class RibbonTaskbarGalleryProjection(
val galleryContentModel: RibbonGalleryContentModel,
val galleryMetaPresentationModel: RibbonGalleryMetaPresentationModel,
val secondaryOverlays: Map<Command, BaseCommandButtonPresentationModel.Overlay>? = null,
val galleryInlineState: RibbonGalleryInlineState
) : RibbonTaskbarElement
data class RibbonTaskbarGallery(val galleryProjection: RibbonGalleryProjection):
RibbonTaskbarElement

interface RibbonTaskbarKeyTipPolicy {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ fun getGalleryProjectionUnder(x: Float, y: Float) : RibbonGalleryProjection? {
}
}
}
// second pass - see if a command button projection was created from a gallery
for (tracked in BoundsTracker.getBounds().entries) {
if (tracked.key is BaseCommandButtonProjection<*, *, *>) {
val commandButtonProjection = tracked.key as BaseCommandButtonProjection<*, *, *>
if ((commandButtonProjection.contentModel.tag is RibbonGalleryProjection) &&
tracked.value.contains(x, y)) {
return commandButtonProjection.contentModel.tag as RibbonGalleryProjection
}
}
}
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import org.pushingpixels.aurora.component.ribbon.RibbonBandCommandButtonPresenta
import org.pushingpixels.aurora.component.ribbon.RibbonBandCommandButtonPresentationStates.BigFixedLandscape
import org.pushingpixels.aurora.component.ribbon.RibbonGalleryContentModel
import org.pushingpixels.aurora.component.ribbon.RibbonGalleryInlineState
import org.pushingpixels.aurora.component.ribbon.RibbonGalleryMetaPresentationModel
import org.pushingpixels.aurora.component.ribbon.RibbonGalleryPresentationModel
import org.pushingpixels.aurora.component.utils.*
import org.pushingpixels.aurora.component.utils.ArrowSizingConstants.DefaultDoubleArrowWidth
import org.pushingpixels.aurora.theming.*
Expand All @@ -52,7 +52,7 @@ import kotlin.math.roundToInt
@Composable
internal fun ribbonGalleryIntrinsicWidth(
contentModel: RibbonGalleryContentModel,
presentationModel: RibbonGalleryMetaPresentationModel,
presentationModel: RibbonGalleryPresentationModel,
visibleCount: Int,
height: Int
): Int {
Expand Down Expand Up @@ -93,9 +93,9 @@ internal fun ribbonGalleryIntrinsicWidth(
@Composable
internal fun RibbonGallery(
modifier: Modifier,
originalProjection: Projection<RibbonGalleryContentModel, RibbonGalleryMetaPresentationModel>,
originalProjection: Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>,
contentModel: RibbonGalleryContentModel,
presentationModel: RibbonGalleryMetaPresentationModel,
presentationModel: RibbonGalleryPresentationModel,
inlineState: RibbonGalleryInlineState
) {
val density = LocalDensity.current
Expand Down Expand Up @@ -439,7 +439,7 @@ internal fun RibbonGallery(
}

private class GalleryLocator(
val projection: Projection<RibbonGalleryContentModel, RibbonGalleryMetaPresentationModel>,
val projection: Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>,
val topLeftOffset: AuroraOffset,
val size: MutableState<IntSize>
) :
Expand Down Expand Up @@ -467,7 +467,7 @@ private class GalleryLocator(

@Composable
private fun Modifier.galleryLocator(
projection: Projection<RibbonGalleryContentModel, RibbonGalleryMetaPresentationModel>,
projection: Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>,
topLeftOffset: AuroraOffset,
size: MutableState<IntSize>
) = this.then(GalleryLocator(projection, topLeftOffset, size))
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import org.pushingpixels.aurora.component.popup.BaseCascadingCommandMenuPopupLay
import org.pushingpixels.aurora.component.popup.CascadingCommandMenuHandler
import org.pushingpixels.aurora.component.projection.BaseCommandButtonProjection
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarCommandProjection
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarComponentProjection
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarCommand
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarComponent
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarElement
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarGalleryProjection
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarGallery
import org.pushingpixels.aurora.component.utils.getEndwardDoubleArrowIcon
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.colorscheme.AuroraColorSchemeBundle
Expand Down Expand Up @@ -378,7 +378,7 @@ fun RibbonTaskbar(
private fun TaskbarContent(elements: List<RibbonTaskbarElement>) {
for (element in elements) {
when (element) {
is RibbonTaskbarCommandProjection -> {
is RibbonTaskbarCommand -> {
element.commandProjection.reproject(
modifier = Modifier,
primaryOverlay = BaseCommandButtonPresentationModel.Overlay(
Expand All @@ -390,25 +390,25 @@ private fun TaskbarContent(elements: List<RibbonTaskbarElement>) {
)
}

is RibbonTaskbarGalleryProjection -> {
val galleryContentModel = element.galleryContentModel
val galleryPresentationModel = element.galleryMetaPresentationModel
is RibbonTaskbarGallery -> {
val galleryContentModel = element.galleryProjection.contentModel
val galleryPresentationModel = element.galleryProjection.presentationModel

val galleryCommand = Command(
text = "",
icon = galleryContentModel.icon,
secondaryContentModel = CommandMenuContentModel(
onDeactivatePopup = {
// Mark the inline state to have the latest selected command button to be revealed
element.galleryInlineState.revealSelected()
element.galleryProjection.inlineState.revealSelected()
},
panelContentModel = CommandPanelContentModel(
commandGroups = galleryContentModel.commandGroups
),
groups = galleryContentModel.extraPopupGroups
),
isSecondaryEnabled = true,
tag = element.galleryContentModel
tag = element.galleryProjection
)
CommandButtonProjection(
contentModel = galleryCommand,
Expand All @@ -426,11 +426,11 @@ private fun TaskbarContent(elements: List<RibbonTaskbarElement>) {
)
)
),
secondaryOverlays = element.secondaryOverlays
secondaryOverlays = element.galleryProjection.secondaryOverlays
).project()
}

is RibbonTaskbarComponentProjection -> {
is RibbonTaskbarComponent -> {
element.componentProjection.reproject(modifier = Modifier)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun main() = auroraApplication {
}

val styleGalleryContentModel = builder.getStyleGalleryContentModel()
val styleGalleryInlineMetaPresentationModel = RibbonGalleryMetaPresentationModel(
val styleGalleryInlineMetaPresentationModel = RibbonGalleryPresentationModel(
popupLayoutSpec = MenuPopupPanelLayoutSpec(
columnCount = 3, visibleRowCount = 3
),
Expand All @@ -137,7 +137,7 @@ fun main() = auroraApplication {
inlineState = ribbonState.documentStyleGalleryInlineState
)

val styleGalleryTaskbarMetaPresentationModel = RibbonGalleryMetaPresentationModel(
val styleGalleryTaskbarMetaPresentationModel = RibbonGalleryPresentationModel(
popupLayoutSpec = MenuPopupPanelLayoutSpec(columnCount = 4, visibleRowCount = 2),
commandButtonPresentationState = RibbonBandCommandButtonPresentationStates.BigFixed,
collapsedVisibleCountLow = styleGalleryInlineMetaPresentationModel.collapsedVisibleCountLow,
Expand Down Expand Up @@ -395,13 +395,13 @@ fun main() = auroraApplication {

val taskbarElements: MutableList<RibbonTaskbarElement> = remember {
mutableStateListOf(
RibbonTaskbarCommandProjection(
RibbonTaskbarCommand(
CommandButtonProjection(
contentModel = builder.pasteCommand,
presentationModel = CommandButtonPresentationModel()
)
),
RibbonTaskbarCommandProjection(
RibbonTaskbarCommand(
CommandButtonProjection(
contentModel = Command(
text = "",
Expand All @@ -412,7 +412,7 @@ fun main() = auroraApplication {
presentationModel = CommandButtonPresentationModel()
)
),
RibbonTaskbarComponentProjection(
RibbonTaskbarComponent(
ComboBoxProjection(
contentModel = fontFamilyComboBoxContentModel,
presentationModel = ComboBoxPresentationModel(displayConverter = { it.name }),
Expand All @@ -423,10 +423,12 @@ fun main() = auroraApplication {
// 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(
galleryContentModel = styleGalleryContentModel,
galleryMetaPresentationModel = styleGalleryTaskbarMetaPresentationModel,
galleryInlineState = ribbonState.documentStyleGalleryInlineState
RibbonTaskbarGallery(
RibbonGalleryProjection(
contentModel = styleGalleryContentModel,
presentationModel = styleGalleryTaskbarMetaPresentationModel,
inlineState = ribbonState.documentStyleGalleryInlineState
)
)
)
}
Expand Down Expand Up @@ -480,14 +482,14 @@ fun main() = auroraApplication {
componentProjection: Projection<C, P>
): CommandMenuContentModel {
val isInTaskbar = ribbon.taskbarElements.find {
(it is RibbonTaskbarComponentProjection) &&
(it is RibbonTaskbarComponent) &&
(it.componentProjection.contentModel == componentProjection.contentModel)
} != null
val componentCommand = if (isInTaskbar) {
Command(text = resourceBundle.getString("ContextMenu.removeFromTaskbar"),
action = {
taskbarElements.removeIf {
(it is RibbonTaskbarComponentProjection) &&
(it is RibbonTaskbarComponent) &&
it.componentProjection.contentModel == componentProjection.contentModel
}
}
Expand All @@ -499,7 +501,7 @@ fun main() = auroraApplication {
// presentation model in the taskbar
if (componentProjection.contentModel == fontFamilyComboBoxContentModel) {
taskbarElements.add(
RibbonTaskbarComponentProjection(
RibbonTaskbarComponent(
ComboBoxProjection(
contentModel = fontFamilyComboBoxContentModel,
presentationModel = ComboBoxPresentationModel(
Expand All @@ -509,7 +511,7 @@ fun main() = auroraApplication {
)
)
} else {
taskbarElements.add(RibbonTaskbarComponentProjection(componentProjection))
taskbarElements.add(RibbonTaskbarComponent(componentProjection))
}
}
)
Expand All @@ -522,22 +524,22 @@ fun main() = auroraApplication {
commandProjection: BaseCommandButtonProjection<*, *, *>
): CommandMenuContentModel {
val isInTaskbar = ribbon.taskbarElements.find {
(it is RibbonTaskbarCommandProjection) &&
(it is RibbonTaskbarCommand) &&
(it.commandProjection.contentModel == commandProjection.contentModel)
} != null
val buttonCommand = if (isInTaskbar) {
Command(text = resourceBundle.getString("ContextMenu.removeFromTaskbar"),
action = {
taskbarElements.removeIf {
(it is RibbonTaskbarCommandProjection) &&
(it is RibbonTaskbarCommand) &&
(it.commandProjection.contentModel == commandProjection.contentModel)
}
}
)
} else {
Command(text = resourceBundle.getString("ContextMenu.addToTaskbar"),
action = {
taskbarElements.add(RibbonTaskbarCommandProjection(commandProjection))
taskbarElements.add(RibbonTaskbarCommand(commandProjection))
}
)
}
Expand All @@ -549,15 +551,15 @@ fun main() = auroraApplication {
galleryProjection: RibbonGalleryProjection
): CommandMenuContentModel {
val isInTaskbar = ribbon.taskbarElements.find {
(it is RibbonTaskbarGalleryProjection) &&
(it.galleryContentModel == galleryProjection.contentModel)
(it is RibbonTaskbarGallery) &&
(it.galleryProjection.contentModel == galleryProjection.contentModel)
} != null
val galleryCommand = if (isInTaskbar) {
Command(text = resourceBundle.getString("ContextMenu.removeFromTaskbar"),
action = {
taskbarElements.removeIf {
(it is RibbonTaskbarGalleryProjection) &&
it.galleryContentModel == galleryProjection.contentModel
(it is RibbonTaskbarGallery) &&
it.galleryProjection.contentModel == galleryProjection.contentModel
}
}
)
Expand All @@ -566,10 +568,12 @@ fun main() = auroraApplication {
action = {
if (galleryProjection.contentModel == styleGalleryContentModel) {
taskbarElements.add(
RibbonTaskbarGalleryProjection(
galleryContentModel = styleGalleryContentModel,
galleryMetaPresentationModel = styleGalleryTaskbarMetaPresentationModel,
galleryInlineState = ribbonState.documentStyleGalleryInlineState
RibbonTaskbarGallery(
RibbonGalleryProjection(
contentModel = styleGalleryContentModel,
presentationModel = styleGalleryTaskbarMetaPresentationModel,
inlineState = ribbonState.documentStyleGalleryInlineState
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.pushingpixels.aurora.window

import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.window.WindowDraggableArea
import androidx.compose.runtime.*
Expand All @@ -29,7 +28,6 @@ import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.ClipOp
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.drawscope.withTransform
Expand All @@ -52,12 +50,10 @@ import org.pushingpixels.aurora.common.AuroraInternalApi
import org.pushingpixels.aurora.common.AuroraPopupManager
import org.pushingpixels.aurora.common.AuroraSwingPopupMenu
import org.pushingpixels.aurora.common.withAlpha
import org.pushingpixels.aurora.component.contextmenu.auroraContextMenu
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.projection.LabelProjection
import org.pushingpixels.aurora.component.ribbon.Ribbon
import org.pushingpixels.aurora.component.ribbon.RibbonTask
import org.pushingpixels.aurora.component.ribbon.RibbonTaskbarGalleryProjection
import org.pushingpixels.aurora.component.ribbon.impl.*
import org.pushingpixels.aurora.component.utils.TransitionAwarePainter
import org.pushingpixels.aurora.component.utils.TransitionAwarePainterDelegate
Expand Down

0 comments on commit ffe7ffb

Please sign in to comment.