This file contains hidden or 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
@Immutable | |
class Sticker( | |
val type: StickerType, | |
val width: Dp, | |
val height: Dp, | |
val offset: Offset, | |
val zIndex: Int, | |
val rotation: Float, | |
val scaleX: Float, | |
val scaleY: Float, |
This file contains hidden or 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
@Stable | |
class Sticker( | |
type: StickerType, | |
width: Dp, | |
height: Dp, | |
offset: Offset, | |
zIndex: Int, | |
rotation: Float, | |
scaleX: Float, | |
scaleY: Float |
This file contains hidden or 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
@Composable | |
fun StickerBoard( | |
stickers: List<Sticker>, | |
modifier: Modifier = Modifier | |
) { | |
Box(modifier.fillMaxWidth().background(Color.White).clipToBounds()) { | |
stickers.forEach { sticker -> | |
key(sticker.id) { | |
Sticker(sticker) | |
} |
This file contains hidden or 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
@Stable | |
sealed interface StickerType { | |
@Stable | |
class Shape( | |
shape: androidx.compose.ui.graphics.Shape, | |
color: Color, | |
borderWidth: Dp, | |
borderColor: Color | |
) : StickerType { | |
var shape by mutableStateOf(shape) |
This file contains hidden or 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
@Immutable | |
sealed interface BoardAction { | |
@Immutable | |
data class Add(val sticker: Sticker) : BoardAction | |
@Immutable | |
data class Remove(val id: String) : BoardAction | |
@Immutable |
This file contains hidden or 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
@Stable | |
class UndoManager(private val stickers: () -> List<Sticker>) { | |
private val undoHistory = mutableStateListOf<BoardAction>() | |
private val redoHistory = mutableStateListOf<BoardAction>() | |
fun register(action: BoardAction) { | |
val invertedAction = action.invert(oldSticker = ???) | |
undoHistory.add(invertedAction) | |
redoHistory.clear() |
OlderNewer