www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is anyone running gtk4 is D?

reply aberba <karabutaworld gmail.com> writes:
I'm building a UI component library on top of gtk3 to aid and 
building good looking UI faster with few lines of code. Currently 
using Gtk-d (gtk3)

I know there's a gtk4 branch somewhere but doesn't seem to have 
gained much improvement a while now. I would much rather prefer 
going with the newest version of gtk, v4, rather than the soon to 
be phased out, v3

Is anyone able to use gtk4 in D?
Jan 18
next sibling parent Martyn <martyn.developer googlemail.com> writes:
On Thursday, 18 January 2024 at 09:11:07 UTC, aberba wrote:
 I'm building a UI component library on top of gtk3 to aid and 
 building good looking UI faster with few lines of code. 
 Currently using Gtk-d (gtk3)

 I know there's a gtk4 branch somewhere but doesn't seem to have 
 gained much improvement a while now. I would much rather prefer 
 going with the newest version of gtk, v4, rather than the soon 
 to be phased out, v3

 Is anyone able to use gtk4 in D?
Not heard anything about GTK4 for D. Seems gtk-d is the best option at the moment with gtk3. gtk-d does have a gtk4 branch, but that was last updated 3 years ago. https://github.com/gtkd-developers/GtkD/tree/gtk4 Not sure why there has been no further work. The most recent Issue about the asking the state on GTK4 is below, which was on Aug 22nd 2022. Their reply implies the gtk4 branch does build 'and work' https://github.com/gtkd-developers/GtkD/issues/350 Of course - we are in 2024 now. Not sure if it does work. I guess it is worth a try and see.
Jan 18
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Thursday, 18 January 2024 at 09:11:07 UTC, aberba wrote:
 I'm building a UI component library on top of gtk3 to aid and 
 building good looking UI faster with few lines of code. 
 Currently using Gtk-d (gtk3)

 I know there's a gtk4 branch somewhere but doesn't seem to have 
 gained much improvement a while now. I would much rather prefer 
 going with the newest version of gtk, v4, rather than the soon 
 to be phased out, v3

 Is anyone able to use gtk4 in D?
GTK4 is still a C library, it's very easy to use from D Here is ported their example from here https://docs.gtk.org/gtk4/getting_started.html ![screen](https://i.imgur.com/Y39rtbw.png) ```d extern(C) void activate (GtkApplication* app, gpointer user_data) { GtkWidget *window = gtk_application_window_new (app); gtk_window_set_title (window, "Hello Gtk4 from D!"); gtk_window_set_default_size (window, 640, 480); gtk_window_present (window); } int main () { GtkApplication *app = gtk_application_new ("org.gtk.example", /*G_APPLICATION_DEFAULT_FLAGS*/ 0); g_signal_connect (app, "activate", cast(void*) &activate, 0); int status = g_application_run(app, 0, null); g_object_unref (app); return status; } // gtk4 binding, put that in a separate module as complete as you go pragma(lib, "gtk-4"); pragma(lib, "gio-2.0"); pragma(lib, "gobject-2.0"); pragma(lib, "glib-2.0"); pragma(lib, "gthread-2.0"); alias GtkWidget = void; alias GtkWindow = void; alias GtkApplication = void; alias gpointer = void*; extern(C) GtkWidget* gtk_application_window_new(GtkApplication*); extern(C) void gtk_window_set_title(GtkWindow*, const(char)*); extern(C) void gtk_window_set_default_size(GtkWindow*, int, int); extern(C) void gtk_window_present(GtkWindow*); extern(C) GtkApplication* gtk_application_new(const(char)*, int); // macro extern(C) void g_signal_connect(GtkApplication* instance, const(char)* detailed_signal, void* c_handler, int data) { g_signal_connect_data(instance, detailed_signal, c_handler, data, 0, 0); } extern(C) void g_signal_connect_data (GtkApplication*, const(char)*, void*, int, int, int); extern(C) void g_object_unref(GtkApplication*); extern(C) int g_application_run(GtkApplication*, int, void*); ``` Doing it this way, you can reuse their official documentation, examples, and help, complete the definition from the header as you go, and that's it No need something complicated Unless you want a OOP wrapper, in that case, all you have to do is wrap these calls in your classes, just like what gtkd is doing
Jan 18
parent aberba <karabutaworld gmail.com> writes:
On Thursday, 18 January 2024 at 15:02:39 UTC, ryuukk_ wrote:
 On Thursday, 18 January 2024 at 09:11:07 UTC, aberba wrote:
 [...]
GTK4 is still a C library, it's very easy to use from D Here is ported their example from here https://docs.gtk.org/gtk4/getting_started.html [...]
My brain goes numb whenever I see the pointer symbol. I've avoided C my entire career. I use D like Java.
Jan 18