Skip to content

Commit

Permalink
Pass command menu handler into the showPopupContent
Browse files Browse the repository at this point in the history
This enables configuring color selector menu content for #56 and #58
  • Loading branch information
kirill-grouchnikov committed Jan 3, 2023
1 parent 61087de commit a904536
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.pushingpixels.aurora.common.AuroraPopupManager
import org.pushingpixels.aurora.common.withAlpha
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.utils.*
import org.pushingpixels.aurora.component.utils.popup.GeneralCommandMenuPopupHandler
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.utils.MutableColorScheme
import kotlin.math.max
Expand Down Expand Up @@ -258,6 +259,7 @@ internal fun <E> AuroraComboBox(
maxVisibleMenuCommands = presentationModel.popupMaxVisibleItems,
popupPlacementStrategy = presentationModel.popupPlacementStrategy
),
popupHandler = GeneralCommandMenuPopupHandler(),
toDismissPopupsOnActivation = true,
toUseBackgroundStriping = true,
popupPlacementStrategy = presentationModel.popupPlacementStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.projection.HorizontalSeparatorProjection
import org.pushingpixels.aurora.component.projection.VerticalSeparatorProjection
import org.pushingpixels.aurora.component.utils.*
import org.pushingpixels.aurora.component.utils.popup.GeneralCommandMenuPopupHandler
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.utils.MutableColorScheme
import java.awt.event.KeyEvent
Expand Down Expand Up @@ -894,6 +895,7 @@ internal fun AuroraCommandButton(
),
contentModel = secondaryContentModel,
presentationModel = presentationModel.popupMenuPresentationModel,
popupHandler = GeneralCommandMenuPopupHandler(),
toDismissPopupsOnActivation = presentationModel.toDismissPopupsOnActivation,
toUseBackgroundStriping = false,
popupPlacementStrategy = presentationModel.popupPlacementStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.pushingpixels.aurora.component.model.Command
import org.pushingpixels.aurora.component.model.CommandButtonPresentationModel
import org.pushingpixels.aurora.component.model.CommandMenuContentModel
import org.pushingpixels.aurora.component.model.CommandPopupMenuPresentationModel
import org.pushingpixels.aurora.component.utils.popup.GeneralCommandMenuPopupHandler
import org.pushingpixels.aurora.component.utils.showPopupContent
import org.pushingpixels.aurora.theming.*

Expand Down Expand Up @@ -84,6 +85,7 @@ fun Modifier.auroraContextMenu(
popupTriggerAreaInWindow = Rect.Zero,
contentModel = contentModelState,
presentationModel = presentationModel,
popupHandler = GeneralCommandMenuPopupHandler(),
toDismissPopupsOnActivation = presentationModel.toDismissOnCommandActivation,
toUseBackgroundStriping = false,
popupPlacementStrategy = presentationModel.popupPlacementStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ import org.pushingpixels.aurora.common.AuroraPopupManager
import org.pushingpixels.aurora.common.AuroraSwingPopupMenu
import org.pushingpixels.aurora.component.*
import org.pushingpixels.aurora.component.model.*
import org.pushingpixels.aurora.component.utils.popup.GeneralCommandMenuPopupHandler
import org.pushingpixels.aurora.theming.*
import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
import java.awt.*
import java.awt.geom.Rectangle2D
import javax.swing.JPopupMenu
import javax.swing.border.Border
import kotlin.math.ceil

internal val Color.awtColor: java.awt.Color
get() = java.awt.Color(
Expand Down Expand Up @@ -68,7 +66,7 @@ internal interface CommandMenuHandler<M : BaseCommandMenuContentModel, L : Comma
}

@OptIn(AuroraInternalApi::class)
internal fun showPopupContent(
internal fun <M : BaseCommandMenuContentModel, L : CommandMenuPopupLayoutInfo> showPopupContent(
popupOriginator: Component,
layoutDirection: LayoutDirection,
density: Density,
Expand All @@ -80,16 +78,15 @@ internal fun showPopupContent(
compositionLocalContext: CompositionLocalContext,
anchorBoundsInWindow: Rect,
popupTriggerAreaInWindow: Rect,
contentModel: State<CommandMenuContentModel?>,
contentModel: State<M?>,
presentationModel: CommandPopupMenuPresentationModel,
popupHandler: CommandMenuHandler<M, L>,
toDismissPopupsOnActivation: Boolean,
toUseBackgroundStriping: Boolean,
popupPlacementStrategy: PopupPlacementStrategy,
overlays: Map<Command, CommandButtonPresentationModel.Overlay>
) {
val popupOriginatorLocationOnScreen = popupOriginator.locationOnScreen

val popupHandler = GeneralCommandMenuPopupHandler()
val popupContentLayoutInfo = popupHandler.getPopupContentLayoutInfo(
menuContentModel = contentModel.value!!,
menuPresentationModel = presentationModel,
Expand All @@ -99,9 +96,8 @@ internal fun showPopupContent(
fontFamilyResolver = fontFamilyResolver
)

// Full size of the popup accounts for extra pixel (in DP units) on each side for the popup border
val fullPopupWidth = ceil(popupContentLayoutInfo.fullSize.width / density.density).toInt() + 2
val fullPopupHeight = ceil(popupContentLayoutInfo.fullSize.height / density.density).toInt() + 2
val fullPopupWidth = popupContentLayoutInfo.popupSize.width
val fullPopupHeight = popupContentLayoutInfo.popupSize.height

// From this point, all coordinates are in Swing display units - which are density independent.
// This is why the popup width and height was converted from pixels.
Expand Down

0 comments on commit a904536

Please sign in to comment.