Changeset main,80 for main/form.lisp


Ignore:
Timestamp:
12/13/2007 12:47:56 AM (18 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071213004756-lr4quvaf0hy1zpub
Message:

Widgets now support validation (#1).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/form.lisp

    r79 r80  
    5555
    5656(defun make-textbox-def (row column name display-width
    57                          &key data-width read-only (validate 'nothing)
     57                         &key data-width read-only (validator 'identity)
    5858                         (inactive-background
    5959                          *default-inactive-widget-background*)
     
    6464                  :display-width ,display-width :data-width ,data-width
    6565                  :read-only ,read-only
    66                   :validator ',validate
     66                  :validator ',validator
    6767                  :inactive-background (list ,@inactive-background)
    6868                  :active-background (list ,@active-background)))
     
    7070(defun make-numberbox-def (row column name display-width
    7171                           &key data-width precision read-only
    72                            (validate 'nothing)
     72                           (validator 'identity)
    7373                           (inactive-background
    7474                            *default-inactive-widget-background*)
     
    7979                  :display-width ,display-width :data-width ,data-width
    8080                  :precision ,precision :read-only ,read-only
    81                   :validator ',validate
     81                  :validator ',validator
    8282                  :inactive-background (list ,@inactive-background)
    8383                  :active-background (list ,@active-background)))
     
    130130        (create-label window row column text))))
    131131  (:method ((tbd textbox-def) form)
    132     (with-slots (row column name display-width inactive-background
     132    (with-slots (row column name validator display-width inactive-background
    133133                     active-background) tbd
    134134      (with-slots (data window scroll) form
    135135        (let ((r (make-reflector data name)))
    136136          (create-textbox window (- row scroll) column r display-width
     137                          :validator validator
    137138                          :inactive-background inactive-background
    138139                          :active-background active-background)))))
    139140  (:method ((nbd numberbox-def) form)
    140     (with-slots (row column name display-width inactive-background
     141    (with-slots (row column name validator display-width inactive-background
    141142                     active-background) nbd
    142143      (with-slots (data window scroll) form
    143144        (let ((r (make-reflector data name)))
    144145          (create-numberbox window (- row scroll) column r display-width
     146                            :validator validator
    145147                            :inactive-background inactive-background
    146148                            :active-background active-background))))))
     
    256258        (assert (> n 0) nil "The form has no fields.")
    257259        (labels ((f-idx () (aref focusables focus))
    258                  (f-peer () (aref peers (f-idx)))
    259                  (f-def () (aref widget-defs (f-idx)))
    260                  (validate ()
    261                    (let* ((v (slot-value (f-def) 'validator))
    262                           (name (slot-value (f-def) 'name))
    263                           (text (form-value data name))
    264                           (r (funcall v text)))
    265                      (when r
    266                        (setf (form-value data name) r)))))
     260                 (f-peer () (aref peers (f-idx))))
    267261          (loop
    268262             (ensure-widget-visible form (f-idx))
     
    271265               (case key
    272266                 ((#\Return #\Newline #\Tab :key-down)
    273                   #|(setf focus (mod (1+ focus) n))|#
    274                   (validate)
    275267                  (incf focus)
    276268                  (boundf focus 0 (1- n)))
    277269                 ((:key-btab :key-up)
    278                   #|(setf focus (mod (1- focus) n))|#
    279                   (validate)
    280270                  (decf focus)
    281271                  (boundf focus 0 (1- n)))
Note: See TracChangeset for help on using the changeset viewer.