GTK is a library set of libraries used to create UI, base of the well known Gnome desktop.
GTK4 shard is a binding for these libraries based on information given by gobject introspection, but this is too much information for a release anouncement.
So, I think that’s the first version I can tell someone: “Hey, try this for a desktop app in Crystal”, and that’s it, version 0.9.0 was just released
No, I wasn’t, seems a very interesting project, I don’t know how it would behave with more complex projects and widget hierarchies… anyway it’s possible to write something similar on top of crystal/gtk4 shard.
The NixOS people have also managed to package Collision (and possibly RTFM) for darwin into a .app bundle according to one comment, might be worth looking into!
Small example Gtk::GLArea application, just see if I get things “working”.
The render method is only called once, not sure how to get the opengl GLArea updated.
require "gtk4"
require "lib_gl"
def render(w,h)
time_value = Random.new.rand(1)
red_value = Math.sin(time_value).abs
green_value = Math.cos(time_value).abs
blue_value = Math.tan(time_value).abs
LibGL.viewport(0,0,w,h)
# Clear the window with the generated color.
LibGL.clear_color(red_value, green_value, blue_value, 1.0)
LibGL.clear(LibGL::COLOR_BUFFER_BIT)
end
app = Gtk::Application.new("hello.opengl.com", Gio::ApplicationFlags::None)
app.activate_signal.connect do
window = Gtk::ApplicationWindow.new(app)
window.title = "Gtk GLArea"
w = 300
h = 300
window.set_default_size(w,h)
widget = Gtk::GLArea.new
widget.render_signal.connect do
render(w,h)
true
end
window.child = widget
window.present
end
exit(app.run)
You need to tell GTK that something changed and the scene must be redraw.
If you are not doing animations and just want to redraw something you can just call Gtk::Widget#queue_draw when something changed and the scene needs to be redraw.
If you are doing animations you must use Gtk::Widget#add_tick_callback, so you can calculate how much time was spent since last frame and calculate how much your animation must advance.