Made the entry field add when pressing enter, and made the whole thing a little less ugly

This commit is contained in:
Emin Arslan 2025-01-17 22:55:25 +03:00
parent ce586f88ed
commit e4a32c0ca2

View File

@ -22,36 +22,46 @@
(gtk-widget-show-all row)
row))
(defmacro within-box (window orientation &body body)
(let ((boxsym (gensym)))
`(let ((,boxsym (gtk-box-new ,orientation 5)))
,@(mapcar (lambda (x) (list 'gtk-box-pack-start boxsym x))
body)
(gtk-container-add ,window ,boxsym)
,boxsym)))
(defun my-app ()
(within-main-loop
(let ((win (gtk-window-new :toplevel)))
(let ((win (make-instance 'gtk-window
:type :toplevel
:border-width 6
:default-width 200
:default-height 600
)))
(g-signal-connect win "destroy" (lambda (widget) widget (leave-gtk-main)))
(let ((completed (gtk-list-box-new))
(let ((frame (make-instance 'gtk-frame :label "Todo" :shadow-type :etched-in))
(box (make-instance 'gtk-box :orientation :vertical :spacing 6
:homogeneous nil))
(completed (gtk-list-box-new))
(todo (gtk-list-box-new))
(add-button (gtk-button-new-with-label "Add"))
(entry (gtk-entry-new)))
(g-signal-connect add-button "clicked"
(lambda (widget)
(declare (ignore widget))
(gtk-list-box-prepend todo
(make-todo-item
(gtk-entry-text entry)
completed
todo))
(gtk-container-add todo
(make-todo-item
(gtk-entry-text entry)
completed
todo))
(setf (gtk-entry-text entry) "")))
(within-box win :vertical
(gtk-label-new "Completed tasks:")
completed
(gtk-label-new "TODO:")
todo
entry
add-button))
(g-signal-connect entry "activate"
(lambda (widget)
(gtk-container-add todo
(make-todo-item
(gtk-entry-text widget)
completed todo))
(setf (gtk-entry-text widget) "")))
(gtk-box-pack-start box (gtk-label-new "Completed:") :expand nil :fill nil)
(gtk-box-pack-start box completed :expand nil :fill nil)
(gtk-box-pack-start box (gtk-label-new "Todo:") :expand nil :fill nil)
(gtk-box-pack-start box todo :expand t :fill t)
(gtk-box-pack-start box entry :expand nil :fill nil)
(gtk-box-pack-start box add-button :expand nil :fill nil)
(gtk-container-add frame box)
(gtk-container-add win frame)
)
(gtk-widget-show-all win))))