Skip to content

Commit

Permalink
Start work on chained key tips
Browse files Browse the repository at this point in the history
Associate a chain root for each key tip (ribbon, ribbon task, ribbon app menu, command secondary / popup model). Only display top-level key tips when Alt key is pressed in the ribbon window. For #56
  • Loading branch information
kirill-grouchnikov committed Nov 3, 2023
1 parent a3830b2 commit c51a6fb
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,8 @@ internal fun <M : BaseCommandMenuContentModel,

val trackBounds = LocalRibbonTrackBounds.current && (popupMenu == null)
val trackKeyTips = LocalRibbonTrackKeyTips.current && (popupMenu == null)
val keyTipChainRoot = LocalRibbonKeyTipChainRoot.current
//println("${originalProjection.javaClass.simpleName} : ${command.text} -> ${keyTipChainRoot?.javaClass?.simpleName}")
val bandRowHeight = LocalRibbonBandRowHeight.current
val bandRow = LocalRibbonBandRow.current

Expand All @@ -889,7 +891,8 @@ internal fun <M : BaseCommandMenuContentModel,
buttonTopLeftOffset,
buttonSize,
trackBounds,
trackKeyTips
trackKeyTips,
keyTipChainRoot
),
content = {
val modifierAction: Modifier
Expand Down Expand Up @@ -1613,7 +1616,8 @@ internal fun <M : BaseCommandMenuContentModel,
anchor = layoutManager.getActionKeyTipAnchorCenterPoint(command, presentationModel, layoutInfo),
row = bandRow,
rowHeight = bandRowHeight
)
),
keyTipChainRoot
)
}
if ((presentationModel.popupKeyTip != null) && !layoutInfo.popupClickArea.isEmpty) {
Expand All @@ -1625,7 +1629,8 @@ internal fun <M : BaseCommandMenuContentModel,
anchor = layoutManager.getPopupKeyTipAnchorCenterPoint(command, presentationModel, layoutInfo),
row = bandRow,
rowHeight = bandRowHeight
)
),
keyTipChainRoot
)
}
}
Expand Down Expand Up @@ -2080,7 +2085,8 @@ private class CommandButtonLocator(
val topLeftOffset: AuroraOffset,
val size: MutableState<IntSize>,
val trackBounds: Boolean,
val trackKeyTips: Boolean
val trackKeyTips: Boolean,
val keyTipChainRoot: Any?,
) :
OnGloballyPositionedModifier {
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
Expand Down Expand Up @@ -2108,15 +2114,17 @@ private class CommandButtonLocator(
originalProjection,
presentationModel.actionKeyTip!!,
command.isActionEnabled,
bounds
bounds,
keyTipChainRoot
)
}
if (presentationModel.popupKeyTip != null) {
KeyTipTracker.trackKeyTipBase(
originalProjection,
presentationModel.popupKeyTip!!,
command.isSecondaryEnabled,
bounds
bounds,
keyTipChainRoot
)
}
}
Expand All @@ -2132,7 +2140,8 @@ private fun Modifier.commandButtonLocator(
topLeftOffset: AuroraOffset,
size: MutableState<IntSize>,
trackBounds: Boolean,
trackKeyTips: Boolean
trackKeyTips: Boolean,
keyTipChainRoot: Any?,
) = this.then(
CommandButtonLocator(
originalProjection,
Expand All @@ -2141,6 +2150,7 @@ private fun Modifier.commandButtonLocator(
topLeftOffset,
size,
trackBounds,
trackKeyTips
trackKeyTips,
keyTipChainRoot
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.pushingpixels.aurora.common.AuroraInternalApi
import org.pushingpixels.aurora.common.AuroraPopupManager
import org.pushingpixels.aurora.common.AuroraSwingPopupMenu
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.ribbon.impl.LocalRibbonKeyTipChainRoot
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.colorscheme.AuroraColorSchemeBundle
import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
Expand Down Expand Up @@ -203,6 +204,7 @@ interface CascadingCommandMenuHandler<in M : BaseCommandMenuContentModel,
LocalWindowSize provides popupDpSize,
LocalTopWindowSize provides LocalTopWindowSize.current,
LocalSkinColors provides LocalSkinColors.current,
LocalRibbonKeyTipChainRoot provides contentModel.value,
) {
Box(modifier = Modifier.fillMaxSize().background(fillColor)) {
generatePopupContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ internal fun <C : ContentModel, P : PresentationModel> RibbonMetaComponent(

val trackBounds = LocalRibbonTrackBounds.current
val trackKeyTips = LocalRibbonTrackKeyTips.current
val keyTipChainRoot = LocalRibbonKeyTipChainRoot.current
val bandRowHeight = LocalRibbonBandRowHeight.current
val bandRow = LocalRibbonBandRow.current

Layout(
modifier = if (trackBounds) {
modifier.metaComponentLocator(originalProjection, trackBounds, trackKeyTips)
modifier.metaComponentLocator(originalProjection, trackBounds, trackKeyTips, keyTipChainRoot)
} else {
modifier
},
Expand Down Expand Up @@ -320,7 +321,8 @@ internal fun <C : ContentModel, P : PresentationModel> RibbonMetaComponent(
anchor = Offset(captionMid.toFloat(), height / 2.0f),
row = bandRow,
rowHeight = bandRowHeight
)
),
keyTipChainRoot
)
} else {
val componentMid = if (layoutDirection == LayoutDirection.Ltr) {
Expand All @@ -346,7 +348,8 @@ internal fun <C : ContentModel, P : PresentationModel> RibbonMetaComponent(
anchor = Offset(componentMid, height / 2.0f),
row = bandRow,
rowHeight = bandRowHeight
)
),
keyTipChainRoot
)
}
}
Expand Down Expand Up @@ -385,7 +388,8 @@ internal fun <C : ContentModel, P : PresentationModel> RibbonMetaComponent(
private class MetaComponentLocator(
val projection: RibbonMetaComponentProjection<*, *>,
val trackBounds: Boolean,
val trackKeyTips: Boolean
val trackKeyTips: Boolean,
val keyTipChainRoot: Any?,
) :
OnGloballyPositionedModifier {
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
Expand All @@ -407,7 +411,8 @@ private class MetaComponentLocator(
projection,
projection.presentationModel.ribbonComponentPresentationModel.keyTip!!,
projection.enabled.invoke(),
bounds
bounds,
keyTipChainRoot
)
}
}
Expand All @@ -418,8 +423,9 @@ private class MetaComponentLocator(
private fun Modifier.metaComponentLocator(
projection: RibbonMetaComponentProjection<*, *>,
trackBounds: Boolean,
trackKeyTips: Boolean
) = this.then(MetaComponentLocator(projection, trackBounds, trackKeyTips))
trackKeyTips: Boolean,
keyTipChainRoot: Any?,
) = this.then(MetaComponentLocator(projection, trackBounds, trackKeyTips, keyTipChainRoot))

private val DefaultMetaComponentIconTextLayoutGap = 4.dp
private val DefaultMetaComponentLayoutGap = 6.dp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.pushingpixels.aurora.common.isEmpty
import org.pushingpixels.aurora.component.model.ContentModel
import org.pushingpixels.aurora.component.model.PresentationModel
import org.pushingpixels.aurora.component.projection.Projection
import org.pushingpixels.aurora.component.ribbon.Ribbon
import org.pushingpixels.aurora.component.utils.DrawingCache
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
Expand All @@ -56,6 +57,7 @@ object KeyTipTracker {
val isEnabled: Boolean,
var screenRect: AuroraRect,
var anchor: Offset,
val chainRoot: Any? = null,
val traversal: (() -> KeyTipChain)? = null
)

Expand All @@ -73,23 +75,31 @@ object KeyTipTracker {
projection: Projection<ContentModel, PresentationModel>,
keyTip: String,
isEnabled: Boolean,
screenRect: AuroraRect
screenRect: AuroraRect,
chainRoot: Any?,
) {
val existing = keyTips.find {
(it.projection == projection) && (it.keyTip == keyTip)
}
if (existing != null) {
existing.screenRect = screenRect.copy()
} else {
keyTips.add(KeyTipLink(projection, keyTip, isEnabled, screenRect, Offset.Zero))
keyTips.add(KeyTipLink(
projection = projection,
keyTip = keyTip,
isEnabled = isEnabled,
screenRect = screenRect,
anchor = Offset.Zero,
chainRoot = chainRoot))
}
}

fun trackKeyTipOffset(
projection: Projection<ContentModel, PresentationModel>,
keyTip: String,
isEnabled: Boolean,
anchor: Offset
anchor: Offset,
chainRoot: Any?,
) {
val existing = keyTips.find {
(it.projection == projection) && (it.keyTip == keyTip)
Expand All @@ -99,8 +109,12 @@ object KeyTipTracker {
} else {
keyTips.add(
KeyTipLink(
projection, keyTip, isEnabled,
AuroraRect(0.0f, 0.0f, 0.0f, 0.0f), anchor.copy()
projection = projection,
keyTip = keyTip,
isEnabled = isEnabled,
screenRect = AuroraRect(0.0f, 0.0f, 0.0f, 0.0f),
anchor = anchor.copy(),
chainRoot = chainRoot,
)
)
}
Expand Down Expand Up @@ -138,12 +152,16 @@ object KeyTipTracker {
visibleFlow.value = false
}

fun showRootKeyTipChain() {
keyTipChains.add(KeyTipChain(links = keyTips))
fun showRootKeyTipChain(ribbon: Ribbon) {
keyTipChains.add(KeyTipChain(links = keyTips.filter { it.chainRoot == ribbon }))
visibleFlow.value = true
}

fun handleKeyPress(char: Char) {}
fun handleKeyPress(char: Char) {
if (isShowingKeyTips()) {
println("Handling key press $char")
}
}

val visibleFlow = MutableStateFlow(false)
val uiVisibleFlow: StateFlow<Boolean> = visibleFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ val LocalRibbonTrackKeyTips = staticCompositionLocalOf {
false
}

@AuroraInternalApi
val LocalRibbonKeyTipChainRoot = staticCompositionLocalOf<Any?> {
null
}

@AuroraInternalApi
val LocalRibbonBandRow = staticCompositionLocalOf {
RibbonBandRow.None
Expand Down
Loading

0 comments on commit c51a6fb

Please sign in to comment.