Skip to content

Commit

Permalink
Support RTL in drawPastOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtakac committed Jan 29, 2025
1 parent 07f1e73 commit 1b67bd3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ package com.davidtakac.bura.graphs.common
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.LayoutDirection

fun DrawScope.drawPastOverlay(
nowX: Float,
layoutDirection: LayoutDirection = LayoutDirection.Ltr,
args: GraphArgs
) {
drawLine(
Expand All @@ -26,17 +28,20 @@ fun DrawScope.drawPastOverlay(
end = Offset(x = nowX, y = size.height),
strokeWidth = 2f
)
val topLeftX = if (layoutDirection == LayoutDirection.Ltr) 0f else nowX
val overlayWidth = if (layoutDirection == LayoutDirection.Ltr) nowX else size.width - nowX
drawRect(
color = args.pastOverlayColor,
topLeft = Offset.Zero,
size = Size(width = nowX, height = size.height)
topLeft = Offset(topLeftX, 0f),
size = Size(width = overlayWidth, height = size.height)
)
}

fun DrawScope.drawPastOverlayWithPoint(
nowCenter: Offset,
layoutDirection: LayoutDirection = LayoutDirection.Ltr,
args: GraphArgs
) {
drawPastOverlay(nowCenter.x, args)
drawPastOverlay(nowCenter.x, layoutDirection, args)
drawPoint(nowCenter, args)
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private fun DrawScope.drawHorizontalAxisAndPlot(
)
}
nowCenter?.let {
drawPastOverlayWithPoint(it, args)
drawPastOverlayWithPoint(nowCenter = it, args = args)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private fun DrawScope.drawHorizontalAxisAndBars(
}

nowX?.let {
drawPastOverlay(it, args)
drawPastOverlay(nowX = it, args = args)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private fun DrawScope.drawHorizontalAxisAndPlot(
)
}
nowCenter?.let {
drawPastOverlayWithPoint(it, args)
drawPastOverlayWithPoint(it, layoutDirection, args)
}
}

Expand Down

0 comments on commit 1b67bd3

Please sign in to comment.