Skip to content

Commit c7464f3

Browse files
committed
Revert "Let various elements access their parents"
This reverts commit 08545d7.
1 parent 08545d7 commit c7464f3

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ 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
87
import com.lambda.gui.api.component.core.IComponent
98
import com.lambda.gui.api.component.core.list.IListComponent
109
import com.lambda.gui.api.component.core.list.ChildComponent
11-
import com.lambda.gui.api.component.core.list.IChildComponent
1210
import com.lambda.gui.api.layer.RenderLayer
1311
import com.lambda.module.modules.client.ClickGui
1412
import com.lambda.util.KeyCode
@@ -17,7 +15,7 @@ import com.lambda.util.math.MathUtils.toInt
1715
import com.lambda.util.math.Rect
1816
import com.lambda.util.math.Vec2d
1917

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

2321
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: MutableList<T>
9+
val children: List<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(override val owner: WindowComponent<*>) : ChildComponent() {
17+
abstract class ButtonComponent(final override val owner: WindowComponent<*>) : ChildComponent() {
1818
abstract val position: Vec2d
1919
abstract val size: Vec2d
2020

@@ -24,7 +24,7 @@ abstract class ButtonComponent(override val owner: WindowComponent<*>) : ChildCo
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 by lazy { owner.subLayer }
27+
private val layer = owner.subLayer
2828
private val animation = AnimationTicker()
2929

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

33
import com.lambda.gui.api.LambdaGui
4+
import com.lambda.gui.api.component.WindowComponent
45
import com.lambda.gui.api.component.core.list.IListComponent
5-
import com.lambda.gui.impl.clickgui.buttons.ModuleButton
6+
import com.lambda.gui.api.component.sub.ButtonComponent
67
import com.lambda.gui.impl.clickgui.windows.TagWindow
78
import com.lambda.module.ModuleRegistry
89
import com.lambda.module.modules.client.ClickGui
10+
import com.lambda.util.Mouse
11+
import com.lambda.util.math.Vec2d
912

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

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

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
34
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, override val owner: TagWindow) : ButtonComponent(owner) {
10+
class ModuleButton(val module: Module, owner: WindowComponent<*>) : 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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.lambda.gui.impl.clickgui.windows
22

3-
import com.lambda.gui.api.LambdaGui
43
import com.lambda.gui.api.component.WindowComponent
54
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(override val owner: LambdaGui) : WindowComponent<ModuleButton>(owner) {
8+
class TagWindow : WindowComponent<ModuleButton>() {
99
override val title = "Test Window"
10-
11-
// TODO: resizing
1210
override var width = 110.0
1311
override var height = 300.0
1412

13+
init {
14+
ModuleRegistry.modules.forEach {
15+
children.add(ModuleButton(it, this))
16+
}
17+
}
18+
1519
override fun onRender() {
1620
updateModules()
1721
super.onRender()

0 commit comments

Comments
 (0)