Closed apr3vau closed 4 months ago
For example, some dialog classes and methods seem missing or being mapped to different names compared to official document, like Adw.AlertDialog (the adw:message-dialog seems the identical one), the constructor function of AlertDialog (there isn't a
make-alert-dialog
in my environment...), and present functions likeadw_dialog_present
(But it works well by just usingwindow-present
).
Both AlertDialog
and Dialog
are only available in libadwaita
versions higher than 1.5, but most distributions currently offer versions lower than that.
I can't make it works, the user_data argument cannot automatically convert to correct pointer type, and the application will get stuck while running the callback.
The last 2 parameters should be given as CFFI callback and pointer, like:
(adw:message-dialog-choose dialog nil (cffi:callback foo) (cffi:null-pointer))
It seems this pattern is quite common in libadwaita
, so I will develop a pattern for passing Lisp closures to such functions later on. Actually, similar functionality already exists in my glib
bindings, but I haven't exposed it yet.
Most callbacks in GTK4 are implemented through signals, and AdwMessageDialog
also provides a response
signal. Perhaps at this stage, you could try going forward using signals:
(in-package #:gtk4.example)
(define-application (:name message-dialog-test
:id "org.bohonghuang.gtk4-example.message-dialog-test")
(define-main-window (window (make-application-window :application *application*))
(adw:init)
(setf (window-title window) "Message Dialog Test")
(let ((box (make-box :orientation +orientation-vertical+ :spacing 4)))
(let ((button (make-button :label "Show Message Dialog")))
(connect button "clicked" (lambda (button)
(let ((dialog (adw:make-message-dialog :parent window :heading "Test Message" :body "Test Message Body")))
(adw:message-dialog-add-response dialog "cancel" "Cancel")
(adw:message-dialog-add-response dialog "ok" "OK")
(connect dialog "response" (lambda (dialog respose)
(declare (ignore dialog))
(alexandria:eswitch (respose :test #'string=)
("ok" (setf (widget-sensitive-p button) nil))
("cancel"))))
(window-present dialog))))
(box-append box button))
(setf (window-child window) box))
(unless (widget-visible-p window)
(window-present window))))
My environment is CCL (due to unsolvable floating points error under SBCL), Windows11 with msys.
Just quickload float-features
and:
(float-features:with-float-traps-masked t (run-your-application))
Thank you, your explanations really save my life :D! Thanks for your effort!
I feel not easy when I trying to programming with dialogs, as the usual conversion rules seems not really adaptable...
For example, some dialog classes and methods seem missing or being mapped to different names compared to official document, like Adw.AlertDialog (the adw:message-dialog seems the identical one), the constructor function of AlertDialog (there isn't a
make-alert-dialog
in my environment...), and present functions likeadw_dialog_present
(But it works well by just usingwindow-present
). And some other essential functions are also difficult to use, like theadw:message-dialog-choose
- I can't make it works, the user_data argument cannot automatically convert to correct pointer type, and the application will get stuck while running the callback. Maybe is a multiprocessing problem, but it's difficult to find out for me as a newer in Gtk.I'm still confusing about where the problems happen, but hopefully there's always someway to suite my needs. Maybe they're my faults, but I do think things can be easier if there's a trivial example/document to demonstrate what it should be...
My environment is CCL (due to unsolvable floating points error under SBCL), Windows11 with msys.
Thanks for your efforts, and I must say that this is a really awesome and beautiful library~