package net.shadowfacts.phycon.screen import net.minecraft.client.MinecraftClient import net.minecraft.text.LiteralText import net.minecraft.text.Text import net.minecraft.util.Identifier import net.shadowfacts.cacao.CacaoScreen import net.shadowfacts.cacao.window.Window import net.shadowfacts.cacao.geometry.Axis import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.util.Color import net.shadowfacts.cacao.util.texture.NinePatchTexture import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.view.* import net.shadowfacts.cacao.view.button.Button import net.shadowfacts.cacao.view.textfield.TextField import net.shadowfacts.cacao.viewcontroller.TabViewController import net.shadowfacts.cacao.viewcontroller.ViewController import net.shadowfacts.kiwidsl.dsl /** * @author shadowfacts */ class TestCacaoScreen: CacaoScreen() { init { val viewController = object: ViewController() { override fun loadView() { view = View() } override fun viewDidLoad() { super.viewDidLoad() val stack = view.addSubview(StackView(Axis.VERTICAL, StackView.Distribution.CENTER, spacing = 4.0)).apply { backgroundColor = Color.WHITE } val birch = stack.addArrangedSubview(TextureView(Texture(Identifier("textures/block/birch_log_top.png"), 0, 0, 16, 16))).apply { intrinsicContentSize = Size(50.0, 50.0) } val ninePatch = stack.addArrangedSubview(NinePatchView(NinePatchTexture.PANEL_BG)).apply { intrinsicContentSize = Size(75.0, 100.0) } val red = stack.addArrangedSubview(View()).apply { intrinsicContentSize = Size(50.0, 50.0) backgroundColor = Color.RED } val label = Label(LiteralText("Test"), wrappingMode = Label.WrappingMode.NO_WRAP).apply { // textColor = Color.BLACK } // stack.addArrangedSubview(label) val button = red.addSubview(Button(label)) val field = TextField("Test") { println("new value: ${it.text}") } stack.addArrangedSubview(field) view.solver.dsl { stack.topAnchor equalTo 0 stack.centerXAnchor equalTo window!!.centerXAnchor stack.widthAnchor equalTo 100 button.centerXAnchor equalTo red.centerXAnchor button.centerYAnchor equalTo red.centerYAnchor // label.heightAnchor equalTo 9 button.heightAnchor equalTo 20 field.widthAnchor equalTo stack.widthAnchor field.heightAnchor equalTo 20 } } } addWindow(Window(viewController)) // val viewController = object: ViewController() { // override fun viewDidLoad() { // super.viewDidLoad() // // val tabs = arrayOf( // Tab(Label("A"), AViewController()), // Tab(Label("B"), BViewController()), // ) // val tabVC = TabViewController(tabs) // embedChild(tabVC, pinEdges = false) // // view.solver.dsl { // tabVC.view.centerXAnchor equalTo view.centerXAnchor // tabVC.view.centerYAnchor equalTo view.centerYAnchor // tabVC.view.widthAnchor equalTo 200 // tabVC.view.heightAnchor equalTo 150 // } // } // } // addWindow(Window(viewController)) } data class Tab( override val tabView: View, override val controller: ViewController, override val tooltip: Text? = null ): TabViewController.Tab class AViewController: ViewController() { override fun viewDidLoad() { super.viewDidLoad() val button = Button(Label("A content")) { println("A pressed") } view.addSubview(button) view.solver.dsl { button.centerXAnchor equalTo view.centerXAnchor button.centerYAnchor equalTo view.centerYAnchor } } } class BViewController: ViewController() { override fun viewDidLoad() { super.viewDidLoad() val button = Button(Label("B content")) { println("B pressed") } view.addSubview(button) view.solver.dsl { button.centerXAnchor equalTo view.centerXAnchor button.centerYAnchor equalTo view.centerYAnchor } } } }