Skip to content

Commit

Permalink
Add the rest of per-layout logic for keytip anchoring
Browse files Browse the repository at this point in the history
For #56
  • Loading branch information
kirill-grouchnikov committed Sep 12, 2023
1 parent 36de6ae commit 3fcc63c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ internal fun <M : BaseCommandMenuContentModel,
val compositionLocalContext by rememberUpdatedState(currentCompositionLocalContext)
val coroutineScope = rememberCoroutineScope()

val trackBounds = LocalRibbonTrackBounds.current
val trackKeyTips = LocalRibbonTrackKeyTips.current
val trackBounds = LocalRibbonTrackBounds.current && (popupMenu == null)
val trackKeyTips = LocalRibbonTrackKeyTips.current && (popupMenu == null)

Layout(
modifier = modifier.commandButtonLocator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,17 @@ interface CommandButtonLayoutManager : MeasureScope {
preLayoutInfo: CommandButtonPreLayoutInfo
): CommandButtonLayoutInfo

open fun getActionKeyTipAnchorCenterPoint(
fun getActionKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutInfo
): Offset {
return Offset(
(layoutInfo.actionClickArea.left + layoutInfo.actionClickArea.right) / 2.0f,
(layoutInfo.actionClickArea.top + layoutInfo.actionClickArea.bottom) / 2.0f,
)
}
): Offset

open fun getPopupKeyTipAnchorCenterPoint(
fun getPopupKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutInfo
): Offset {
return Offset(
(layoutInfo.popupClickArea.left + layoutInfo.popupClickArea.right) / 2.0f,
(layoutInfo.popupClickArea.top + layoutInfo.popupClickArea.bottom) / 2.0f,
)
}
): Offset
}

fun getCommandButtonKind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.pushingpixels.aurora.component.ribbon

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.painter.Painter
Expand Down Expand Up @@ -296,6 +297,30 @@ object RibbonBandCommandButtonPresentationStates {
popupActionRect = popupActionRect
)
}

override fun getActionKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
// horizontally centered at the bottom edge of the action click area
return Offset(
x = layoutInfo.actionClickArea.left + layoutInfo.actionClickArea.width / 2,
y = layoutInfo.actionClickArea.top + layoutInfo.actionClickArea.height
)
}

override fun getPopupKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
// horizontally centered at the bottom edge of the popup click area
return Offset(
x = layoutInfo.popupClickArea.left + layoutInfo.popupClickArea.width / 2,
y = layoutInfo.popupClickArea.top + layoutInfo.popupClickArea.height
)
}
}

val BigFixed: CommandButtonPresentationState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.pushingpixels.aurora.component.utils.appmenu

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.text.Paragraph
Expand Down Expand Up @@ -737,4 +738,44 @@ internal class CommandButtonLayoutManagerAppMenuLevel2(
popupActionRect = popupActionRect
)
}

override fun getActionKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
return if (layoutDirection == LayoutDirection.Ltr) {
// bottom-right corner of the icon area
Offset(
x = layoutInfo.iconRect.left + layoutInfo.iconRect.width,
y = layoutInfo.actionClickArea.top + layoutInfo.actionClickArea.height
)
} else {
// bottom-left corner of the icon area
Offset(
x = layoutInfo.iconRect.left,
y = layoutInfo.actionClickArea.top + layoutInfo.actionClickArea.height
)
}
}

override fun getPopupKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
return if (layoutDirection == LayoutDirection.Ltr) {
// bottom-left corner of the popup click area
Offset(
x = layoutInfo.popupClickArea.left,
y = layoutInfo.popupClickArea.top + layoutInfo.popupClickArea.height
)
} else {
// bottom-left corner of the popup click area
Offset(
x = layoutInfo.popupClickArea.left + layoutInfo.popupClickArea.width,
y = layoutInfo.popupClickArea.top + layoutInfo.popupClickArea.height
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.text.Paragraph
Expand Down Expand Up @@ -150,6 +151,30 @@ private object WindowMenuBarLayout {
popupActionRect = Rect.Zero
)
}

override fun getActionKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
// horizontally centered at the bottom edge of the action click area
return Offset(
x = layoutInfo.actionClickArea.left + layoutInfo.actionClickArea.width / 2,
y = layoutInfo.actionClickArea.top + layoutInfo.actionClickArea.height
)
}

override fun getPopupKeyTipAnchorCenterPoint(
command: BaseCommand,
presentationModel: BaseCommandButtonPresentationModel,
layoutInfo: CommandButtonLayoutManager.CommandButtonLayoutInfo
): Offset {
// horizontally centered at the bottom edge of the popup click area
return Offset(
x = layoutInfo.popupClickArea.left + layoutInfo.popupClickArea.width / 2,
y = layoutInfo.popupClickArea.top + layoutInfo.popupClickArea.height
)
}
}

val MenuBar: CommandButtonPresentationState =
Expand Down

0 comments on commit 3fcc63c

Please sign in to comment.