Giter Club home page Giter Club logo

Comments (19)

edvin avatar edvin commented on May 13, 2024 1

I implemented it with two possible usage patterns.

  1. Create the nodes for the splitpane up front:
val left = HBox()
val right = HBox()

splitpane(left, right) {
    setDividerPositions(0.3)
}
  1. Add the items inside in a more "builder like" fashion:
splitpane {
    items {
        label("I'm on the left side")
        label("I'm on the right side")
    }
    orientation = HORIZONTAL
    setDividerPositions(0.3)
}

The two options can also be combined. It's possible to shoot yourself in the foot here, but with proper documentation it shouldn't be a problem :)

from tornadofx.

ruckustboom avatar ruckustboom commented on May 13, 2024 1

Works like a charm.
Here's a quick test I did (the basic layout of an app I'm converting from Java to try Kotlin and TornadoFX out):

class TestLayout : View() {
    override val root = VBox()

    init {
        with (root) {
            menubar {
                menu("File") { menuitem("Close") }
                menu("Edit") { menuitem("Delete") }
                menu("Help") { menuitem("About") }
            }
            splitpane {
                items {
                    stackpane { label("Left") }
                    stackpane { label("Middle") }
                    stackpane { label("Right") }
                }
                orientation = Orientation.HORIZONTAL
                setDividerPositions(0.3, 0.7)
                vboxConstraints { vGrow = Priority.ALWAYS }
            }
            hbox { label("Status") }
            prefHeight = 600.0
            prefWidth = 900.0
        }
    }
}

splits

from tornadofx.

edvin avatar edvin commented on May 13, 2024 1

@t-boom wow, nice example :) You're getting the hang of this quick :)) As Thomas said, we appreciate all contributions, from filing issues to pull requests :)

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

It would make sense to add this. I'll take a look and see if I can add it.

from tornadofx.

ruckustboom avatar ruckustboom commented on May 13, 2024

Awesome. I would have tried committing a pull request, but I'm quite new to Kotlin and TornadoFX.

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

Shoot, SplitPane does not extend Pane which the builders target. From what I see we basically have to re-implement every builder for every control for SplitPane or use a fake Pane strategy. The problem with the latter approach is the closure would target a Pane and not allow access to the SplitPane's properties.

@edvin do any ideas immediately pop up to mind?

from tornadofx.

edvin avatar edvin commented on May 13, 2024

I'll give it a shot right now :)

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

I've thought of a couple of strategies, like multi-inheritance delegation, but Pane and SplitPane are classes and not interfaces unfortunately : (

from tornadofx.

edvin avatar edvin commented on May 13, 2024

There are some things we just can't do with extension functions, so maybe down the line we'll change the strategy for the builders and do like JetBrains did with Kara basically. For now, we should go with the same approach we use for the toolbar builder, to stay consistent.

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

Thinking out loud here... is it possible we can create an interface that holds all the builder functions as well as an abstract plusAssign(), and we can apply them to any type such as Pane and SplitPane? If that would work, we can scale this problem for other "Pane-like but not Pane" controls we may have not considered.

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

But I don't think that would work since extension functions can't be applied via interfaces. The target types need to be extended. Darn.

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

Haha you thought that through pretty well. I think that works!

from tornadofx.

edvin avatar edvin commented on May 13, 2024

You're right Thomas, that wouldn't work :( There are a few tradeoffs, but all in all builders are working quite good right now, so I think it's best to leave it like it is for now. Could you add a splitpane example to the docs?

from tornadofx.

edvin avatar edvin commented on May 13, 2024

The items thing is a trick we can use for stuff that doesn't extend pane etc. The good thing is that we could keep this for backwards compatibility even if we change the builder structure later.

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

I agree, you're right that is a better abstraction strategy. I'll add an example definitely.

from tornadofx.

edvin avatar edvin commented on May 13, 2024

Thanks Thomas!

@t-boom Let me know how the splitpane builders work for you :)

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

That is beautiful, thanks for making this request and test driving it. We will likely include it in the coming release probably with the cell factories for TableView.

I hope you are liking Kotlin and TornadoFX so far!

from tornadofx.

ruckustboom avatar ruckustboom commented on May 13, 2024

I'm loving them so far. Hopefully I'll be able to contribute more with experience.

By the way, you guys have possibly the best response time I've ever seen. Kudos 👍

from tornadofx.

thomasnield avatar thomasnield commented on May 13, 2024

No problem! @edvin would have beat me if it wasn't late in Norway. He started a great initiative and I'm excited it caught fire quickly. If you have any questions or suggestions, please let us know. We welcome help!

from tornadofx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.