Dynamically add widgets or groups/hierarchies of widgets when using glade and builder

i’m new to gtk and i’ve built some simple gtk GUIs with rust where i created the gtk widgets in the code instead of using glade and builder. This became unwieldy when the program got more complicated, so i pulled off, as i was also confused with some rust stuff.
Now, i’m learning nim and trying to use glade and builder to create a slightly more complex GUI app than my previous attempt.
What i’m confused about is, how are you supposed to dynamically add (or remove) widgets or widget hierarchies to the existing GUI, based on application state (for ex: foreach file in dir, add horiz box with buttons, labels, entry in them) if using the glade and builder work flow?
Are you just supposed to create whatever widgets and hierarchies you may need in glade and then decide when to use them in the program code?Because it seems like not using some widgets or groups of widgets would alter/break the layout if you did it this way.
Or, are you supposed to create your hierarchy minus any dynamic widgets/widget hierarchies and then manually add/remove those in the program code?
Or some other method i’m not seeing mention/thinking of (like a feature in glade for optional/dynamic widgets. dynamic IDs or something.)?
Any tutorial in written or video form that shows whatever this work flow is supposed to be? I haven’t come across an example of this yet. The language shouldn’t really matter, i wouldn’t think.
thanks

2 Likes

Hullo

For widgets that are dynamically added, I follow the norm :

  1. If the widgets are content-specific or can’t be prepacked, like folders in a user directory (which will change based on the user, file structure etc.), username; then I create and add them as required from the source code itself.
  2. If the widgets’ state is static and will never change, like placeholders, error labels; then I make a dummy window in Glade and fill it with the widgets. Then I add them as required using code by removing it from the dummy window and adding it to the user window.

Either way, the approach I use is kinda coding + Glade. For simple cases, toggling visibility may help. Let’s hear what others say !

cool, thanks for your response!

update: i marked your answer as the solution, as i will likely just do number 1 and see what happens. I think this is a case of making a mountain out of a mole hill, due to inexperience with gtk. :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.