Skip to content

Commit 08545d7

Browse files
committed
Let various elements access their parents
1 parent 14fbebc commit 08545d7

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import com.lambda.graphics.animation.Animation.Companion.exp
44
import com.lambda.graphics.animation.AnimationTicker
55
import com.lambda.graphics.gl.Scissor.scissor
66
import com.lambda.graphics.renderer.gui.font.IFontEntry
7+
import com.lambda.gui.api.LambdaGui
78
import com.lambda.gui.api.component.core.IComponent
89
import com.lambda.gui.api.component.core.list.IListComponent
910
import com.lambda.gui.api.component.core.list.ChildComponent
11+
import com.lambda.gui.api.component.core.list.IChildComponent
1012
import com.lambda.gui.api.layer.RenderLayer
1113
import com.lambda.module.modules.client.ClickGui
1214
import com.lambda.util.KeyCode
@@ -15,7 +17,7 @@ import com.lambda.util.math.MathUtils.toInt
1517
import com.lambda.util.math.Rect
1618
import com.lambda.util.math.Vec2d
1719

18-
abstract class WindowComponent <T : ChildComponent> : InteractiveComponent(), IListComponent<T> {
20+
abstract class WindowComponent <T : ChildComponent> (override val owner: LambdaGui) : InteractiveComponent(), IListComponent<T>, IChildComponent {
1921
abstract val title: String
2022

2123
abstract var width: Double

common/src/main/kotlin/com/lambda/gui/api/component/core/list/IListComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.lambda.util.Mouse
66
import com.lambda.util.math.Vec2d
77

88
interface IListComponent <T : IComponent> : IComponent {
9-
val children: List<T>
9+
val children: MutableList<T>
1010

1111
fun isChildAccessible(child: T): Boolean = true
1212

common/src/main/kotlin/com/lambda/gui/api/component/sub/ButtonComponent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.lambda.util.math.Vec2d
1414
import java.awt.Color
1515
import kotlin.math.abs
1616

17-
abstract class ButtonComponent(final override val owner: WindowComponent<*>) : ChildComponent() {
17+
abstract class ButtonComponent(override val owner: WindowComponent<*>) : ChildComponent() {
1818
abstract val position: Vec2d
1919
abstract val size: Vec2d
2020

@@ -24,7 +24,7 @@ abstract class ButtonComponent(final override val owner: WindowComponent<*>) : C
2424
private val actualSize get() = Vec2d(if (size.x == FILL_PARENT) owner.contentRect.size.x else size.x, size.y)
2525
final override val rect get() = Rect.basedOn(position, actualSize) + owner.contentRect.leftTop
2626

27-
private val layer = owner.subLayer
27+
private val layer by lazy { owner.subLayer }
2828
private val animation = AnimationTicker()
2929

3030
private var activeAnimation by animation.exp(0.0, 1.0, 0.1, ::active)
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.lambda.gui.impl.clickgui
22

33
import com.lambda.gui.api.LambdaGui
4-
import com.lambda.gui.api.component.WindowComponent
54
import com.lambda.gui.api.component.core.list.IListComponent
6-
import com.lambda.gui.api.component.sub.ButtonComponent
5+
import com.lambda.gui.impl.clickgui.buttons.ModuleButton
76
import com.lambda.gui.impl.clickgui.windows.TagWindow
87
import com.lambda.module.ModuleRegistry
98
import com.lambda.module.modules.client.ClickGui
10-
import com.lambda.util.Mouse
11-
import com.lambda.util.math.Vec2d
129

13-
class LambdaClickGui : LambdaGui("Lambda ClickGui", ClickGui), IListComponent<WindowComponent<*>> {
14-
override val children = mutableListOf<WindowComponent<*>>()
10+
class LambdaClickGui : LambdaGui("Lambda ClickGui", ClickGui), IListComponent<TagWindow> {
11+
override val children = mutableListOf<TagWindow>()
1512

1613
init {
17-
children.add(TagWindow())
14+
TagWindow(this).apply {
15+
children.addAll(
16+
ModuleRegistry.modules.map {
17+
ModuleButton(it, this)
18+
}
19+
)
20+
}.apply(children::add)
1821
}
1922
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.lambda.gui.impl.clickgui.buttons
22

3-
import com.lambda.gui.api.component.WindowComponent
43
import com.lambda.gui.api.component.sub.ButtonComponent
4+
import com.lambda.gui.impl.clickgui.windows.TagWindow
55
import com.lambda.module.Module
66
import com.lambda.module.modules.client.ClickGui
77
import com.lambda.util.Mouse
88
import com.lambda.util.math.Vec2d
99

10-
class ModuleButton(val module: Module, owner: WindowComponent<*>) : ButtonComponent(owner) {
10+
class ModuleButton(val module: Module, override val owner: TagWindow) : ButtonComponent(owner) {
1111
override val position get() = Vec2d(0.0, heightOffset)
1212
override val size get() = Vec2d(FILL_PARENT, ClickGui.buttonHeight)
1313

common/src/main/kotlin/com/lambda/gui/impl/clickgui/windows/TagWindow.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.lambda.gui.impl.clickgui.windows
22

3+
import com.lambda.gui.api.LambdaGui
34
import com.lambda.gui.api.component.WindowComponent
45
import com.lambda.gui.impl.clickgui.buttons.ModuleButton
5-
import com.lambda.module.ModuleRegistry
66
import com.lambda.module.modules.client.ClickGui
77

8-
class TagWindow : WindowComponent<ModuleButton>() {
8+
class TagWindow(override val owner: LambdaGui) : WindowComponent<ModuleButton>(owner) {
99
override val title = "Test Window"
10+
11+
// TODO: resizing
1012
override var width = 110.0
1113
override var height = 300.0
1214

13-
init {
14-
ModuleRegistry.modules.forEach {
15-
children.add(ModuleButton(it, this))
16-
}
17-
}
18-
1915
override fun onRender() {
2016
updateModules()
2117
super.onRender()

0 commit comments

Comments
 (0)