- Timestamp:
- 11/16/2007 04:52:26 PM (19 years ago)
- branch-nick:
- tui
- revision id:
- dsowen@fugue88.ws-20071116165226-urvzht93m31b4n1t
- Location:
- main/grid
- Files:
-
- 4 edited
-
display.lisp (modified) (4 diffs)
-
model.lisp (modified) (3 diffs)
-
package.lisp (modified) (1 diff)
-
test.lisp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
main/grid/display.lisp
r53 r55 5 5 (defclass grid () 6 6 ((data :initarg :data) 7 (column-widths :type (vector (integer 1)) :initarg :column-widths)8 7 (header-rows :type (integer 0) :initarg :header-rows) 9 8 (header-columns :type (integer 0) :initarg :header-columns) … … 12 11 (column-scroll :type (integer 0) :initform 0 :accessor column-scroll))) 13 12 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)) 16 14 (make-instance 'grid 17 15 :data data 18 :column-widths (coerce column-widths 'vector)19 16 :header-rows header-rows 20 17 :header-columns header-columns … … 41 38 42 39 (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)))) 45 44 (multiple-value-bind (in-header in-data) (column-split grid column) 46 45 (let ((w1 (reduce '+ column-widths :end in-header)) … … 99 98 100 99 (defun draw (grid) 101 (with-slots (data column-widthsheader-columns window column-scroll) grid100 (with-slots (data header-columns window column-scroll) grid 102 101 (erase window) 103 102 (let ((x 0)) 104 103 (dotimes (i header-columns) 105 104 (draw-column grid i x) 106 (incf x ( svref column-widthsi)))105 (incf x (column-width data i))) 107 106 (do ((i (+ header-columns column-scroll) (incf i))) 108 107 ((or (>= i (columns data)) 109 108 (> x (nth-value 1 (size window))))) 110 109 (draw-column grid i x) 111 (incf x ( svref column-widthsi))))))110 (incf x (column-width data i)))))) 112 111 113 112 -
main/grid/model.lisp
r26 r55 2 2 3 3 4 5 (defgeneric rows (grid-data) 6 (:documentation 7 "Returns the number of rows of data.")) 4 8 5 9 #|(defgeneric header-rows (grid-data) … … 10 14 (:method (grid-data) 0))|# 11 15 16 (defgeneric columns (grid-data) 17 (:documentation 18 "Returns the number of columns of data.")) 19 12 20 #|(defgeneric header-columns (grid-data) 13 21 (:documentation … … 17 25 (:method (grid-data) 0))|# 18 26 19 #|(defgeneric column-width (grid-data column)27 (defgeneric column-width (grid-data column) 20 28 (:documentation 21 29 "Returns the width of the column, as the total number of characters 22 30 requested 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.")) 31 the maximal item in the column.")) 32 32 33 33 (defgeneric item (grid-data row column) -
main/grid/package.lisp
r53 r55 1 1 (defpackage #:grid 2 2 (:use #:cl #:dso-util #:tui-display-string #:tui-output #:tui-window) 3 (:export #:rows #:columns #: item #:uses-display-strings #:row-scroll4 #: 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 12 12 13 13 (defmethod columns ((gd test)) 10) 14 15 (defmethod column-width ((gd test) column) 16 5) 14 17 15 18 (defmethod item ((gd test) row column) … … 34 37 35 38 (defun test-draw () 36 (let ((data (make-instance 'test)) 37 (widths (make-sequence 'vector 10 :initial-element 5))) 39 (let ((data (make-instance 'test))) 38 40 (with-screen (screen) 39 41 (clear screen) 40 42 (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))) 42 44 (flet ((try (i) 43 45 (setf (row-scroll grid) i) … … 55 57 (try 99)))) 56 58 (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))) 58 60 (draw grid) 59 61 (read-key screen)))))
Note: See TracChangeset
for help on using the changeset viewer.
