Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.pseudoankit.coachmark.shape.Arrow
import com.pseudoankit.coachmark.shape.Balloon
import com.pseudoankit.coachmark.util.CoachMarkKey

public enum class Keys { Text1, Text2, TextStart, TextBottom, TextTop }
public enum class Keys { Text1, Text2, TextCenter, TextStart, TextBottom, TextTop }


@Composable
Expand Down Expand Up @@ -85,6 +85,18 @@ private fun ColumnScope.PlotTextsAndUseLocalCoachMarkScope() {
placement = ToolTipPlacement.End
)

CoachMarkTargetText(
text = "Will show tooltip centrally",
alignment = Alignment.CenterHorizontally,
key = Keys.TextCenter,
placement = ToolTipPlacement.ScreenCenter,
tooltip = {
Balloon(arrow = Arrow.Top()) {
Text(text = "tooltip on screen center at enableCoachmark method", color = Color.White)
}
}
)

CoachMarkTargetText(
text = "Will show tooltip to left",
alignment = Alignment.End,
Expand Down Expand Up @@ -156,6 +168,12 @@ private fun Tooltip(key: CoachMarkKey) {
}
}

Keys.TextCenter -> {
Balloon(arrow = Arrow.Top()) {
Text(text = "A tooltip on screen center root level", color = Color.White)
}
}

Keys.TextStart -> {
Balloon(arrow = Arrow.End()) {
Text(text = "A tooltip to the left root level", color = Color.White)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public enum class ToolTipPlacement {
/**
* denotes that tooltip will be placed at bottom of actual view
*/
Bottom
Bottom,

/**
* denotes that tooltip will be placed at the center of the screen, regardless of the actual view.
*/
ScreenCenter

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public fun OverlayLayout(

// place children
layout(constraints.maxWidth, constraints.maxHeight) {
place(placeableCurrent, configCurrent)
place(placeablePrevious, configPrevious)
place(placeableCurrent, configCurrent, constraints.maxWidth, constraints.maxHeight)
place(placeablePrevious, configPrevious, constraints.maxWidth, constraints.maxHeight)
}
}
}
Expand Down Expand Up @@ -125,8 +125,15 @@ private fun measure(
* Centralizes null checks and switching on toolTipPlacement value.
* @param placeable no-op if null
* @param config no-op if null
* @param containerWidth the width of the container overlay
* @param containerHeight the height of the container overlay
*/
private fun Placeable.PlacementScope.place(placeable: Placeable?, config: TooltipConfig?) {
private fun Placeable.PlacementScope.place(
placeable: Placeable?,
config: TooltipConfig?,
containerWidth: Int,
containerHeight: Int
) {
if (placeable != null && config != null) {
val layout = config.layout
var x = 0
Expand All @@ -142,6 +149,10 @@ private fun Placeable.PlacementScope.place(placeable: Placeable?, config: Toolti
fun centerHorizontally() =
(layout.startX + calculateCenteringOffset(layout.width, placeable.width)).toInt()

fun centerVerticallyToScreen() = (containerHeight - placeable.height) / 2

fun centerHorizontallyToScreen() = (containerWidth - placeable.width) / 2

when (config.toolTipPlacement) {
ToolTipPlacement.Start -> {
x = layout.startX.toInt() - placeable.width
Expand All @@ -162,6 +173,11 @@ private fun Placeable.PlacementScope.place(placeable: Placeable?, config: Toolti
x = centerHorizontally()
y = layout.endY.toInt()
}

ToolTipPlacement.ScreenCenter -> {
x = centerHorizontallyToScreen()
y = centerVerticallyToScreen()
}
}

placeable.placeRelative(x, y)
Expand Down