Hi David!
On 28.05.25 20:36, David Pirotte wrote:
I wonder why that is though. I imagine (I don't know that for sure at
all, so some Dunning-Kruger chance here) that internally Gtk probably
uses the same machinery ...
Not at all. A template is installed at (GObject) class initialization
time, and as a user, since g-golf provides the adequate machinery, you
won't need to call get-object anymore, providing 'you do the write
thing', you'll get access to those widgets as instance slots: just look
at the <adw-demo-window> class definition, and for example, search for
all occurrences of the word stack, or split-view (or any child-id slot
name ... search in the sxml ui file and in the (adw-demo-window)
module, to see how this works ...
I feel like you misunderstood completely what I am trying to say.
The rendered widgets are not the XML itself. At some point the XML must be
translated to the objects, that will be rendered as user interface on our
screens. Whether you pass the template to the constructor or not, this step must
happen somewhere, somehow. To me it would make a lot of sense, if it turned out,
that the XML file one passes to the constructor will also be processed the same
way. Either GtkBuilder knows which classes to use when making widgets from the
XML representation, or the classes know to call GtkBuilder, that knows what
widget to make and how to set their attributes. It would not make much sense to
have 2 completely separate ways to create instances of widget or other user
interface objects.
That's what I meant by using the same machinery. That is why I wonder, why
GtkBuilder was discouraged by them, why they convinced you not to use it,
despite it being in the official docs in simple examples.
And as I said, I don't know the internals of GTK, so maybe they do have some
reason to maintain 2 completely separate ways of making widgets. I don't know.
Just seems unlikely to me.Dunning-Kruger totally possible.
How could I create the GMenu from a UI file instead?
There are quite a few examples in the adwaita-1-demo, one among others
in the pages/buttons/buttons-ui.scm, %sample-menu ...
This is also a misunderstanding of what I mean.
That example code shows how to construct the SXML for a menu. That is what I
already have in my own example for a menu bar. It is probably even what I copied
and adapted to write the SXML in my code. It is great and helpful as such.
However, it does not show how to _only_ use that SXML for the menu. It
integrates that SXML into a larger SXML for %buttons-page. Which is then
probably integrated into an even larger one. Which is all fine and great! Just
that it is not an example for making _only_ a visible menu from SXML. An example
doing that would have shown me, that a menu constructor maybe also has a
#:template argument and that I could be using a UI file for that as well. That
would be great, as a general concept of GTK, while being only able to do that on
a window would diminish its generality and with that its usefulness.
Best regards,
Zelphir
--
repositories:https://codeberg.org/ZelphirKaltstahl