Changeset main,46 for main


Ignore:
Timestamp:
11/12/2007 07:08:49 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@tux-20071112190849-f4iha3mmvx2nskce
Message:

Textboxes and numberboxes now change colors.

Location:
main/widget
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/widget/generic.lisp

    r45 r46  
    11(defpackage #:tui-widget-generic
    22  (:use #:cl)
    3   (:export #:text #:widget #:parent-window #:column #:row #:scroll
    4            #:insertion-point #:destroy #:draw #:activate))
     3  (:export #:text #:widget #:parent-window #:column #:row #:inactive-background
     4           #:active-background #:scroll #:insertion-point #:destroy #:draw
     5           #:activate))
    56
    67(in-package #:tui-widget-generic)
     
    2324  ((parent-window :initarg :parent-window)
    2425   (column :type (integer 0) :initarg :column)
    25    (row :type (integer 0) :initarg :row)))
     26   (row :type (integer 0) :initarg :row)
     27   ;; TODO: initform for bg-color
     28   (inactive-background :initarg :inactive-background)
     29   (active-background :initarg :active-background)))
    2630
    2731(defclass scroll ()
  • main/widget/label.lisp

    r45 r46  
    3030
    3131(defmethod activate ((label label) &optional callback)
     32  (declare (ignore callback))
    3233  #\Tab)
  • main/widget/numberbox-test.lisp

    r40 r46  
    1212
    1313
     14(defun create-nb (window row name)
     15  (create-numberbox window row 10 name 10
     16                    :inactive-background '(#\Space 60)
     17                    :active-background '(#\Space 57)))
     18
    1419(defun test ()
    1520  (with-screen (s)
     
    1722           (data2 (make-instance 'data))
    1823           (data3 (make-instance 'data))
    19            (nbs (list (create-numberbox s 10 10 data1 10)
    20                       (create-numberbox s 11 10 data2 10)
    21                       (create-numberbox s 12 10 data3 10))))
     24           (nbs (list (create-nb s 10 data1)
     25                      (create-nb s 11 data2)
     26                      (create-nb s 12 data3))))
    2227      (setf (cdddr nbs) nbs)
    2328      (refresh s)
  • main/widget/numberbox.lisp

    r40 r46  
    3232    (setf (text data) s)))
    3333
    34 (defun create-numberbox (parent-window y x data width)
     34(defun create-numberbox (parent-window y x data width &key
     35                         (inactive-background '(#\Space 0))
     36                         (active-background '(#\Space 0)))
    3537  (let* ((data-wrapper (make-instance 'numberbox-data :data data :width width))
    36          (textbox (create-textbox parent-window y x data-wrapper width)))
     38         (textbox (create-textbox parent-window y x data-wrapper width
     39                                  :inactive-background inactive-background
     40                                  :active-background active-background)))
    3741    (change-class textbox 'numberbox)))
    3842
  • main/widget/textbox-test.lisp

    r40 r46  
    1414  (with-screen (s)
    1515    (let* ((data (make-instance 'data))
    16            (tb (create-textbox s 10 10 data 8)))
     16           (tb (create-textbox s 10 10 data 8
     17                               :active-background '(#\Space 60))))
    1718      (unwind-protect
    1819           (flet ((cb (key)
  • main/widget/textbox.lisp

    r44 r46  
    1010(defclass textbox (widget scroll insertion-point)
    1111  ((data :initarg :data)
    12    (window :initarg :window)))
     12   (window :initarg :window)
     13   (active :type boolean :initform nil)))
    1314
    1415
     
    2829
    2930(defmethod draw ((textbox textbox))
    30   (with-slots (data window scroll) textbox
     31  (with-slots (data window scroll inactive-background active-background active)
     32      textbox
     33    (setf (background window) (if active
     34                                  active-background
     35                                  inactive-background))
    3136    (erase window)
    3237    (add-clipped-string window 0 (- scroll) (text data))
     
    5863
    5964
    60 (defun create-textbox (parent-window y x data width)
     65(defun create-textbox (parent-window y x data width &key
     66                       (inactive-background '(#\Space 0))
     67                       (active-background '(#\Space 0)))
    6168  (let* ((window (tui-window::create-subwindow parent-window 1 width y x))
    62          (inst (make-instance 'textbox :data data :window window)))
     69         (inst (make-instance 'textbox
     70                              :data data
     71                              :window window
     72                              :inactive-background inactive-background
     73                              :active-background active-background)))
    6374    (draw inst)
    6475    inst))
     
    7990
    8091(defmethod activate ((textbox textbox) &optional (callback 'nothing))
    81   (with-slots (data window) textbox
    82     (cdk::c-keypad (window-pointer window) t)
    83     (setf (insertion-point textbox) :end)
    84     (loop
    85        (let ((key (read-key window)))
    86          (case key
    87            (:key-left (decf (insertion-point textbox)))
    88            (:key-right (incf (insertion-point textbox)))
    89            (:key-home (setf (insertion-point textbox) 0))
    90            (:key-end (setf (insertion-point textbox) :end))
    91            (:key-backspace
    92             (multiple-value-bind (left right) (split textbox)
    93               (when (string/= left "")
    94                 (setf left (subseq left 0 (1- (length left))))
    95                 (setf (text data) (concatenate 'string left right))
    96                 (decf (insertion-point textbox)))))
    97            (:key-dc
    98             (multiple-value-bind (left right) (split textbox)
    99               (when (string/= right "")
    100                 (setf right (subseq right 1))
    101                 (setf (text data) (concatenate 'string left right))
    102                 (setf (insertion-point textbox) (insertion-point textbox)))))
    103            (t
    104             (if (or (keywordp key)
    105                     (member key '(#\Return #\Newline #\Tab #\Esc)))
    106                 (let ((r (funcall callback key)))
    107                   (when r
    108                     (setf (insertion-point textbox) 0)
    109                     (return-from activate r)))
    110                 (multiple-value-bind (left right) (split textbox)
    111                   (setf (text data)
    112                         (concatenate 'string left (string key) right))
    113                   (incf (insertion-point textbox))))))))))
     92  (with-slots (data window active) textbox
     93    (setf active t)
     94    (unwind-protect
     95         (progn
     96           (cdk::c-keypad (window-pointer window) t)
     97           (setf (insertion-point textbox) :end)
     98           (loop
     99              (let ((key (read-key window)))
     100                (case key
     101                  (:key-left (decf (insertion-point textbox)))
     102                  (:key-right (incf (insertion-point textbox)))
     103                  (:key-home (setf (insertion-point textbox) 0))
     104                  (:key-end (setf (insertion-point textbox) :end))
     105                  (:key-backspace
     106                   (multiple-value-bind (left right) (split textbox)
     107                     (when (string/= left "")
     108                       (setf left (subseq left 0 (1- (length left))))
     109                       (setf (text data) (concatenate 'string left right))
     110                       (decf (insertion-point textbox)))))
     111                  (:key-dc
     112                   (multiple-value-bind (left right) (split textbox)
     113                     (when (string/= right "")
     114                       (setf right (subseq right 1))
     115                       (setf (text data) (concatenate 'string left right))
     116                       (setf (insertion-point textbox)
     117                             (insertion-point textbox)))))
     118                  (t
     119                   (if (or (keywordp key)
     120                           (member key '(#\Return #\Newline #\Tab #\Esc)))
     121                       (let ((r (funcall callback key)))
     122                         (when r
     123                           (setf (insertion-point textbox) 0)
     124                           (return-from activate r)))
     125                       (multiple-value-bind (left right) (split textbox)
     126                         (setf (text data)
     127                               (concatenate 'string left (string key) right))
     128                         (incf (insertion-point textbox)))))))))
     129      (setf active nil))))
Note: See TracChangeset for help on using the changeset viewer.