Skip to content

Commit

Permalink
Restructure ribbon classes
Browse files Browse the repository at this point in the history
Start splitting them into separate files
Also add ribbon band resize policies

For #56
  • Loading branch information
kirill-grouchnikov committed Dec 11, 2022
1 parent 3557662 commit 4571352
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package org.pushingpixels.aurora.component.ribbon

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.projection.CommandButtonProjection
import org.pushingpixels.aurora.component.projection.Projection
import org.pushingpixels.aurora.theming.IconFilterStrategy
import org.pushingpixels.aurora.theming.PopupPlacementStrategy

enum class PresentationPriority {
Expand All @@ -34,14 +32,6 @@ enum class PresentationPriority {
Low
}

sealed interface AbstractRibbonBand {
val title: String
val icon: Painter?
val expandCommand: Command?
val expandCommandKeyTip: String?
val collapsedStateKeyTip: String?
}

data class RibbonCommandButtonPresentationModel(
val presentationPriority: PresentationPriority,
val popupPlacementStrategy: PopupPlacementStrategy = PopupPlacementStrategy.Downward.HAlignStart,
Expand Down Expand Up @@ -126,105 +116,6 @@ class RibbonComponentProjection(
val presentationModel: RibbonComponentPresentationModel
) : Projection<Command, RibbonComponentPresentationModel>()

data class RibbonBand(
override val title: String,
override val icon: Painter? = null,
override val expandCommand: Command? = null,
override val expandCommandKeyTip: String? = null,
override val collapsedStateKeyTip: String? = null,
val commandProjections: List<RibbonCommandButtonProjection> = emptyList(),
val componentProjections: List<RibbonComponentProjection> = emptyList(),
val galleryProjections: List<RibbonGalleryProjection> = emptyList(),
) : AbstractRibbonBand

data class FlowRibbonBand(
override val title: String,
override val icon: Painter? = null,
override val expandCommand: Command? = null,
override val expandCommandKeyTip: String? = null,
override val collapsedStateKeyTip: String? = null,
val flowComponentProjections: List<RibbonComponentProjection> = emptyList()
) : AbstractRibbonBand

interface RibbonBandResizeSequencingPolicy {
/**
* Resets this policy. Note that this method is for internal use only and
* should not be called by the application code.
*/
fun reset(ribbonTask: RibbonTask)

/**
* Returns the next ribbon band for collapse.
*
* @return The next ribbon band for collapse.
*/
fun next(ribbonTask: RibbonTask): AbstractRibbonBand
}

data class RibbonTask(
val title: String,
val bands: List<AbstractRibbonBand>,
val resizeSequencingPolicy: RibbonBandResizeSequencingPolicy,
val keyTip: String? = null
)

object CoreRibbonResizeSequencingPolicies {
/**
* The round robin resize sequencing policy. Under this policy the ribbon
* bands are being collapsed in a cyclic fashion, distributing the collapsed
* pixels between the different bands.
*
* @author Kirill Grouchnikov
*/
class RoundRobin() : RibbonBandResizeSequencingPolicy {
// The index of the next ribbon task for collapsing.
private var nextIndex = 0

override fun reset(ribbonTask: RibbonTask) {
nextIndex = ribbonTask.bands.size - 1
}

override fun next(ribbonTask: RibbonTask): AbstractRibbonBand {
val result: AbstractRibbonBand = ribbonTask.bands[nextIndex]
nextIndex--
if (nextIndex < 0) nextIndex = ribbonTask.bands.size - 1
return result
}
}
}

data class RibbonContextualTaskGroup(
val title: String,
val hueColor: Color,
val tasks: List<RibbonTask>,
val isActive: Boolean = false
)

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)
* at the specified index.
*
* @param contentIndex Index of the task bar content. Content index starts at 1.
* @return Keytip for the specified content.
*/
fun getContentKeyTip(contentIndex: Int): String

/**
* Returns the keytip for the overflow button of the task bar.
*
* @return Keytip for the overflow button of the task bar.
*/
val overflowButtonKeyTip: String
}

interface OnShowContextualMenuListener {
fun getContextualMenuContentModel(
ribbon: Ribbon,
Expand All @@ -244,11 +135,6 @@ interface OnShowContextualMenuListener {
fun getContextualMenuContentModel(ribbon: Ribbon): CommandMenuContentModel
}

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

data class RibbonApplicationMenuCommandButtonPresentationModel(
val popupKeyTip: String? = null
) : PresentationModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020-2022 Aurora, Kirill Grouchnikov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pushingpixels.aurora.component.ribbon

import androidx.compose.ui.graphics.painter.Painter
import org.pushingpixels.aurora.component.model.Command
import org.pushingpixels.aurora.component.ribbon.resize.CoreRibbonResizePolicies
import org.pushingpixels.aurora.component.ribbon.resize.RibbonBandResizePolicy

sealed interface AbstractRibbonBand {
val title: String
val icon: Painter?
val expandCommand: Command?
val expandCommandKeyTip: String?
val collapsedStateKeyTip: String?
val resizePolicies: List<RibbonBandResizePolicy>
}

data class RibbonBand(
override val title: String,
override val icon: Painter? = null,
override val expandCommand: Command? = null,
override val expandCommandKeyTip: String? = null,
override val collapsedStateKeyTip: String? = null,
override val resizePolicies: List<RibbonBandResizePolicy> =
CoreRibbonResizePolicies.getCorePoliciesPermissive(),
val commandProjections: List<RibbonCommandButtonProjection> = emptyList(),
val componentProjections: List<RibbonComponentProjection> = emptyList(),
val galleryProjections: List<RibbonGalleryProjection> = emptyList(),
) : AbstractRibbonBand

data class FlowRibbonBand(
override val title: String,
override val icon: Painter? = null,
override val expandCommand: Command? = null,
override val expandCommandKeyTip: String? = null,
override val collapsedStateKeyTip: String? = null,
override val resizePolicies: List<RibbonBandResizePolicy> =
CoreRibbonResizePolicies.getCoreFlowPoliciesRestrictive(3),
val flowComponentProjections: List<RibbonComponentProjection> = emptyList()
) : AbstractRibbonBand


Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020-2022 Aurora, Kirill Grouchnikov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pushingpixels.aurora.component.ribbon

import androidx.compose.ui.graphics.Color
import org.pushingpixels.aurora.component.ribbon.resize.RibbonBandResizeSequencingPolicy

data class RibbonTask(
val title: String,
val bands: List<AbstractRibbonBand>,
val resizeSequencingPolicy: RibbonBandResizeSequencingPolicy,
val keyTip: String? = null
)

data class RibbonContextualTaskGroup(
val title: String,
val hueColor: Color,
val tasks: List<RibbonTask>,
val isActive: Boolean = false
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020-2022 Aurora, Kirill Grouchnikov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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)
* at the specified index.
*
* @param contentIndex Index of the task bar content. Content index starts at 1.
* @return Keytip for the specified content.
*/
fun getContentKeyTip(contentIndex: Int): String

/**
* Returns the keytip for the overflow button of the task bar.
*
* @return Keytip for the overflow button of the task bar.
*/
val overflowButtonKeyTip: String
}

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

Loading

0 comments on commit 4571352

Please sign in to comment.