# GTK4 0.9.0 released

**URL:** <https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626>\
**Category:** News\
**Tags:** release\
**Created:** [May 16, 2022, 1:04am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626 "2022-05-16T01:04:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [May 16, 2022, 1:04am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/1 "2022-05-16T01:04:57Z")

</div>

[GTK](https://www.gtk.org/) is a library set of libraries used to create UI, base of the well known Gnome desktop.

[GTK4 shard](https://github.com/hugopl/gtk4.cr) 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 🙂

---

<div class="post-metadata">

**Author:** ![mavu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/mavu/32/213_2.png) [@mavu](https://forum.crystal-lang.org/u/mavu)\
**Post date:** [May 16, 2022, 10:17pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/2 "2022-05-16T22:17:33Z")

</div>

I will definitely try this!

Thank you!

---

<div class="post-metadata">

**Author:** ![bararchy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bararchy/32/33_2.png) [@bararchy](https://forum.crystal-lang.org/u/bararchy)\
**Post date:** [May 17, 2022, 6:50am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/3 "2022-05-17T06:50:25Z")

</div>

Really cool!

---

<div class="post-metadata">

**Author:** ![leofigy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/leofigy/32/1606_2.png) [@leofigy](https://forum.crystal-lang.org/u/leofigy)\
**Post date:** [May 18, 2022, 4:46am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/4 "2022-05-18T04:46:14Z")

</div>

Thank you !!!

---

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [June 4, 2022, 8:41pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/5 "2022-06-04T20:41:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cloutiy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/cloutiy/32/222_2.png) [@cloutiy](https://forum.crystal-lang.org/u/cloutiy)\
**Post date:** [June 9, 2022, 9:04pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/6 "2022-06-09T21:04:02Z")

</div>

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

> **[GitHub - AndyObtiva/glimmer-dsl-gtk: Glimmer DSL for GTK - Ruby-GNOME Desktop...](https://github.com/AndyObtiva/glimmer-dsl-gtk)**
>
> Glimmer DSL for GTK - Ruby-GNOME Desktop Development GUI Library - GitHub - AndyObtiva/glimmer-dsl-gtk: Glimmer DSL for GTK - Ruby-GNOME Desktop Development GUI Library

---

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [June 14, 2022, 7:20pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/7 "2022-06-14T19:20:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [June 17, 2022, 9:44am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/8 "2022-06-17T09:44:26Z")

</div>

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

![image](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/b/b9d1f20fac38adbcdabbfaa6616f202ad033e239.jpeg)

I use Arch linux + GNOME 3 + Wayland.

---

<div class="post-metadata">

**Author:** ![serge-hulne](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/serge-hulne/32/1211_2.png) [@serge-hulne](https://forum.crystal-lang.org/u/serge-hulne)\
**Post date:** [August 1, 2023, 6:11pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/9 "2023-08-01T18:11:47Z")

</div>

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) ?

---

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [August 2, 2023, 1:23pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/10 "2023-08-02T13:23:44Z")

</div>

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](https://github.com/hugopl/gtk4.cr/pull/1)

---

<div class="post-metadata">

**Author:** ![GeopJr](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/geopjr/32/1051_2.png) [@GeopJr](https://forum.crystal-lang.org/u/GeopJr)\
**Post date:** [August 2, 2023, 3:28pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/11 "2023-08-02T15:28:48Z")

</div>

The NixOS people have also managed to package Collision (and possibly RTFM) for darwin into a .app bundle [according to one comment](https://github.com/NixOS/nixpkgs/pull/242681#issuecomment-1636195416), might be worth looking into!

---

<div class="post-metadata">

**Author:** ![serge-hulne](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/serge-hulne/32/1211_2.png) [@serge-hulne](https://forum.crystal-lang.org/u/serge-hulne)\
**Post date:** [August 2, 2023, 3:47pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/12 "2023-08-02T15:47:21Z")

</div>

Thank you,

---

<div class="post-metadata">

**Author:** ![gummybears](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/gummybears/32/1886_2.png) [@gummybears](https://forum.crystal-lang.org/u/gummybears)\
**Post date:** [September 3, 2023, 9:23pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/13 "2023-09-03T21:23:30Z")

</div>

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.

```auto
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

```auto
name: gtk4_opengl
version: 0.15.0

dependencies:
  gtk4:
    github: hugopl/gtk4.cr

  lib_gl:
    github: calebuharrison/LibGL
    branch: master

```

---

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [September 4, 2023, 5:06pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/14 "2023-09-04T17:06:10Z")

</div>

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 😅 [Gtk::Widget - GTK4.cr 0.12.0](https://hugopl.github.io/gtk4.cr/Gtk/Widget.html#queue_draw:Nil-instance-method)

I’ll fix that… in mean time you can use the docs for the C library: [Gtk.Widget.add\_tick\_callback](https://docs.gtk.org/gtk4/method.Widget.add_tick_callback.html)

---

<div class="post-metadata">

**Author:** ![gummybears](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/gummybears/32/1886_2.png) [@gummybears](https://forum.crystal-lang.org/u/gummybears)\
**Post date:** [September 7, 2023, 4:15pm UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/15 "2023-09-07T16:15:28Z")

</div>

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

```auto
Gtk::Widget#add_tick_callback

```

Perhaps you can give a small example?

---

<div class="post-metadata">

**Author:** ![hugopl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hugopl/32/970_2.png) [@hugopl](https://forum.crystal-lang.org/u/hugopl)\
**Post date:** [September 10, 2023, 3:35am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/16 "2023-09-10T03:35:34Z")

</div>

There’s an example in the repository.

> <https://github.com/hugopl/gtk4.cr/blob/main/examples/particles.cr#L41>

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.

---

<div class="post-metadata">

**Author:** ![gummybears](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/gummybears/32/1886_2.png) [@gummybears](https://forum.crystal-lang.org/u/gummybears)\
**Post date:** [September 10, 2023, 11:26am UTC](https://forum.crystal-lang.org/t/gtk4-0-9-0-released/4626/17 "2023-09-10T11:26:49Z")

</div>

Thanks for the reply.
