Closed J7mbo closed 4 years ago
You could consider below approches:
Excellent, thanks for the options.
@J7mbo or @AllenDang can You write an example for this case ?
@AllenDang @rjablecki Here's a short example of adding widgets dynamically:
package main
import (
g "github.com/AllenDang/giu"
)
func buildStuff() g.Layout{
dynamicLabel := g.Label("I am rendered dynamically!")
dynamicButton := g.Button("I am also rendered dynamically!")
l := g.Layout([]g.Widget{dynamicLabel,dynamicButton})
return l
}
func loop() {
g.SingleWindow("Drag and Drop").Layout(
g.Label("I am not dynamic."),
buildStuff(),
)
}
func main() {
wnd := g.NewMasterWindow("Hi",600,400,g.MasterWindowFlagsNotResizable,nil)
wnd.Run(loop)
}
It took me a few minutes to figure out, so it might be beneficial for AllenDang to add this as an example.
@HACKERALERT Good suggestion, will do. And I think this is the most charming part of immediate ui. :)
Hi, I'm trying to, given the click of a button (in it's triggered func(){}) add another button next to the previous one.
I can't find a concrete example of how to do this because the widgets are not passed by reference. Do I need to copy and re-render the whole window with all it's previous state and just the new button added? How can I achieve this?
Many thanks for the great lib!