(require :cells)
(require :cells-gtk)

(in-package :cl-user)

(defpackage :gtk-add
  (:use :common-lisp :cells :cells-gtk)
  (:export :start-add))

(in-package :gtk-add)

(defun add-numbers (a b)
  (let ((str (concatenate 'string
                          "A + B = "
                          (format nil "~d" (+ (parse-integer a)
                                              (parse-integer b))))))
    (show-message str :title "Solution")))

(defmodel gtk-add (gtk-app)
  ()
  (:default-initargs
      :title "Gtk Add" :position :center
      :kids
      (list
       (mk-vbox
        :kids
        (list
         (mk-hbox
          :kids
          (list
           (mk-label :text "A =")
           (mk-entry :expand t :fill t :md-name :entry-a
                     :init "0" :auto-aupdate t)))
         (mk-hbox
          :kids
          (list
           (mk-label :text "B =")
           (mk-entry :expand t :fill t :md-name :entry-b
                     :init "0" :auto-aupdate t)))
         (mk-button :label "Add" :expand t :fill t
                    :on-clicked (callback (widget event data)
                                  (let ((a (md-value (fm-other :entry-a)))
                                        (b (md-value (fm-other :entry-b))))
                                    (add-numbers a b)))))))))

(defun start-add ()
  (cells-gtk-init)
  (start-app 'gtk-add))