GTK4 0.9.0 released

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 :slight_smile:

25 Likes

I will definitely try this!

Thank you!

2 Likes

Really cool!

1 Like

Thank you !!!

1 Like

Version 0.10.0 just released, now it’s possible to create GObject signals in Crystal :tada:

6 Likes

Out of curiosity are you aware of Glimmer DSL on the ruby side? Nice dsl over gtk.

2 Likes

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.

Works like a charm! It so easy, i only spend less than 2 minutes, make it work!

image

I use Arch linux + GNOME 3 + Wayland.

6 Likes

It looks nice and it is easy to learn.

I was wondering if it is possible to distribute an app build with this library (on Mac) ?
(Does one have to ship some libraries with it) ?

I don’t have access to a mac, so I can’t help, but people got it working on MacOS: add macOS instruction to readme by mamantoha · Pull Request #1 · hugopl/gtk4.cr · GitHub

1 Like

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!

1 Like

Thank you,

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)

shards.yml

name: gtk4_opengl
version: 0.15.0

dependencies:
  gtk4:
    github: hugopl/gtk4.cr

  lib_gl:
    github: calebuharrison/LibGL
    branch: master

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.

BTW I noticed that the docs are being generated without the text in CI :sweat_smile: Gtk::Widget - GTK4.cr 0.12.0

I’ll fix that… in mean time you can use the docs for the C library: Gtk.Widget.add_tick_callback

2 Likes

I got my shader code working but I don’t seem to figure out how to setup/call

Gtk::Widget#add_tick_callback

Perhaps you can give a small example?

There’s an example in the repository.

It just doesn’t use the data (Gdk::FrameClock) to let the animation run at same speed in any hardware, but patches adding this are welcomed.

Thanks for the reply.