Skip to content

Commit 7364534

Browse files
committed
KeyBindWidget and cleaner setting layout
1 parent a3498dd commit 7364534

File tree

15 files changed

+139
-100
lines changed

15 files changed

+139
-100
lines changed

src/main/kotlin/com/lambda/config/settings/FunctionSetting.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ open class FunctionSetting<T>(
3636
) {
3737
override fun ImGuiBuilder.buildLayout() {
3838
button(name) { value() }
39-
40-
sameLine()
41-
helpMarker(description)
39+
lambdaTooltip(description)
4240
}
4341

4442
override fun toJson(): JsonElement = JsonNull.INSTANCE

src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ abstract class NumericSetting<T>(
6565
val valueString = this@NumericSetting.toString()
6666

6767
buildSlider()
68-
69-
if (description.isNotBlank()) {
70-
lambdaTooltip(description)
71-
}
68+
lambdaTooltip(description)
7269

7370
val itemRectMin = ImGui.getItemRectMin()
7471
val itemRectMax = ImGui.getItemRectMax()

src/main/kotlin/com/lambda/config/settings/StringSetting.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ class StringSetting(
4545
visibility
4646
) {
4747
override fun ImGuiBuilder.buildLayout() {
48-
text(name)
49-
50-
sameLine()
51-
helpMarker(description)
52-
53-
if (multiline) inputTextMultiline(name, ::value, flags = flags)
54-
else inputText(name, ::value, flags)
48+
if (multiline) {
49+
inputTextMultiline(name, ::value, flags = flags)
50+
} else {
51+
inputText(name, ::value, flags)
52+
}
53+
lambdaTooltip(description)
5554
}
5655

5756
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/collections/ListSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ListSetting<T : Any>(
4646
TypeToken.getParameterized(MutableList::class.java, String::class.java).type
4747

4848
override fun ImGuiBuilder.buildLayout() {
49-
combo(name, "${value.size} item(s)") {
49+
combo("##$name", "$name: ${value.size} item(s)") {
5050
immutableList
5151
.forEach {
5252
val isSelected = value.contains(it)

src/main/kotlin/com/lambda/config/settings/collections/SetSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SetSetting<T : Any>(
4545
TypeToken.getParameterized(Set::class.java, String::class.java).type
4646

4747
override fun ImGuiBuilder.buildLayout() {
48-
combo(name, "${value.size} item(s)") {
48+
combo("##$name", "$name: ${value.size} item(s)") {
4949
immutableSet
5050
.forEach {
5151
val isSelected = value.contains(it)

src/main/kotlin/com/lambda/config/settings/comparable/BooleanSetting.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ class BooleanSetting(
4343
) {
4444
override fun ImGuiBuilder.buildLayout() {
4545
checkbox(name, ::value)
46-
47-
if (description.isNotEmpty()) {
48-
lambdaTooltip(description)
49-
}
46+
lambdaTooltip(description)
5047
}
5148

5249
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/comparable/EnumSetting.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class EnumSetting<T : Enum<T>>(
5959

6060
override fun ImGuiBuilder.buildLayout() {
6161
val values = value.enumValues
62-
val preview = value.displayValue
62+
val currentDisplay = value.displayValue
6363

64-
combo("##$name", preview = preview) {
64+
combo("##$name", preview = "$name: $currentDisplay") {
6565
values.forEachIndexed { idx, v ->
6666
val isSelected = idx == index
6767

@@ -73,13 +73,11 @@ class EnumSetting<T : Enum<T>>(
7373
}
7474
}
7575

76-
(value as? Describable)?.let { lambdaTooltip(it.description) }
77-
sameLine()
78-
text(name)
79-
if (description.isNotBlank()) lambdaTooltip(description)
76+
lambdaTooltip(description)
8077
}
8178

8279

80+
8381
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
8482
required(word(name)) { parameter ->
8583
suggests { _, builder ->

src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ import com.lambda.brigadier.execute
2424
import com.lambda.brigadier.required
2525
import com.lambda.config.AbstractSetting
2626
import com.lambda.gui.dsl.ImGuiBuilder
27-
import com.lambda.gui.dsl.ImGuiBuilder.helpMarker
28-
import com.lambda.gui.dsl.ImGuiBuilder.inputVec3i
29-
import com.lambda.gui.dsl.ImGuiBuilder.sameLine
30-
import com.lambda.gui.dsl.ImGuiBuilder.text
31-
import com.lambda.gui.dsl.ProcedureBlock
3227
import com.lambda.util.BlockUtils.blockPos
3328
import com.lambda.util.extension.CommandBuilder
3429
import net.minecraft.command.CommandRegistryAccess
@@ -48,17 +43,9 @@ class BlockPosSetting(
4843
description,
4944
visibility
5045
) {
51-
private var x = "${value.x}"
52-
private var y = value.y
53-
private var z = value.z
54-
5546
override fun ImGuiBuilder.buildLayout() {
56-
text(name)
57-
58-
sameLine()
59-
helpMarker(description)
60-
61-
inputVec3i("##$name", value) { value = it.blockPos }
47+
inputVec3i(name, value) { value = it.blockPos }
48+
lambdaTooltip(description)
6249
}
6350

6451
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/complex/ColorSetting.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ class ColorSetting(
4444
visibility
4545
) {
4646
override fun ImGuiBuilder.buildLayout() {
47-
text(name)
48-
49-
sameLine()
50-
helpMarker(description)
51-
52-
colorEdit("##$name", ::value)
47+
colorEdit(name, ::value)
48+
lambdaTooltip(description)
5349
}
5450

5551
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/complex/KeyBindSetting.kt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
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-
181
package com.lambda.config.settings.complex
192

203
import com.google.gson.reflect.TypeToken
@@ -24,14 +7,12 @@ import com.lambda.brigadier.execute
247
import com.lambda.brigadier.required
258
import com.lambda.config.AbstractSetting
269
import com.lambda.gui.dsl.ImGuiBuilder
10+
import com.lambda.gui.widgets.KeybindWidget
2711
import com.lambda.util.KeyCode
2812
import com.lambda.util.StringUtils.capitalize
2913
import com.lambda.util.extension.CommandBuilder
3014
import net.minecraft.command.CommandRegistryAccess
3115

32-
/**
33-
* @see [com.lambda.config.Configurable]
34-
*/
3516
class KeyBindSetting(
3617
override val name: String,
3718
defaultValue: KeyCode,
@@ -43,8 +24,15 @@ class KeyBindSetting(
4324
description,
4425
visibility
4526
) {
27+
private val widget = KeybindWidget(
28+
label = name,
29+
description = description,
30+
valueGetter = { value },
31+
valueSetter = { value = it },
32+
)
33+
4634
override fun ImGuiBuilder.buildLayout() {
47-
// ToDo
35+
with(widget) { build() }
4836
}
4937

5038
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

0 commit comments

Comments
 (0)