From bbeae1a3e0dbad48b1756c3eeb6e178775bf3deb Mon Sep 17 00:00:00 2001 From: ankitkumar Date: Sun, 3 Dec 2023 00:05:52 +0530 Subject: [PATCH] code reformatting --- README.md | 4 +++ coachmark/src/main/AndroidManifest.xml | 2 +- .../coachmark/demo/UnifyCoachmarkDemo.kt | 25 +++++++++++++++---- .../coachmark/overlay/OverlayLayout.kt | 14 ++++++++--- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d840ac3..ac71b3d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ Now provide seamless onboarding experience to end users with just few lines of c - Compatible with Jetpack Compose UI components. ## Getting Started + In your settings.gradle + ``` dependencyResolutionManagement { repositories { @@ -31,6 +33,7 @@ dependencyResolutionManagement { ``` In your module's build.gradle + ``` dependencies { implementation 'com.github.pseudoankit:coachmark:' @@ -38,6 +41,7 @@ dependencies { ``` ## Usage + ``` public enum class Keys { Text1, Text2 } diff --git a/coachmark/src/main/AndroidManifest.xml b/coachmark/src/main/AndroidManifest.xml index a5918e6..44008a4 100644 --- a/coachmark/src/main/AndroidManifest.xml +++ b/coachmark/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt b/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt index 6d327a8..9a4afd9 100644 --- a/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt +++ b/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt @@ -33,11 +33,26 @@ private fun ColumnScope.PlotTextsAndUseLocalCoachMarkScope() { CoachMarkTargetText("Will show tooltip 2", Alignment.Start, Keys.Text2, ToolTipPlacement.End) - CoachMarkTargetText("Will show tooltip to left", Alignment.End, Keys.TextStart, ToolTipPlacement.Start) - - CoachMarkTargetText("Will show tooltip below", Alignment.CenterHorizontally, Keys.TextBottom, ToolTipPlacement.Bottom) - - CoachMarkTargetText("Will show tooltip above", Alignment.CenterHorizontally, Keys.TextTop, ToolTipPlacement.Top) + CoachMarkTargetText( + "Will show tooltip to left", + Alignment.End, + Keys.TextStart, + ToolTipPlacement.Start + ) + + CoachMarkTargetText( + "Will show tooltip below", + Alignment.CenterHorizontally, + Keys.TextBottom, + ToolTipPlacement.Bottom + ) + + CoachMarkTargetText( + "Will show tooltip above", + Alignment.CenterHorizontally, + Keys.TextTop, + ToolTipPlacement.Top + ) } diff --git a/coachmark/src/main/java/com/pseudoankit/coachmark/overlay/OverlayLayout.kt b/coachmark/src/main/java/com/pseudoankit/coachmark/overlay/OverlayLayout.kt index 21dd356..96827f3 100644 --- a/coachmark/src/main/java/com/pseudoankit/coachmark/overlay/OverlayLayout.kt +++ b/coachmark/src/main/java/com/pseudoankit/coachmark/overlay/OverlayLayout.kt @@ -87,6 +87,7 @@ private fun measure( ToolTipPlacement.Start -> { tooltipConfig.layout.startX.toInt() - gapTooltipScreenPx // left edge of highlight, minus overlay padding } + ToolTipPlacement.End -> { constraintsParent.maxWidth - gapTooltipScreenPx - tooltipConfig.layout.endX.toInt() } @@ -132,24 +133,31 @@ private fun Placeable.PlacementScope.place(placeable: Placeable?, config: Toolti var y = 0 // result positive when highlight is larger, negative when tooltip is larger - fun calculateCenteringOffset(independentHeight: Int, dependentHeight: Int): Int = (independentHeight - dependentHeight) shr 1 + fun calculateCenteringOffset(independentHeight: Int, dependentHeight: Int): Int = + (independentHeight - dependentHeight) shr 1 + + fun centerVertically() = + (layout.startY + calculateCenteringOffset(layout.height, placeable.height)).toInt() - fun centerVertically() = (layout.startY + calculateCenteringOffset(layout.height, placeable.height)).toInt() - fun centerHorizontally() = (layout.startX + calculateCenteringOffset(layout.width, placeable.width)).toInt() + fun centerHorizontally() = + (layout.startX + calculateCenteringOffset(layout.width, placeable.width)).toInt() when (config.toolTipPlacement) { ToolTipPlacement.Start -> { x = layout.startX.toInt() - placeable.width y = centerVertically() } + ToolTipPlacement.End -> { x = layout.endX.toInt() y = centerVertically() } + ToolTipPlacement.Top -> { x = centerHorizontally() y = layout.startY.toInt() - placeable.height } + ToolTipPlacement.Bottom -> { x = centerHorizontally() y = layout.endY.toInt()