gotk3 / gotk3

Go bindings for GTK3
ISC License
2.11k stars 230 forks source link

[Project question] Would BindWidgets() be useful? #635

Open yktoo opened 4 years ago

yktoo commented 4 years ago

For my Ymuse project, which has quite a few widgets, I've created an extended version of Builder. It features the BindWidgets() method, which uses reflection to bind widgets from a .glade file to the same-named fields in a struct.

It saves a lot of searching and casting, and binding a struct is as simple as:

    w := &MainWindow{}
    if err := builder.BindWidgets(w); err != nil {
        log.Fatalf("BindWidgets() failed: %v", err)
    }

The method is quite generic and would bind widgets of any type reflection can recognize. It's also unit-tested.

Would it be interesting to incorporate that in gotk3's codebase?

shackra commented 4 years ago

I was searching for glade in the issue tracker and I'm glad at least there is some code to allow me to design my UI on Glade and use it with this project.