Skip to content

Commit

Permalink
code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoankit committed Dec 2, 2023
1 parent 5c3e582 commit bbeae1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,13 +33,15 @@ dependencyResolutionManagement {
```

In your module's build.gradle

```
dependencies {
implementation 'com.github.pseudoankit:coachmark:<version>'
}
```

## Usage

```
public enum class Keys { Text1, Text2 }
Expand Down
2 changes: 1 addition & 1 deletion coachmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bbeae1a

Please sign in to comment.