-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add UI implementation of range selections - add RoundedRangeIllustrator and UnderlineIllustrator as basic types of usage - add RangeIllustrator to make it possible write own illustrators for ranges
- Loading branch information
1 parent
f9c9f21
commit df5f1e0
Showing
12 changed files
with
314 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/modifiers/RangeModifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.wojciechosak.calendar.modifiers | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.draw.drawBehind | ||
import io.wojciechosak.calendar.range.RangeConfig | ||
import kotlinx.datetime.LocalDate | ||
|
||
internal fun Modifier.drawRange( | ||
date: LocalDate, | ||
selectedDates: List<LocalDate>, | ||
config: RangeConfig? = null, | ||
) = composed { | ||
if (config == null) return@composed this | ||
|
||
drawBehind { | ||
with(config) { | ||
val range = | ||
if (selectedDates.size == 2) { | ||
if (selectedDates.first() >= selectedDates.last()) { | ||
Pair(selectedDates.last(), selectedDates.first()) | ||
} else { | ||
Pair(selectedDates.first(), selectedDates.last()) | ||
} | ||
} else { | ||
null | ||
} | ||
|
||
if (range != null && date == range.second) { | ||
rangeIllustrator.drawEnd(this@drawBehind) | ||
} else if (range != null && date == range.first) { | ||
rangeIllustrator.drawStart(this@drawBehind) | ||
} else if (range != null && date in (range.first..range.second)) { | ||
rangeIllustrator.drawMiddle(this@drawBehind) | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.wojciechosak.calendar.range | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import io.wojciechosak.calendar.utils.Pallete.LightBlue | ||
|
||
data class RangeConfig( | ||
val color: Color = LightBlue, | ||
val rangeIllustrator: RangeIllustrator = RoundedRangeIllustrator(color), | ||
) |
11 changes: 11 additions & 0 deletions
11
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeIllustrator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.wojciechosak.calendar.range | ||
|
||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
|
||
interface RangeIllustrator { | ||
fun drawEnd(drawScope: DrawScope) | ||
|
||
fun drawStart(drawScope: DrawScope) | ||
|
||
fun drawMiddle(drawScope: DrawScope) | ||
} |
46 changes: 46 additions & 0 deletions
46
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RoundedRangeIllustrator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.wojciechosak.calendar.range | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
|
||
class RoundedRangeIllustrator( | ||
private val color: Color, | ||
) : RangeIllustrator { | ||
override fun drawEnd(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawArc( | ||
color = color, | ||
startAngle = -90f, | ||
sweepAngle = 180f, | ||
useCenter = true, | ||
) | ||
drawRect( | ||
color = color, | ||
size = size.copy(width = size.width * 0.5f), | ||
) | ||
} | ||
} | ||
|
||
override fun drawStart(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawArc( | ||
color = color, | ||
startAngle = 180f, | ||
sweepAngle = 360f, | ||
useCenter = true, | ||
) | ||
drawRect( | ||
color = color, | ||
size = size.copy(width = size.width * 0.5f), | ||
topLeft = Offset(size.width * 0.5f, 0f), | ||
) | ||
} | ||
} | ||
|
||
override fun drawMiddle(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawRect(color = color) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/UnderlineIllustrator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.wojciechosak.calendar.range | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
|
||
class UnderlineIllustrator( | ||
private val color: Color, | ||
private val y: (Size) -> Float = { it.height }, | ||
private val strokeWidth: Float = 10f, | ||
) : RangeIllustrator { | ||
override fun drawEnd(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawLine( | ||
color = color, | ||
strokeWidth = strokeWidth, | ||
start = Offset(0f, y(size)), | ||
end = Offset(size.width, y(size)), | ||
) | ||
} | ||
} | ||
|
||
override fun drawStart(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawLine( | ||
color = color, | ||
strokeWidth = strokeWidth, | ||
start = Offset(0f, y(size)), | ||
end = Offset(size.width, y(size)), | ||
) | ||
} | ||
} | ||
|
||
override fun drawMiddle(drawScope: DrawScope) { | ||
drawScope.apply { | ||
drawLine( | ||
color = color, | ||
strokeWidth = strokeWidth, | ||
start = Offset(0f, y(size)), | ||
end = Offset(size.width, y(size)), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.