Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GTK 4 examples #122

Open
wants to merge 56 commits into
base: master
Choose a base branch
from

Conversation

gavr123456789
Copy link

Added a simplified version of headerbar, I think this version looks very overcomplicated for someone who will just look for how to implement CSD.

Added an example of a ListBox with different Control widgets

Added simple hello word from your book.

I used with which makes the code much more readable.

README with screenshots of examples to simplify the search for beginners.

@StefanSalewski
Copy link
Owner

Thanks for the examples. I can not promise when I will find time to review unfortunately.

For the with construct, I left it out with some purpose, as it is not a core of Nim language, so not all people may know it, and get more confused. They may think that it is a gintro macro. My strategy for examples is generally to make understanding simple, not that much to make the code look fine. And for some examples I kept the C layout by intent, even if a nimified version would look better. For the GTK4 book I relaxed this, but then I wrote that in the text. Will see how I can use your modifications. For listbox I know not much about it, I read about listview and treeview in 2008 in the Krause gtk2 book but forgot all, and still found no time to learn again.

@gavr123456789
Copy link
Author

They may think that it is a gintro macro

No since now it can't be imported without std/

so not all people may know it,

Method cascading is a very popular concept, found in Pascal, Smalltalk, VB, Dark, Vala, Ruby, many functional languages, etc.

and get more confused

now there is a Readme in which you can explain it in one example:

var x = "yay"
with x:
  add "abc"
  add "efg"

same as

var x = "yay"
x.add "abc" 
x.add "efg

generally to make understanding simple, not that much to make the code look fine

Im sure it also improves the understanding of the code too, making it easier to group actions into groups with objects when you write it, and less distracts the focus of attention when you read it.

@gavr123456789
Copy link
Author

@StefanSalewski the last example with adwaita doesnt work with ARC.
Idk is this a nim bug or bindings.
The error occurs after the application is started inside GObject, it seems that some memory is released before all references to it are dead, may be even #118 related, not sure.

P.S. I continue to study nim, so far I'm just delighted. The most important problem is the quality of nimsuggest, you can practically assume that there is no auto-completion, since you still have to look at the documentation for everything.

@gavr123456789
Copy link
Author

@StefanSalewski Just found great tutorial for GTK 4, may be it will help you with your GTK 4 book
https://github.com/ToshioCP/Gtk4-tutorial

@gavr123456789
Copy link
Author

Now there are adw.Application. So need to fix all adwaita examples error:
Error: ambiguous identifier: 'Application' -- use one of the following: gtk4.Application: Application adw.Application: Application

with window:
title = "GTK4 & Nim"
defaultSize = (200, 200)
child = mainBox

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wanna do content = mainBox here I think. Source: https://gitlab.gnome.org/GNOME/libadwaita/-/blob/main/src/adw-window.c#L206-211

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this exactly. Another example uses setChild which does not work with Adwaita. content = mainBox is the exact right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants