diff options
Diffstat (limited to 'src/compat/yacl/java/KeybindingController.kt')
-rw-r--r-- | src/compat/yacl/java/KeybindingController.kt | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/src/compat/yacl/java/KeybindingController.kt b/src/compat/yacl/java/KeybindingController.kt index 6be9dd1..204d521 100644 --- a/src/compat/yacl/java/KeybindingController.kt +++ b/src/compat/yacl/java/KeybindingController.kt @@ -31,41 +31,53 @@ class KeybindingController( { option.pendingValue() }, { option.requestSet(it) }, { screen.focused = null }, - { screen.focused = button } + { screen.focused = button }, ) - button = object : ControllerWidget<KeybindingController>(this, screen, widgetDimension) { - override fun getHoveredControlWidth(): Int { - return 130 - } + button = KeybindingWidget(sm, this, screen, widgetDimension) + option.addListener { t, u -> + sm.updateLabel() + } + sm.updateLabel() + return button + } +} + +class KeybindingWidget( + val sm: KeyBindingStateManager, + controller: KeybindingController, + screen: YACLScreen, + dimension: Dimension<Int> +) : ControllerWidget<KeybindingController>(controller, screen, dimension) { + override fun getHoveredControlWidth(): Int { + return 130 + } + + override fun getValueText(): Text { + return sm.label + } - override fun getValueText(): Text { - return sm.label - } + override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { + return sm.keyboardEvent(keyCode, true) + } - override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { - return sm.keyboardEvent(keyCode, true) - } + override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { + return sm.keyboardEvent(keyCode, false) + } - override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { - return sm.keyboardEvent(keyCode, false) - } + override fun unfocus() { + sm.onLostFocus() + } - override fun unfocus() { - sm.onLostFocus() - } + override fun setFocused(focused: Boolean) { + super.setFocused(focused) + if (!focused) sm.onLostFocus() + } - override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { - if (button == 0 && isHovered) { - sm.onClick() - return true - } - return super.mouseClicked(mouseX, mouseY, button) - } + override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { + if (button == 0 && isHovered) { + sm.onClick() + return true } - option.addListener { t, u -> - sm.updateLabel() - } - sm.updateLabel() - return button + return super.mouseClicked(mouseX, mouseY, button) } } |