Skip to content

Commit 8cb2c81

Browse files
committed
Add KeybindPicker
1 parent 644e314 commit 8cb2c81

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

common/src/main/kotlin/com/lambda/gui/GuiManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import com.lambda.config.settings.NumericSetting
2121
import com.lambda.config.settings.comparable.BooleanSetting
2222
import com.lambda.config.settings.comparable.EnumSetting
2323
import com.lambda.config.settings.FunctionSetting
24+
import com.lambda.config.settings.complex.KeyBindSetting
2425
import com.lambda.core.Loadable
2526
import com.lambda.gui.component.core.UIBuilder
2627
import com.lambda.gui.component.layout.Layout
2728
import com.lambda.gui.impl.clickgui.module.settings.BooleanButton.Companion.booleanSetting
2829
import com.lambda.gui.impl.clickgui.module.settings.EnumSlider.Companion.enumSetting
30+
import com.lambda.gui.impl.clickgui.module.settings.KeybindPicker.Companion.keybindSetting
2931
import com.lambda.gui.impl.clickgui.module.settings.NumberSlider.Companion.numericSetting
3032
import com.lambda.gui.impl.clickgui.settings.UnitButton.Companion.unitSetting
3133
import kotlin.reflect.KClass
@@ -54,6 +56,10 @@ object GuiManager : Loadable {
5456
owner.numericSetting(ref)
5557
}
5658

59+
typeAdapter<KeyBindSetting> { owner, ref ->
60+
owner.keybindSetting(ref)
61+
}
62+
5763
return "Loaded ${typeMap.size} gui type adapters."
5864
}
5965

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.gui.impl.clickgui.module.settings
19+
20+
import com.lambda.config.settings.complex.KeyBindSetting
21+
import com.lambda.gui.component.HAlign
22+
import com.lambda.gui.component.core.TextField.Companion.textField
23+
import com.lambda.gui.component.core.UIBuilder
24+
import com.lambda.gui.component.layout.Layout
25+
import com.lambda.gui.impl.clickgui.module.SettingLayout
26+
import com.lambda.util.KeyCode
27+
import com.lambda.util.extension.displayValue
28+
29+
class KeybindPicker(
30+
owner: Layout,
31+
setting: KeyBindSetting
32+
) : SettingLayout<KeyCode, KeyBindSetting>(owner, setting) {
33+
34+
init {
35+
textField {
36+
text = setting.value.displayValue
37+
textHAlignment = HAlign.RIGHT
38+
}
39+
}
40+
41+
companion object {
42+
/**
43+
* Creates a [KeybindPicker] - visual representation of the [KeyBindSetting]
44+
*/
45+
@UIBuilder
46+
fun Layout.keybindSetting(setting: KeyBindSetting) =
47+
KeybindPicker(this, setting).apply(children::add)
48+
}
49+
}

0 commit comments

Comments
 (0)