https://kotlinlang.org logo
#gui
Title
m

Marshall

10/20/2020, 7:24 PM
has anyone tried to make a kotlin gtk app?
m

Miroslav Sobotka

10/21/2020, 4:04 PM
I tried. At that moment the easiest way was to take the libui. There is also a repository with finished artifacts on bintray. You can see it on my project. The good way would be to have a nice DSL like with libui, or to be able to take the XML from the Gnome Designer (Glade).
m

Marshall

10/21/2020, 4:07 PM
Yeah the kotlin-native-gtk provides a DSL, it generates it from the GIR XML provided by gtk
👍 1
I was able to build and run the sample
message has been deleted
The sample code looks pretty decent, very similar to tornadofx or well any GUI with kotlin DSL I've seen so far:
Copy code
vbox {
            hbox {
                hbbox {
                    button {
                        label = "Quit"
                        onClicked {
                            println("Quit Kotlin GTK!")
                            this@createWindow.destroy()
                        }
                    }
                    button {
                        label = "File Manager"
                        onClicked {
                            fileManager().showAll()
                        }
                    }
                }
m

Miroslav Sobotka

10/21/2020, 4:41 PM
Cool, you're right, it looks pretty good. Btw do you know this project? https://github.com/kavanmevada/kotlin-native-gtk-linux
m

Marshall

10/21/2020, 4:43 PM
yeah I was looking at it earlier today
it uses the gtk c interface directly, the kotlin-native-gtk library gives you the easier to use kotlin DSL
m

Miroslav Sobotka

10/21/2020, 4:49 PM
I agree. A pretty DSL and/or UI file and binding only. This is the goals of mine. But still, one more problem: threads and async. Again in my example project, I don't know how to do async I/O operations without crashing (because of the freezed object) 😁
m

Marshall

10/21/2020, 4:52 PM
Most GUIs require you to update the GUI in the main thread so your other threads have to push any data to the GUI thread, but I'm sure how you do that is highly specific to each GUI framework
b

bjonnh

10/22/2020, 8:17 PM
this is cool!
m

Marshall

10/22/2020, 8:21 PM
It's really promising
b

bjonnh

10/22/2020, 8:28 PM
I didn't manage to build the kavanmevada project
Copy code
A problem occurred evaluating root project 'weather'.
> Could not create task ':cinteropLibgtk3Linux'.
   > Could not create task of type 'CInteropProcess'.
      > 'org.gradle.api.file.RegularFileProperty org.jetbrains.kotlin.gradle.tasks.CInteropProcess.newOutputFile()'
m

Marshall

10/22/2020, 8:29 PM
yeah I'm not sure about that project, what you want is this: https://github.com/kropp/kotlin-native-gtk
although you should clone the forked version that has a number of updates
it only builds on linux at the moment
b

bjonnh

10/22/2020, 8:30 PM
will have to redo the work for GTK4 soon 😉
m

Marshall

10/22/2020, 8:30 PM
I may take a stab at updating it for other platforms just to see if/how well it works
only if you really really need GTK4
b

bjonnh

10/22/2020, 8:31 PM
when is GTK3 going to be deprecated?
m

Marshall

10/22/2020, 8:33 PM
¯\_(ツ)_/¯
b

bjonnh

10/22/2020, 8:41 PM
building
wow building times are pretty long
m

Marshall

10/22/2020, 8:44 PM
yep, it is faster if you update the kotlin version to 1.4.10
b

bjonnh

10/22/2020, 8:44 PM
42s for the sample. That machine compile a linux kernel in <=2min
m

Marshall

10/22/2020, 8:44 PM
but if you already started it will take longer to restart 😛
b

bjonnh

10/22/2020, 8:44 PM
yes I moved everything to 1.4.10
it refused to compile at all without that
had to upgrade gradle as well
m

Marshall

10/22/2020, 8:45 PM
right, need at least gradle 6
b

bjonnh

10/22/2020, 8:45 PM
oh my ❤️ an application that starts in milliseconds
m

Marshall

10/22/2020, 8:46 PM
I would update and make a PR but dude never accepted the one from drieks
b

bjonnh

10/22/2020, 8:46 PM
well that would require a new project …
m

Marshall

10/22/2020, 8:47 PM
only a couple MB executable as well and runs fast
b

bjonnh

10/22/2020, 8:47 PM
oh that was my next step to look at
m

Marshall

10/22/2020, 8:48 PM
what linux system did you build it on? I had to edit the include path to get it to build on kubuntu 20.04
b

bjonnh

10/22/2020, 8:48 PM
archlinux
I had to add harfbuzz include
m

Marshall

10/22/2020, 8:48 PM
yeah same here
b

bjonnh

10/22/2020, 8:48 PM
do you know what those generated kotlin files are?
what is making them?
m

Marshall

10/22/2020, 8:49 PM
yeah
its the code in the kngtk-generator
it reads the GIR XML and generates the kotlin code from it
b

bjonnh

10/22/2020, 8:49 PM
neat
m

Marshall

10/22/2020, 8:50 PM
yeah works pretty well as far as I can tell
b

bjonnh

10/22/2020, 8:51 PM
below 2MB if you strip the binary
m

Marshall

10/22/2020, 8:51 PM
of course, that's what GIR was made for I think, to help other languages create bindings
b

bjonnh

10/22/2020, 8:52 PM
that's a lot of moving pieces
m

Marshall

10/22/2020, 8:55 PM
it's just projects that have used GIR so other languages can use GTK
this project should be on the list
b

bjonnh

10/22/2020, 8:59 PM
yes yes
I was talking about what is necessary to get gtk running on kotlin native
m

Marshall

10/22/2020, 9:00 PM
ah
it didn't look too bad to me
The CInterop allows using the GTK c interfaces
then the kotlin-native-gtk project made it easier to use
using straight GTK from CInterop is ugly
44 Views