2022-06-14 02:26:03 +00:00
|
|
|
# :lazy true needed for jpm quickbin
|
|
|
|
# lazily loads library on first function use
|
|
|
|
# so the `main` function
|
|
|
|
# can be marshalled.
|
|
|
|
(ffi/context "/usr/lib/libgtk-3.so" :lazy true)
|
2022-06-12 23:48:47 +00:00
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-application-new :ptr
|
|
|
|
"Add docstrings as needed."
|
|
|
|
[a :ptr b :uint])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
g-signal-connect-data :ulong
|
|
|
|
[a :ptr b :ptr c :ptr d :ptr e :ptr f :int])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
g-application-run :int
|
|
|
|
[a :ptr b :int c :ptr])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-application-window-new :ptr
|
|
|
|
[a :ptr])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-button-new-with-label :ptr
|
|
|
|
[a :ptr])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-container-add :void
|
|
|
|
[a :ptr b :ptr])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-widget-show-all :void
|
|
|
|
[a :ptr])
|
|
|
|
|
|
|
|
(ffi/defbind
|
|
|
|
gtk-button-set-label :void
|
|
|
|
[a :ptr b :ptr])
|
|
|
|
|
2022-06-14 02:26:03 +00:00
|
|
|
(def cb (delay (ffi/trampoline :default)))
|
2022-06-12 23:48:47 +00:00
|
|
|
|
|
|
|
(defn on-active
|
|
|
|
[app]
|
|
|
|
(def window (gtk-application-window-new app))
|
|
|
|
(def btn (gtk-button-new-with-label "Click Me!"))
|
2022-06-14 02:26:03 +00:00
|
|
|
(g-signal-connect-data btn "clicked" (cb)
|
2022-06-12 23:48:47 +00:00
|
|
|
(fn [btn] (gtk-button-set-label btn "Hello World"))
|
|
|
|
nil 1)
|
|
|
|
(gtk-container-add window btn)
|
|
|
|
(gtk-widget-show-all window))
|
|
|
|
|
|
|
|
(defn main
|
|
|
|
[&]
|
|
|
|
(def app (gtk-application-new "org.janet-lang.example.HelloApp" 0))
|
2022-06-14 02:26:03 +00:00
|
|
|
(g-signal-connect-data app "activate" (cb) on-active nil 1)
|
2022-06-12 23:48:47 +00:00
|
|
|
(g-application-run app 0 nil))
|