|
| 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