Changeset main,55 for main


Ignore:
Timestamp:
11/16/2007 04:52:26 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071116165226-urvzht93m31b4n1t
Message:

Made column-widths part of the data model.

Location:
main/grid
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/grid/display.lisp

    r53 r55  
    55(defclass grid ()
    66  ((data :initarg :data)
    7    (column-widths :type (vector (integer 1)) :initarg :column-widths)
    87   (header-rows :type (integer 0) :initarg :header-rows)
    98   (header-columns :type (integer 0) :initarg :header-columns)
     
    1211   (column-scroll :type (integer 0) :initform 0 :accessor column-scroll)))
    1312
    14 (defun make-grid (window data column-widths
    15                   &key (header-rows 0) (header-columns 0))
     13(defun make-grid (window data &key (header-rows 0) (header-columns 0))
    1614  (make-instance 'grid
    1715                 :data data
    18                  :column-widths (coerce column-widths 'vector)
    1916                 :header-rows header-rows
    2017                 :header-columns header-columns
     
    4138
    4239(defun column-offset (grid column)
    43   (with-slots (column-widths header-columns column-scroll) grid
    44     (let ((base (+ header-columns column-scroll)))
     40  (with-slots (data header-columns column-scroll) grid
     41    (let ((base (+ header-columns column-scroll))
     42          (column-widths (mapcar (peval 'column-width data)
     43                                 (range header-columns))))
    4544      (multiple-value-bind (in-header in-data) (column-split grid column)
    4645        (let ((w1 (reduce '+ column-widths :end in-header))
     
    9998
    10099(defun draw (grid)
    101   (with-slots (data column-widths header-columns window column-scroll) grid
     100  (with-slots (data header-columns window column-scroll) grid
    102101    (erase window)
    103102    (let ((x 0))
    104103      (dotimes (i header-columns)
    105104        (draw-column grid i x)
    106         (incf x (svref column-widths i)))
     105        (incf x (column-width data i)))
    107106      (do ((i (+ header-columns column-scroll) (incf i)))
    108107          ((or (>= i (columns data))
    109108               (> x (nth-value 1 (size window)))))
    110109        (draw-column grid i x)
    111         (incf x (svref column-widths i))))))
     110        (incf x (column-width data i))))))
    112111
    113112
  • main/grid/model.lisp

    r26 r55  
    22
    33
     4
     5(defgeneric rows (grid-data)
     6  (:documentation
     7   "Returns the number of rows of data."))
    48
    59#|(defgeneric header-rows (grid-data)
     
    1014  (:method (grid-data) 0))|#
    1115
     16(defgeneric columns (grid-data)
     17  (:documentation
     18   "Returns the number of columns of data."))
     19
    1220#|(defgeneric header-columns (grid-data)
    1321  (:documentation
     
    1725  (:method (grid-data) 0))|#
    1826
    19 #|(defgeneric column-width (grid-data column)
     27(defgeneric column-width (grid-data column)
    2028  (:documentation
    2129   "Returns the width of the column, as the total number of characters
    2230requested for this column.  The count may be less than the length of
    23 the maximal item in the column."))|#
    24 
    25 (defgeneric rows (grid-data)
    26   (:documentation
    27    "Returns the number of rows of data."))
    28 
    29 (defgeneric columns (grid-data)
    30   (:documentation
    31    "Returns the number of columns of data."))
     31the maximal item in the column."))
    3232
    3333(defgeneric item (grid-data row column)
  • main/grid/package.lisp

    r53 r55  
    11(defpackage #:grid
    22  (:use #:cl #:dso-util #:tui-display-string #:tui-output #:tui-window)
    3   (:export #:rows #:columns #:item #:uses-display-strings #:row-scroll
    4            #:column-scroll #:make-grid #:draw))
     3  (:export #:rows #:columns #:column-width #:item #:uses-display-strings
     4           #:row-scroll #:column-scroll #:make-grid #:draw))
  • main/grid/test.lisp

    r53 r55  
    1212
    1313(defmethod columns ((gd test)) 10)
     14
     15(defmethod column-width ((gd test) column)
     16  5)
    1417
    1518(defmethod item ((gd test) row column)
     
    3437
    3538(defun test-draw ()
    36   (let ((data (make-instance 'test))
    37         (widths (make-sequence 'vector 10 :initial-element 5)))
     39  (let ((data (make-instance 'test)))
    3840    (with-screen (screen)
    3941      (clear screen)
    4042      (with-subwindow (window screen 5 16 0 0)
    41         (let ((grid (make-grid window data widths :header-columns 1 :header-rows 1)))
     43        (let ((grid (make-grid window data :header-columns 1 :header-rows 1)))
    4244          (flet ((try (i)
    4345                   (setf (row-scroll grid) i)
     
    5557            (try 99))))
    5658      (clear screen)
    57       (let ((grid (make-grid screen data widths :header-columns 1 :header-rows 1)))
     59      (let ((grid (make-grid screen data :header-columns 1 :header-rows 1)))
    5860        (draw grid)
    5961        (read-key screen)))))
Note: See TracChangeset for help on using the changeset viewer.