Skip to content

Commit 393c5d6

Browse files
committed
misc changes
1 parent 43cd5a8 commit 393c5d6

File tree

7 files changed

+47
-39
lines changed

7 files changed

+47
-39
lines changed

common/src/main/kotlin/com/lambda/module/modules/client/NewCGui.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import com.lambda.module.Module
44
import com.lambda.module.ModuleRegistry
55
import com.lambda.module.tag.ModuleTag
66
import com.lambda.newgui.ScreenLayout.Companion.gui
7+
import com.lambda.newgui.component.core.FilledRect.Companion.rect
78
import com.lambda.newgui.impl.clickgui.ModuleLayout.Companion.moduleLayout
89
import com.lambda.newgui.impl.clickgui.ModuleWindow.Companion.moduleWindow
10+
import com.lambda.util.math.Rect
911
import com.lambda.util.math.Vec2d
1012
import com.lambda.util.math.setAlpha
1113
import java.awt.Color
@@ -22,6 +24,8 @@ object NewCGui : Module(
2224

2325
val roundRadius by setting("Round Radius", 2.0, 0.0..10.0, 0.1)
2426

27+
val backgroundTint by setting("Background Tint", Color.BLACK.setAlpha(0.4))
28+
2529
val titleBackgroundColor by setting("Title Background Color", Color.WHITE.setAlpha(0.4))
2630
val backgroundColor by setting("Background Color", Color.WHITE.setAlpha(0.25))
2731
val backgroundShade by setting("Background Shade", true)
@@ -31,20 +35,29 @@ object NewCGui : Module(
3135
val outlineColor by setting("Outline Color", Color.WHITE.setAlpha(0.6)) { outline }
3236
val outlineShade by setting("Outline Shade", true) { outline }
3337

38+
val moduleEnabledColor by setting("Module Enabled Color", Color.WHITE.setAlpha(0.25))
39+
val moduleDisabledColor by setting("Module Disabled Color", Color.WHITE.setAlpha(0.05))
40+
3441
private val SCREEN get() = gui("New Click Gui") {
42+
rect {
43+
rectangle = Rect(Vec2d.ZERO, this.size)
44+
setColor(backgroundTint)
45+
}
46+
3547
val tags = ModuleTag.defaults
3648
val modules = ModuleRegistry.modules
3749

38-
tags.forEachIndexed { i, tag ->
39-
val windowPosition = Vec2d.ONE * 20.0 + Vec2d.RIGHT * ((115.0 * i) + (i + 1) * 4)
50+
var x = 20.0
51+
val y = x
4052

41-
moduleWindow(tag, windowPosition) {
53+
tags.forEachIndexed { i, tag ->
54+
x += moduleWindow(tag, Vec2d(x, y)) {
4255
modules.filter {
4356
it.defaultTags.firstOrNull() == tag
4457
}.forEach { module ->
4558
moduleLayout(module)
4659
}
47-
}
60+
}.width + 3
4861
}
4962
}
5063

common/src/main/kotlin/com/lambda/newgui/component/core/FilledRect.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.lambda.newgui.component.core
22

33
import com.lambda.newgui.component.layout.Layout
4+
import com.lambda.util.math.Rect
45
import java.awt.Color
56

67
class FilledRect(
78
owner: Layout
89
) : Layout(owner, true, true) {
9-
var rectangle = owner.rect
10+
var rectangle = Rect.ZERO
1011

1112
var leftTopRadius = 0.0
1213
var rightTopRadius = 0.0

common/src/main/kotlin/com/lambda/newgui/component/core/TextField.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class TextField(
3232
action(this@TextField)
3333
}
3434

35-
width = textWidth
36-
height = textHeight
37-
38-
val renderPos = Vec2d(renderPositionX, renderPositionY + renderHeight * 0.5)
35+
val renderPos = Vec2d(renderPositionX, renderPositionY + textHeight * 0.5)
3936
fr.build(text, renderPos, color, scale, shadow)
4037
}
4138
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ class TitleBar(
2121
text = title
2222
bold = true
2323

24-
horizontalAlignment = HAlign.CENTER
25-
verticalAlignment = VAlign.CENTER
24+
val tb = this@TitleBar
2625

27-
onUpdate {
28-
val tb = this@TitleBar
29-
positionX = tb.renderPositionX + tb.renderWidth * 0.5 - textWidth * 0.5
30-
positionY = tb.renderPositionY + tb.renderHeight * 0.5 - textHeight * 0.5
31-
}
26+
overrideX { tb.renderPositionX + tb.renderWidth * 0.5 - textWidth * 0.5 }
27+
overrideY { tb.renderPositionY + tb.renderHeight * 0.5 - textHeight * 0.5 }
3228
}
3329

3430
private var dragOffset: Vec2d? = null

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open class Window(
2424
owner: Layout,
2525
initialTitle: String = "Untitled",
2626
initialPosition: Vec2d = Vec2d.ZERO,
27-
initialSize: Vec2d = Vec2d(115.0, 300.0),
27+
initialSize: Vec2d = Vec2d(120.0, 300.0),
2828
draggable: Boolean = true,
2929
scrollable: Boolean = true,
3030
private val minimizing: Minimizing = Minimizing.Relative,
@@ -228,7 +228,8 @@ open class Window(
228228
*
229229
* @param draggable Whether to allow user to drag the window
230230
*
231-
* @param scrollable Whether to allow user to scroll the elements
231+
* @param scrollable Whether to let user scroll the content
232+
* This will also make your elements be vertically ordered
232233
*
233234
* @param minimizing The [Minimizing] mode.
234235
*
@@ -241,7 +242,7 @@ open class Window(
241242
@UIBuilder
242243
fun Layout.window(
243244
position: Vec2d = Vec2d.ZERO,
244-
size: Vec2d = Vec2d(115.0, 300.0),
245+
size: Vec2d = Vec2d(120.0, 300.0),
245246
title: String = "Untitled",
246247
draggable: Boolean = true,
247248
scrollable: Boolean = true,

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.math.abs
88

99
class WindowContent(
1010
owner: Window,
11-
scrollable: Boolean
11+
private val scrollable: Boolean
1212
) : Layout(owner, false, true) {
1313
private val animation = animationTicker(false)
1414

@@ -48,9 +48,7 @@ class WindowContent(
4848
if (abs(rubberbandDelta) < 0.05) rubberbandDelta = 0.0
4949

5050
animation.tick()
51-
}
5251

53-
onRender {
5452
reorderChildren()
5553
}
5654

@@ -61,22 +59,24 @@ class WindowContent(
6159
}
6260

6361
private fun reorderChildren() {
64-
// Skip for closed windows
65-
if (renderHeight < 0.1) return
66-
67-
var offset = renderScrollOffset + NewCGui.padding
68-
69-
children.forEach { child ->
70-
child.positionY = renderPositionY + offset
71-
offset += child.renderHeight + NewCGui.listStep
62+
if (!scrollable) return
63+
64+
children.forEachIndexed { i, child ->
65+
val prev by lazy { children[i - 1] }
66+
67+
child.overrideY {
68+
if (i == 0) {
69+
renderPositionY + renderScrollOffset + NewCGui.padding
70+
} else {
71+
prev.renderPositionY + prev.renderHeight + NewCGui.listStep
72+
}
73+
}
7274
}
7375
}
7476

7577
fun getContentHeight(): Double {
76-
val c = children
77-
78-
val components = c.sumOf(Layout::renderHeight)
79-
val step = NewCGui.listStep * (c.size - 1).coerceAtLeast(0)
78+
val components = children.sumOf(Layout::renderHeight)
79+
val step = NewCGui.listStep * (children.size - 1).coerceAtLeast(0)
8080
val padding = NewCGui.padding * 2
8181

8282
return components + step + padding
@@ -87,6 +87,7 @@ class WindowContent(
8787
* Creates an empty [WindowContent] component
8888
*
8989
* @param scrollable Whether to let user scroll this layout
90+
* This will also make your elements be vertically ordered
9091
*/
9192
@UIBuilder
9293
fun Window.windowContent(scrollable: Boolean) =

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class ModuleLayout(
4242
with(titleBar) {
4343
with(textField) {
4444
bold = false
45-
horizontalAlignment = HAlign.LEFT
4645

47-
onUpdate {
48-
positionX = titleBar.renderPositionX + (titleBar.renderHeight - textHeight) * 0.5
46+
overrideX {
47+
titleBar.renderPositionX + (titleBar.renderHeight - textHeight) * 0.5
4948
}
5049
}
5150

@@ -65,12 +64,12 @@ class ModuleLayout(
6564
}
6665

6766
titleBarRect.onUpdate {
68-
setColor(lerp(enableAnimation, NewCGui.titleBackgroundColor.multAlpha(0.15), NewCGui.titleBackgroundColor))
67+
setColor(lerp(enableAnimation, NewCGui.moduleDisabledColor, NewCGui.moduleEnabledColor))
6968
correctRadius()
7069
}
7170

7271
contentRect.onUpdate {
73-
setColor(lerp(enableAnimation, NewCGui.backgroundColor.multAlpha(0.15), NewCGui.backgroundColor))
72+
setColor(lerp(enableAnimation, NewCGui.moduleDisabledColor, NewCGui.moduleEnabledColor))
7473
correctRadius()
7574
}
7675

0 commit comments

Comments
 (0)