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 @@ -247,7 +247,8 @@ private fun Footer(
) {
TextField(
modifier = Modifier
.fillMaxWidth(),
.fillMaxWidth()
.heightIn(max = 50.dp),
value = "",
placeholderText = "Для проверки клавиатуры",
onValueChange = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ internal val endAlignmentLine = VerticalAlignmentLine(merger = { old, new -> max
* @property size размеры триггера
* @property focusScaleFactor на сколько триггер увеличен в фокусе
* @property topAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot]
* @property bottomAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot]
* @property topAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot]
* @property bottomAlignmentLine нижняя линия выранивания триггера. Рассчитывается относительно [positionInRoot]
* @property startAlignmentLine начальная линия выранивания триггера. Рассчитывается относительно [positionInRoot]
* @property endAlignmentLine конечная линия выранивания триггера. Рассчитывается относительно [positionInRoot]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ private fun CacheDrawScope.createTailPath(
tailWidthPx: Float,
tailHeightPx: Float,
tailPaddingPx: Float,
shape: CornerBasedShape,
): Path {
val tailPath = Path().apply {
addArc(
Expand All @@ -303,11 +304,11 @@ private fun CacheDrawScope.createTailPath(
)
close()
}

val trueSideWidthPx = sideWidthWithoutCorners(placement, shape)
val tailTranslationY =
getTailTranslationY(placement, tailAlignment, tailWidthPx, tailPaddingPx)
getTailTranslationY(placement, tailAlignment, tailWidthPx, tailPaddingPx, trueSideWidthPx)
val tailTranslationX =
getTailTranslationX(placement, tailAlignment, tailWidthPx, tailPaddingPx)
getTailTranslationX(placement, tailAlignment, tailWidthPx, tailPaddingPx, trueSideWidthPx)
val rotation = getTailRotationAngle(placement)
val tailMatrix = Matrix().apply {
translate(x = tailTranslationX, y = tailTranslationY)
Expand All @@ -321,12 +322,18 @@ private fun CacheDrawScope.getTailTranslationX(
tailAlignment: PopoverAlignment,
tailWidthPx: Float,
tailPaddingPx: Float,
trueSideWidthPx: Float,
): Float {
val horizontalAlignment = when (tailAlignment) {
PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2
PopoverAlignment.End -> size.width - tailPaddingPx - tailWidthPx / 2
PopoverAlignment.Center -> size.width / 2
}
val horizontalAlignment =
if (canApplyAlignToTail(tailPaddingPx, tailWidthPx, trueSideWidthPx)) {
when (tailAlignment) {
PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2
PopoverAlignment.End -> size.width - tailPaddingPx - tailWidthPx / 2
PopoverAlignment.Center -> size.width / 2
}
} else {
size.width / 2
}
return when (placement) {
PopoverPlacement.Start -> size.width
PopoverPlacement.End -> 0f
Expand All @@ -341,11 +348,16 @@ private fun CacheDrawScope.getTailTranslationY(
tailAlignment: PopoverAlignment,
tailWidthPx: Float,
tailPaddingPx: Float,
trueSideWidthPx: Float,
): Float {
val verticalAlignment = when (tailAlignment) {
PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2
PopoverAlignment.End -> size.height - tailPaddingPx - tailWidthPx / 2
PopoverAlignment.Center -> size.height / 2
val verticalAlignment = if (canApplyAlignToTail(tailPaddingPx, tailWidthPx, trueSideWidthPx)) {
when (tailAlignment) {
PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2
PopoverAlignment.End -> size.height - tailPaddingPx - tailWidthPx / 2
PopoverAlignment.Center -> size.height / 2
}
} else {
size.height / 2
}
return when (placement) {
PopoverPlacement.Top -> size.height
Expand All @@ -356,6 +368,28 @@ private fun CacheDrawScope.getTailTranslationY(
}
}

private fun CacheDrawScope.sideWidthWithoutCorners(
placement: PopoverPlacement,
shape: CornerBasedShape,
): Float {
val topStart = shape.topStart.toPx(size, this)
val topEnd = shape.topEnd.toPx(size, this)
val bottomStart = shape.bottomStart.toPx(size, this)
val bottomEnd = shape.bottomEnd.toPx(size, this)
return when (placement) {
PopoverPlacement.Start -> size.height - topEnd - bottomEnd
PopoverPlacement.Top -> size.width - bottomStart - bottomEnd
PopoverPlacement.End -> size.height - topStart - bottomStart
PopoverPlacement.Bottom -> size.width - topStart - topEnd
}
}

private fun canApplyAlignToTail(
tailOffset: Float,
tailWidth: Float,
total: Float,
) = if (tailOffset + tailWidth >= total) false else true

private fun Modifier.drawPopover(
shape: CornerBasedShape,
backgroundColor: Brush,
Expand All @@ -382,6 +416,7 @@ private fun Modifier.drawPopover(
tailWidthPx = tailWidthPx,
tailHeightPx = tailHeightPx,
tailPaddingPx = tailPaddingPx,
shape = shape,
)
Path().apply { op(backgroundPath, tailPath, PathOperation.Union) }
}
Expand Down
Loading