-
Notifications
You must be signed in to change notification settings - Fork 271
Working with controls that don't have builders available. #95
Comments
Thanks for reporting this! I had missed the ButtonBar builder, so I'll add that right away. To solve your problem with using builders inside an object that is not a Pane, I propose adding a small function called class NewDocumentDialog : Fragment() {
override val root = VBox()
init {
title = "New Document"
with(root) {
label("New Document")
textfield { promptText = "New Document Name" }
add(ButtonBar().apply {
prefHeight = 20.0
prefWidth = 410.0
// Append any builders created inside to `ButtonBar.buttons`
children(buttons) {
button("Create").setOnAction { createDocument() }
button("Cancel").setOnAction { close() }
}
})
}
}
fun createDocument() {
}
fun close() {
this.closeModal()
}
} Also note the Does this seem reasonable to you? |
I've commited the with(root) {
label("New Document")
textfield { promptText = "New Document Name" }
buttonbar {
prefHeight = 20.0
prefWidth = 410.0
children(buttons) {
button("Create").setOnAction { createDocument() }
button("Cancel").setOnAction { close() }
}
}
} @thomasnield The |
I also added special support for adding buttons to a buttonbar, so the above example is now down to: buttonbar {
prefHeight = 20.0
prefWidth = 410.0
button("Create").setOnAction { createDocument() }
button("Cancel").setOnAction { close() }
} I have explained this further with examples and more info in the Wiki: |
@edvin noted! |
I noticed the with(root) {
label("New Document")
textfield { promptText = "New Document Name" }
buttonbar {
prefHeight = 20.0
prefWidth = 410.0
children(buttons) {
button("Create").setOnAction { createDocument() }
vbox { label("Uh-oh") } // What happens here?
button("Cancel").setOnAction { close() }
}
}
} I can't just test it out right now, which is why I'm asking. |
That works fine, since |
I didn't realize that. Good to know. |
Are you satisfied @radicaled ? Should we close the issue? |
Would this basically be the same workflow for ToolBar? |
Yeah, for ToolBar you would use |
I know that, but I was testing an idea a couple days ago that required more than buttons on a toolbar. This children trick should make that a lot easier. |
Yeah, thanks, this looks really good @edvin ! Better than what I was going to do. |
Great @radicaled :) @t-boom The builder pattern we use have certain limitations, and this is one of them. The alternative is to subclass everything though, and that sucks more IMO :) Once you know about the caveats though, it works really well :) |
Here's a modal dialog I have:
I've been using the
pattern to work with controls that don't have builders available, usually custom ones. I'm wondering now if I'm using the right approach of
add
andapply
, and if those with more experience have come up with a better way to handle custom controls.Also, this feels kind of like a misappropriation of the issues tracker -- is there a mailing list for tornadofx that's not listed in the README?
The text was updated successfully, but these errors were encountered: