Hello Zelphir, As an aside note, this email is far too long and mixes far too many subjects and questions 'at the same time', please in the future, make one email per question, keep it short and precise as possible, thanks!
> I am slowly figuring things out with G-Golf and trying to build my > own examples for how to do things with it. (repo: > https://codeberg.org/ZelphirKaltstahl/guilt-gtk-g-golf-examples, or > most recent branch: > https://codeberg.org/ZelphirKaltstahl/guilt-gtk-g-golf-examples/src/branch/feature/add-menu-bar) Before answering your specific quiz, let me immediately suggest: - never refer to (nor even read) earlier doc versions of gtk, always read and take examples from gtk-4 (and g-golf); - use libadwaita, and only use gtk for those widgets that are not provided by libadwaita; - use templates, and define your app (as much as possible) in its sxml files (because it is easier to write and read, to answer one of your below quiz) - use a subdir for those and copy/use the makefile that is in g-golf's libadwaita demo to generate the .ui files whenever you make changes; [ there is a primary menu example in g-golf, the adwaita-1-demo [ port - most of the difficulties you are facing are due to the inherent complexities of the upstream libraries, not g-golf (which actually 'makes things' a lot easier then if you had to program your app in C). > (Q1) Using G-Golf, does one ever have to call `g-object-unref`, or > does G-Golf take care of that? Unless you find a bug, g-golf takes care of those. > ~~~~ > ;; A UI XML string can be processed by a GtkBuilder. I have little experience using gtk builder, upstream developers convinced me to switch to (always) use templates. > (Q2) What does `next-method` do in an `initialize` method? For > example: This is a goops related question. May I recommend you to (carefully) read the goops reference manual, in particular wrt to your quiz: 8.6.4 Next-method 8.11.5 Class Definition Protocol > (define-class <menu-bar-demo-window> (<gtk-application-window>)) As said above, you should use llibadwaita, define your app/example in a template, and subclass using the name of the app. But if you 'stick' to gtk-4, in this particular example of yours, you don't even need to subclass, nor to specialize the default initialize method. > (define-method (initialize (self <menu-bar-demo-window>) initargs) > ;; No idea what `next-method` does. It calls the default initialize method, which as defined by the protocol calls allocate - if you don't, unless you define your own metaclass and its allocation method, your app will 'explode'. > It took me a long time to get the menu bar added to the application. Note that you are learning, most of the difficulties you are facing are due to your lack of knowledge and experience, as well as the overall upstream libs complexities, not due to g-golf. If you stick to gtk-4, as you are learning, always look for and try to port an upstream example, the gtk4-demo nearly covers the entire gtk 'spectrum', in this case: gtk4-demo Applications Class application.ui menu.ui Source ... > (1) The adwaita example renders the _whole_ window from a template, > not only the menu bar. You should also do this, even for a small example, and learn how to define and use templates, as well as how to write the corresponding scheme (g-golf/goops) code that use the template, define one child-id slot per template entry that has an id ... > (2) The adwaita example does not show you how to add a menu bar that > is dynamically built from a string to an application. You don't 'dynamically' define the entries of your menubar in your example either. Though it might be possible, ime, a menubar as a 'fixed number of items, defined in a ui file, that you may hide/show, or activate/disable ... I have yet to add a popover menu example (right-click 'in the old days') ... I am busy on other things for now. > (3) The example does not show how to only load parts of the UI from a > file. That is not possible, by upstream design. > But what if you want to populate or create another > widget ... You'd grab the widget defined in the template by its child-id, then use the upstream api's to append, set-child ... > (4) The examples have almost zero explanatory comments in them. That is because the code explains it all by itself - You just lack upstream lib knowedge and experience, that is what makes your reading g-golf examples experience a bit difficult, but I am sure you'll get there ... > (5) I did not understand at all, why there is an SXML representation > of the UI templates in the > code, but also those ".ui" I prefer to write and read sxml, then generate (and distribute) the required ui files. > sxml->ui is not actually a function, that returns a value, but > merely `display`s the XML string... The g-golf provided sxml->ui calls guile's sxml->xml, which writes the xml tree to the current-output-port. > While I want to make an application, I think I should continue > putting examples into my repo, for myself ... I would start to write your app, using libadwaita (and gtk-4), by 'copying' the g-golf adwaita-1-demo structure and files, just start with a few items in the application.sxml and application.scm, then grow as needed ... I am actually working on an application myself, early stage still so I haven't uploaded its content any where yet - but I did exactly what I suggest you do in the above sentence, cause I am learning to ... and, before I forgot, join #libadwaita:gnome.org and #gtk:gnome.org and ask for design and code help when you're not sure how to achieve some goal ... be aware and prepared that the tone used in these rooms can be a bit ruff though, as they (nearly all) expect you to (deeply) know the upstream lib doc (and how GObject works ofc) > (Q3) Maybe in the future I could contribute the examples to the > G-Golf repo? I'll write those myself, thanks. I actually think that the most important example is the adwaita-1-demo port, as it shows the entire libadwaita spectrum - see the animation page if you need an example of how to subclass and use a gtk layout manager (which is quite a lot more complex then defining a menu :)) The other existing g-golf gtk examples are 'sufficient', imo, as they show how to define and use virtual functions (snapshot) ... For drag-and-drop, see the peg-solitaire. Ofc I can add other examples as needed (I mean if it covers a 'missing' covered feature). > I think to get this little bit of code, one window with a dynamically > created menu bar, I have spent around 4-6h. It is not a problem, > since it is a free time project, but compared to any more mainstream > way of making a GUI application, this is a long time to figure out > the basics. It will take you months (if not years) to become a libadwaita/gtk expert, not hours nor days (it took years to the gimp team to port from gtk-2 to gtk-3) - I still have to regularly ask for help in those matrix rooms myself ... > Keep in mind though, that I have never used GOOPS before. So that > might also be part of the reason, why I don't get some ideas of the > example code. > (Q4) In the past using JavaFX I have had the experience, that > rendering UI from template files was adding noticeable delay when > opening for example a dialog for the first time. Rendering the ui is next to instantaneous, what takes time, in g-golf, is to import the ustream namespace elements - make sure you do this in a separate file (my-app-init.scm), and share it across your app files, just like the g-golf adwaita-1-demo. Good luck for this (complex by nature) endeavor, Email (small and specific) quiz when you need, Cheers, David
pgptrupZLevDx.pgp
Description: OpenPGP digital signature