Skip to content

Commit db1acda

Browse files
committed
cleanup
1 parent f1924cf commit db1acda

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.lambda.gui.impl.clickgui.module.settings.BooleanButton.Companion.bool
2929
import com.lambda.gui.impl.clickgui.module.settings.EnumSlider.Companion.enumSetting
3030
import com.lambda.gui.impl.clickgui.module.settings.KeybindPicker.Companion.keybindSetting
3131
import com.lambda.gui.impl.clickgui.module.settings.NumberSlider.Companion.numericSetting
32-
import com.lambda.gui.impl.clickgui.settings.UnitButton.Companion.unitSetting
32+
import com.lambda.gui.impl.clickgui.module.settings.UnitButton.Companion.unitSetting
3333
import kotlin.reflect.KClass
3434

3535
object GuiManager : Loadable {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ open class Window(
150150
properties.clampPosition = owner is ScreenLayout
151151

152152
onUpdate {
153+
// Update it here
154+
content.updateHeight()
155+
153156
width = widthAnimation
154157
height = titleBar.height + when (minimizing) {
155158
Minimizing.Disabled -> targetHeight

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ class WindowContent(
7373
positionX = owner.titleBar.positionX
7474
positionY = owner.titleBar.let { it.positionY + it.height } + renderScrollOffset * scrollable.toInt()
7575
width = owner.width
76-
77-
height = ClickGui.padding * 2
78-
79-
val lastIndex = children.lastIndex
80-
children.forEachIndexed { i, it ->
81-
height += layoutHeight(it, false, i == lastIndex)
82-
}
8376
}
8477

8578
onShow {
@@ -113,6 +106,15 @@ class WindowContent(
113106
}
114107
}
115108

109+
fun updateHeight() {
110+
height = ClickGui.padding * 2
111+
112+
val lastIndex = children.lastIndex
113+
children.forEachIndexed { i, it ->
114+
height += layoutHeight(it, false, i == lastIndex)
115+
}
116+
}
117+
116118
private fun layoutHeight(layout: Layout, animate: Boolean, isLast: Boolean = false): Double {
117119
var height = layout.height + ClickGui.listStep * (!isLast).toInt()
118120
val animated = layout as? AnimatedChild ?: return height

common/src/main/kotlin/com/lambda/gui/impl/clickgui/core/SliderLayout.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ import com.lambda.gui.component.layout.Layout
2727
import com.lambda.gui.impl.clickgui.module.settings.SettingSlider
2828
import com.lambda.module.modules.client.ClickGui
2929
import com.lambda.util.Mouse
30+
import com.lambda.util.math.MathUtils.toInt
3031
import com.lambda.util.math.Vec2d
3132
import com.lambda.util.math.multAlpha
3233
import com.lambda.util.math.setAlpha
3334
import com.lambda.util.math.transform
3435
import java.awt.Color
3536

3637
class SliderLayout(
37-
owner: Layout
38+
owner: Layout,
39+
private val isVertical: Boolean
3840
) : AnimatedChild(owner, "") {
3941
// Not a great solution
4042
private val setting = owner as? SettingSlider<*, *>
4143
private val showAnim get() = setting?.showAnimation ?: showAnimation
42-
private val hoverAnim get() = setting?.hoverAnimation ?: hoverAnimation
4344
private val pressedBut get() = setting?.pressedButton ?: pressedButton
4445

4546
// Actions
@@ -74,9 +75,9 @@ class SliderLayout(
7475
}
7576

7677
private val dragProgress: Double get() = transform(
77-
mousePosition.x - bg.positionX,
78-
0.0, bg.width,
79-
0.0, 1.0
78+
if (isVertical) mousePosition.y - bg.positionY else mousePosition.x - bg.positionX,
79+
0.0, if (isVertical) bg.height else bg.width,
80+
isVertical.toInt().toDouble(), 1.0 - isVertical.toInt().toDouble()
8081
).coerceIn(0.0, 1.0)
8182

8283
init {
@@ -93,7 +94,13 @@ class SliderLayout(
9394
rect {
9495
onUpdate { // progress
9596
rect = bg.rect
96-
width *= renderProgress
97+
98+
if (isVertical) {
99+
height *= renderProgress
100+
positionY = bg.positionY + bg.height - height
101+
} else {
102+
width *= renderProgress
103+
}
97104

98105
shade = ClickGui.backgroundShade
99106
setColor(Color.WHITE.setAlpha(0.25 * showAnim))
@@ -118,25 +125,28 @@ class SliderLayout(
118125
*/
119126
@UIBuilder
120127
fun Layout.slider(
128+
isVertical: Boolean = false,
121129
block: SliderLayout.() -> Unit = {}
122-
) = SliderLayout(this).apply(children::add).apply(block)
130+
) = SliderLayout(this, isVertical).apply(children::add).apply(block)
123131

124132
/**
125133
* Adds a [SliderLayout] behind given [layout]
126134
*/
127135
@UIBuilder
128136
fun Layout.sliderBehind(
129137
layout: Layout,
138+
isVertical: Boolean = false,
130139
block: SliderLayout.() -> Unit = {}
131-
) = SliderLayout(this).insertLayout(this, layout, false).apply(block)
140+
) = SliderLayout(this, isVertical).insertLayout(this, layout, false).apply(block)
132141

133142
/**
134143
* Adds a [SliderLayout] over given [layout]
135144
*/
136145
@UIBuilder
137146
fun Layout.sliderOver(
138147
layout: Layout,
148+
isVertical: Boolean = false,
139149
block: SliderLayout.() -> Unit = {}
140-
) = SliderLayout(this).insertLayout(this, layout, true).apply(block)
150+
) = SliderLayout(this, isVertical).insertLayout(this, layout, true).apply(block)
141151
}
142152
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/KeybindPicker.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ class KeybindPicker(
4343
}
4444
}
4545

46+
onShow {
47+
isListening = false
48+
}
49+
50+
onTick {
51+
val module = (owner.owner as? ModuleLayout) ?: return@onTick
52+
if (module.isMinimized) isListening = false
53+
}
54+
4655
onMouseAction(Mouse.Button.Left) {
4756
isListening = !isListening
4857
}
@@ -53,15 +62,6 @@ class KeybindPicker(
5362
settingDelegate = key
5463
isListening = false
5564
}
56-
57-
onShow {
58-
isListening = false
59-
}
60-
61-
onTick {
62-
val module = (owner.owner as? ModuleLayout) ?: return@onTick
63-
if (module.isMinimized) isListening = false
64-
}
6565
}
6666

6767
companion object {

common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/SettingSlider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ abstract class SettingSlider <V : Any, T: AbstractSetting<V>>(
3434
abstract val settingValue: String
3535

3636
private var changeAnimation by animation.exp(0.0, 1.0, 0.5) { true }
37-
3837
private val sliderHeight = 3.0
3938

4039
protected val slider = sliderBehind(titleBar) {

common/src/main/kotlin/com/lambda/gui/impl/clickgui/settings/UnitButton.kt renamed to common/src/main/kotlin/com/lambda/gui/impl/clickgui/module/settings/UnitButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.gui.impl.clickgui.settings
18+
package com.lambda.gui.impl.clickgui.module.settings
1919

2020
import com.lambda.config.settings.FunctionSetting
2121
import com.lambda.gui.component.core.UIBuilder
@@ -28,7 +28,7 @@ class UnitButton <T> (
2828
setting: FunctionSetting<T>,
2929
) : SettingLayout<() -> T, FunctionSetting<T>>(owner, setting) {
3030
init {
31-
onMouse(Mouse.Button.Left, Mouse.Action.Click) {
31+
onMouseAction(Mouse.Button.Left) {
3232
setting.value()
3333
}
3434
}

0 commit comments

Comments
 (0)