korge icon indicating copy to clipboard operation
korge copied to clipboard

Support ObservableProperty in property editor

Open issacyee opened this issue 2 months ago • 2 comments

This PR adds support for the ObservableProperty type in the Debug property editor and excludes meaningless nested ObservableProperty types.

Previously, if you wanted to edit an ObservableProperty type property in the property editor, you had to create a backing property for it and annotate it with @ViewProperty, like this:

@ViewProperty
var score: Int
    get() = _score.value
    set(value) = _score(value)
private val _score: ObservableProperty<Int> = ObservableProperty(0)

This PR simplifies the process of editing ObservableProperty type properties in the property editor. Now, you only need to annotate it with @ViewProperty:

@ViewProperty
private val score: ObservableProperty<Int> = ObservableProperty(0)

Test Code and Screenshots

// ...

class MainTextBounds2 : Scene() {
    @ViewProperty
    val nestedObsInt: ObservableProperty<ObservableProperty<Int>> = ObservableProperty(ObservableProperty(1))
    @ViewProperty
    val obsInt: ObservableProperty<Int> = ObservableProperty(1)
    @ViewProperty
    val obsPair: ObservableProperty<Pair<Int, Int>> = ObservableProperty(1 to 1)
    // ...

    override suspend fun SContainer.sceneMain() {
        uiVerticalStack {
            uiHorizontalStack {
                uiText("obsInt: ")
                uiText(obsInt.value.toString()) {
                    obsInt.observe { text = it.toString() }
                }
            }
            uiHorizontalStack {
                uiText("obsPair: ")
                uiText(obsPair.value.toString()) {
                    obsPair.observe { text = it.toString() }
                }
            }
            // ...
        }
    }
}
image

issacyee avatar Nov 17 '25 12:11 issacyee

augment review

FSaurenbach avatar Dec 16 '25 12:12 FSaurenbach

Sorry, Augment does not have access to the org this pull request's branch is from.

augmentcode[bot] avatar Dec 16 '25 12:12 augmentcode[bot]