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
@Model | |
data class CardDesignerState( | |
var loadingState: LoadingState = LoadingState.Loaded, | |
var card: MemoryCard = MemoryCard(), | |
var selectedElement: MemoryCardElement? = null, | |
var editElement: MemoryCardElement? = null, | |
var layersDropDownOpen: Boolean = false | |
) |
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
when (val element = state.selectedElement) { | |
null -> { | |
SurfacePropertyControls(state.card.upSide) | |
} | |
else -> { | |
ElementControls(element) | |
} | |
} |
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
if (cardUuid != null && cardUuid.isNotEmpty()) { | |
observe({ repository.getCard(cardUuid) }) { | |
state.card = it | |
state.loadingState = LoadingState.Loaded | |
} | |
} |
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 <T> observe(observable: () -> LiveData<T>, result: (T) -> Unit) { | |
val thing = stateFor<T?> { null } | |
onActive { | |
val observer = | |
Observer<T> { | |
thing.value = it | |
result(it) | |
} | |
with(observable()) { |
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
val onCardSaved = { | |
runBlocking { | |
repository.saveCard(state.card) | |
goto(Destination.HomeScreen) | |
} | |
} | |
MemsetMainTemplate { | |
when (state.loadingState) { | |
LoadingState.Loaded -> CardEditorContent(state, onCardSaved) |
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 | |
@Preview | |
fun PianoRollPreview() { | |
PianoRoll(PianoKey(F, 0), PianoKey(C, 1)) | |
} |
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 PianoRoll(from: PianoKey, to: PianoKey) { | |
val startsAtF = from.note >= F | |
Row { | |
for (octave in from.octave..to.octave) { | |
PianoRollOctave(startsAtF, true, octave) | |
} | |
} | |
} |
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 PianoRollOctave(startFromF: Boolean = false, showNoteNames: Boolean = false, octave: Int? = 0) { | |
Stack { | |
Row { | |
repeat(7) { | |
PianoKey() | |
} | |
} | |
Row { | |
if (startFromF) { |
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
Row { | |
repeat(7) { | |
PianoKey() | |
} | |
} |
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 | |
private fun PianoKey() { | |
ColoredRect( | |
modifier = LayoutPadding(right = 1.dp), | |
color = Color.White, | |
height = 64.dp, | |
width = 16.dp | |
) | |
} |