diff --git a/src/main/kotlin/net/shadowfacts/asmr/UITest.kt b/src/main/kotlin/net/shadowfacts/asmr/TestScreen.kt similarity index 83% rename from src/main/kotlin/net/shadowfacts/asmr/UITest.kt rename to src/main/kotlin/net/shadowfacts/asmr/TestScreen.kt index 5c682af..344df36 100644 --- a/src/main/kotlin/net/shadowfacts/asmr/UITest.kt +++ b/src/main/kotlin/net/shadowfacts/asmr/TestScreen.kt @@ -8,23 +8,18 @@ import net.shadowfacts.shadowui.util.Color class UITest: UIScreen() { init { - val red = UIView().apply { + val red = addView(UIView().apply { backgroundColor = Color(0xff0000) - addView(this) - } - val green = UIView().apply { + }) + val green = addView(UIView().apply { backgroundColor = Color(0x00ff00) - addView(this) - } - val blue = UIView().apply { + }) + val blue = addView(UIView().apply { backgroundColor = Color(0x0000ff) - addView(this) - } - - val purple = UIView().apply { + }) + val purple = green.addSubview(UIView().apply { backgroundColor = Color(0x800080) - green.addSubview(this) - } + }) solver.dsl { red.leftAnchor equalTo 0 diff --git a/src/main/kotlin/net/shadowfacts/shadowui/UIScreen.kt b/src/main/kotlin/net/shadowfacts/shadowui/Screen.kt similarity index 90% rename from src/main/kotlin/net/shadowfacts/shadowui/UIScreen.kt rename to src/main/kotlin/net/shadowfacts/shadowui/Screen.kt index d500acc..16deb29 100644 --- a/src/main/kotlin/net/shadowfacts/shadowui/UIScreen.kt +++ b/src/main/kotlin/net/shadowfacts/shadowui/Screen.kt @@ -10,10 +10,13 @@ open class UIScreen: Screen(TextComponent("UIScreen")) { val views = mutableListOf() - fun addView(view: UIView) { + fun addView(view: UIView): UIView { views.add(view) view.solver = solver + view.wasAdded() + + return view } fun layout() { diff --git a/src/main/kotlin/net/shadowfacts/shadowui/UIView.kt b/src/main/kotlin/net/shadowfacts/shadowui/View.kt similarity index 97% rename from src/main/kotlin/net/shadowfacts/shadowui/UIView.kt rename to src/main/kotlin/net/shadowfacts/shadowui/View.kt index 78e0028..8941a54 100644 --- a/src/main/kotlin/net/shadowfacts/shadowui/UIView.kt +++ b/src/main/kotlin/net/shadowfacts/shadowui/View.kt @@ -31,12 +31,14 @@ class UIView { var parent: UIView? = null val subviews = mutableListOf() - fun addSubview(view: UIView) { + fun addSubview(view: UIView): UIView { subviews.add(view) view.parent = this view.solver = solver view.wasAdded() + + return view } fun wasAdded() { diff --git a/src/main/kotlin/net/shadowfacts/shadowui/geometry/UIRect.kt b/src/main/kotlin/net/shadowfacts/shadowui/geometry/Rect.kt similarity index 100% rename from src/main/kotlin/net/shadowfacts/shadowui/geometry/UIRect.kt rename to src/main/kotlin/net/shadowfacts/shadowui/geometry/Rect.kt