GeopJr / ultimate-gtk4-crystal-guide

Learn how to create premium GTK4 apps in Crystal
https://ultimate-gtk4-crystal-guide.geopjr.dev/
Creative Commons Zero v1.0 Universal
19 stars 4 forks source link

custom widgets #6

Open mipmip opened 1 year ago

mipmip commented 1 year ago

Back again with a new question that might be worthy for this awesome guide.

How to create a custom widget by subclassing an existing gtk widget and how to use this with the UI Builder or the BluePrint compiler.

GeopJr commented 1 year ago

I gave it a try but it has to wait until the next gtk4.cr release:

Subclassing is done using annotations. The current gtk4.cr release doesn't include using ui files from gresource - only from path.

I'll point you at the examples from gtk4.cr:

With that said, here's a demo of an app that uses them: https://github.com/GeopJr/ultimate-gtk4-crystal-guide/tree/annotations-demo (!! it uses the master version of gtk4.cr that has gresource support on annotations)

While ui builder template => crystal is pretty straightforward, I couldn't figure out how to do the opposite at the moment :/ (using crystal custom widgets in ui builder files)