Skip to content

Commit ed41aae

Browse files
committed
Abstract setting layout
1 parent 0fdcd76 commit ed41aae

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

common/src/main/kotlin/com/lambda/newgui/component/window/TitleBar.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TitleBar(
2424
textHAlignment = HAlign.CENTER
2525

2626
onUpdate {
27+
offsetX = NewCGui.fontOffset
2728
scale = NewCGui.fontScale
2829
}
2930
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.lambda.newgui.impl.clickgui
2+
3+
import com.lambda.config.AbstractSetting
4+
import com.lambda.module.modules.client.NewCGui
5+
import com.lambda.newgui.component.HAlign
6+
import com.lambda.newgui.component.layout.Layout
7+
import com.lambda.newgui.component.window.Window
8+
import com.lambda.util.math.Vec2d
9+
10+
/**
11+
* A base class for setting layouts.
12+
*/
13+
abstract class SettingLayout <V : Any, T: AbstractSetting<V>> (
14+
owner: Layout,
15+
setting: T,
16+
expandable: Boolean = false
17+
) : Window( // going to use window to easily implement expandable settings (such as color picker)
18+
owner,
19+
setting.name,
20+
Vec2d.ZERO, Vec2d.ZERO,
21+
false, false,
22+
if (expandable) Minimizing.Relative else Minimizing.Disabled,
23+
false,
24+
AutoResize.ForceEnabled,
25+
true
26+
) {
27+
init {
28+
overrideSize(owner::renderWidth, NewCGui::settingsHeight)
29+
minimized = true
30+
31+
with(titleBar.textField) {
32+
text = setting.name
33+
bold = false
34+
textHAlignment = HAlign.LEFT
35+
36+
onUpdate {
37+
scale = NewCGui.fontScale * 0.92
38+
}
39+
}
40+
41+
children.removeAll(listOf(titleBarRect, contentRect, outlineRect))
42+
if (!expandable) children.remove(content)
43+
}
44+
}

common/src/main/kotlin/com/lambda/newgui/impl/clickgui/settings/BooleanButton.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package com.lambda.newgui.impl.clickgui.settings
22

33
import com.lambda.config.settings.comparable.BooleanSetting
4-
import com.lambda.module.modules.client.NewCGui
5-
import com.lambda.newgui.component.core.TextField.Companion.textField
64
import com.lambda.newgui.component.core.UIBuilder
75
import com.lambda.newgui.component.layout.Layout
6+
import com.lambda.newgui.impl.clickgui.SettingLayout
7+
import com.lambda.util.Mouse
88

99
class BooleanButton(
1010
owner: Layout,
11-
val setting: BooleanSetting
12-
) : Layout(owner, true, true) {
11+
setting: BooleanSetting
12+
) : SettingLayout<Boolean, BooleanSetting>(owner, setting) {
1313
init {
14-
overrideSize(owner::renderWidth, NewCGui::settingsHeight)
15-
16-
textField {
17-
text = setting.name
18-
scale = NewCGui.fontScale * 0.95
19-
offsetX = NewCGui.fontOffset
14+
titleBar.onMouseClick { button, action ->
15+
if (button == Mouse.Button.Left && action == Mouse.Action.Click) {
16+
setting.value = !setting.value
17+
}
2018
}
2119
}
2220

0 commit comments

Comments
 (0)