Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Sandbox samples key input interfering with the main dropdown by making the scene container focusable #1795

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions korge-sandbox/src/commonMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class Demo(val sceneBuilder: () -> Scene, val name: String = sceneBuilder()::cla

suspend fun Stage.demoSelector(default: Demo, all: List<Demo>) {
val container = sceneContainer(size = Size(width, height - 48f)) { }.xy(0, 48)
val containerFocus = container.makeFocusable()

lateinit var comboBox: UIComboBox<Demo>

Expand All @@ -256,6 +257,7 @@ suspend fun Stage.demoSelector(default: Demo, all: List<Demo>) {
comboBox.selectedItem = demo
views.clearColor = DEFAULT_KORGE_BG_COLOR
container.changeTo {
containerFocus.focus()
demo.sceneBuilder().also { it.init(this) }
}
}
Expand Down
11 changes: 11 additions & 0 deletions korge/src/commonMain/kotlin/korlibs/korge/ui/UIFocusManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ interface UIFocusable {
val isFocusable: Boolean
fun focusChanged(value: Boolean)
}

fun View.makeFocusable(tabIndex: Int = 0, onChanged: (value: Boolean) -> Unit = {}): UIFocusable {
focusable = object : UIFocusable {
override val UIFocusManager.Scope.focusView: View get() = this@makeFocusable
override var tabIndex: Int = tabIndex
override val isFocusable: Boolean get() = true
override fun focusChanged(value: Boolean) { onChanged(value) }
}
return focusable!!
}

var UIFocusable.focused: Boolean
get() = UIFocusManager.Scope.focusView.stage?.uiFocusedView == this
set(value) {
Expand Down