Skip to content

Commit

Permalink
Refactor ribbon structure for tracking the contextual menu content
Browse files Browse the repository at this point in the history
Use a new internal composition local to exclude specific ribbon elements such as application menu button, collapsed ribbon band buttons, title pane control buttons and others from being "eligible" to be considered for the taskbar content.

For #56
  • Loading branch information
kirill-grouchnikov committed Sep 10, 2023
1 parent f41eb1f commit 4704fe8
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import org.pushingpixels.aurora.component.projection.HorizontalSeparatorProjecti
import org.pushingpixels.aurora.component.projection.Projection
import org.pushingpixels.aurora.component.projection.VerticalSeparatorProjection
import org.pushingpixels.aurora.component.ribbon.impl.BoundsTracker
import org.pushingpixels.aurora.component.ribbon.impl.LocalRibbonTrackBounds
import org.pushingpixels.aurora.component.utils.*
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.utils.MutableColorScheme
Expand Down Expand Up @@ -880,8 +881,10 @@ internal fun <M : BaseCommandMenuContentModel,
val compositionLocalContext by rememberUpdatedState(currentCompositionLocalContext)
val coroutineScope = rememberCoroutineScope()

val trackBounds = LocalRibbonTrackBounds.current

Layout(
modifier = modifier.commandButtonLocator(originalProjection, buttonTopLeftOffset, buttonSize),
modifier = modifier.commandButtonLocator(originalProjection, buttonTopLeftOffset, buttonSize, trackBounds),
content = {
val modifierAction: Modifier
if (isToggle) {
Expand Down Expand Up @@ -1904,7 +1907,8 @@ private fun CommandButtonPopupIconContent(
private class CommandButtonLocator(
val projection: Projection<ContentModel, PresentationModel>,
val topLeftOffset: AuroraOffset,
val size: MutableState<IntSize>
val size: MutableState<IntSize>,
val trackBounds: Boolean
) :
OnGloballyPositionedModifier {
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
Expand All @@ -1916,21 +1920,24 @@ private class CommandButtonLocator(
// And store the component size
size.value = coordinates.size

BoundsTracker.trackBounds(
projection,
AuroraRect(
x = converted.x,
y = converted.y,
width = coordinates.size.width.toFloat(),
height = coordinates.size.height.toFloat()
if (trackBounds) {
BoundsTracker.trackBounds(
projection,
AuroraRect(
x = converted.x,
y = converted.y,
width = coordinates.size.width.toFloat(),
height = coordinates.size.height.toFloat()
)
)
)
}
}
}

@Composable
private fun Modifier.commandButtonLocator(
projection: Projection<ContentModel, PresentationModel>,
topLeftOffset: AuroraOffset,
size: MutableState<IntSize>
) = this.then(CommandButtonLocator(projection, topLeftOffset, size))
size: MutableState<IntSize>,
trackBounds: Boolean
) = this.then(CommandButtonLocator(projection, topLeftOffset, size, trackBounds))
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.pushingpixels.aurora.component.projection.LabelProjection
import org.pushingpixels.aurora.component.projection.Projection
import org.pushingpixels.aurora.component.ribbon.impl.BoundsTracker
import org.pushingpixels.aurora.component.ribbon.impl.LocalRibbonBandRowHeight
import org.pushingpixels.aurora.component.ribbon.impl.LocalRibbonTrackBounds
import org.pushingpixels.aurora.component.utils.AuroraRect
import org.pushingpixels.aurora.component.utils.getLabelPreferredHeight
import org.pushingpixels.aurora.component.utils.getLabelPreferredSingleLineWidth
Expand All @@ -60,8 +61,10 @@ class RibbonMetaComponentProjection<out C : ContentModel, out P : PresentationMo
get() = this.projection.contentModel

override val presentationModel: MetaComponentPresentationModel<P>
get() = MetaComponentPresentationModel(this.projection.presentationModel,
this.ribbonComponentPresentationModel)
get() = MetaComponentPresentationModel(
this.projection.presentationModel,
this.ribbonComponentPresentationModel
)

@Composable
fun project(modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -172,7 +175,14 @@ internal fun <C : ContentModel, P : PresentationModel> RibbonMetaComponent(
val widthNeededForComponent = projection.intrinsicWidth(rowHeight)
val heightNeededForComponent = projection.intrinsicHeight(widthNeededForComponent)

Layout(modifier = modifier.metaComponentLocator(projection),
val trackBounds = LocalRibbonTrackBounds.current

Layout(
modifier = if (trackBounds) {
modifier.metaComponentLocator(projection)
} else {
modifier
},
content = {
if (hasIcon) {
IconProjection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ internal fun RibbonGallery(
val galleryTopLeftOffset = remember { AuroraOffset(0.0f, 0.0f) }
val gallerySize = remember { mutableStateOf(IntSize(0, 0)) }

val trackBounds = LocalRibbonTrackBounds.current

Layout(modifier = Modifier.galleryLocator(
projection = originalProjection,
topLeftOffset = galleryTopLeftOffset,
size = gallerySize
size = gallerySize,
trackBounds = trackBounds
),
content = {
Row(
Expand Down Expand Up @@ -441,7 +444,8 @@ internal fun RibbonGallery(
private class GalleryLocator(
val projection: Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>,
val topLeftOffset: AuroraOffset,
val size: MutableState<IntSize>
val size: MutableState<IntSize>,
val trackBounds: Boolean
) :
OnGloballyPositionedModifier {
override fun onGloballyPositioned(coordinates: LayoutCoordinates) {
Expand All @@ -453,21 +457,24 @@ private class GalleryLocator(
// And store the component size
size.value = coordinates.size

BoundsTracker.trackBounds(
projection,
AuroraRect(
x = converted.x,
y = converted.y,
width = coordinates.size.width.toFloat(),
height = coordinates.size.height.toFloat()
if (trackBounds) {
BoundsTracker.trackBounds(
projection,
AuroraRect(
x = converted.x,
y = converted.y,
width = coordinates.size.width.toFloat(),
height = coordinates.size.height.toFloat()
)
)
)
}
}
}

@Composable
private fun Modifier.galleryLocator(
projection: Projection<RibbonGalleryContentModel, RibbonGalleryPresentationModel>,
topLeftOffset: AuroraOffset,
size: MutableState<IntSize>
) = this.then(GalleryLocator(projection, topLeftOffset, size))
size: MutableState<IntSize>,
trackBounds: Boolean
) = this.then(GalleryLocator(projection, topLeftOffset, size, trackBounds))
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ import org.pushingpixels.aurora.common.AuroraInternalApi
val LocalRibbonBandRowHeight = staticCompositionLocalOf<Int> {
error("LocalRibbonBandRowHeight not provided")
}

@AuroraInternalApi
val LocalRibbonTrackBounds = staticCompositionLocalOf {
false
}
Loading

0 comments on commit 4704fe8

Please sign in to comment.