Changeset main,57 for main


Ignore:
Timestamp:
11/16/2007 05:02:49 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071116170249-94hz80fpsdchxhwp
Message:

Moved header-columns into the data model.

Location:
main/grid
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/grid/display.lisp

    r56 r57  
    55(defclass grid ()
    66  ((data :initarg :data)
    7    (header-columns :type (integer 0) :initarg :header-columns)
    87   (window :initarg :window)
    98   (row-scroll :type (integer 0) :initform 0 :accessor row-scroll)
    109   (column-scroll :type (integer 0) :initform 0 :accessor column-scroll)))
    1110
    12 (defun make-grid (window data &key (header-columns 0))
     11(defun make-grid (window data)
    1312  (make-instance 'grid
    1413                 :data data
    15                  :header-columns header-columns
    1614                 :window window))
    1715
     
    3230
    3331(defun column-split (grid column)
    34   (with-slots (header-columns) grid
    35     (saturate header-columns column)))
     32  (with-slots (data) grid
     33    (saturate (header-columns data) column)))
    3634
    3735(defun column-offset (grid column)
    38   (with-slots (data header-columns column-scroll) grid
    39     (let ((base (+ header-columns column-scroll))
    40           (column-widths (mapcar (peval 'column-width data)
    41                                  (range header-columns))))
    42       (multiple-value-bind (in-header in-data) (column-split grid column)
    43         (let ((w1 (reduce '+ column-widths :end in-header))
    44               (w2 (reduce '+ column-widths :start base
    45                                            :end (+ base in-data))))
    46           (+ w1 w2))))))
     36  (with-slots (data column-scroll) grid
     37    (let ((header-columns (header-columns data)))
     38      (let ((base (+ header-columns column-scroll))
     39            (column-widths (mapcar (peval 'column-width data)
     40                                   (range header-columns))))
     41        (multiple-value-bind (in-header in-data) (column-split grid column)
     42          (let ((w1 (reduce '+ column-widths :end in-header))
     43                (w2 (reduce '+ column-widths :start base
     44                                             :end (+ base in-data))))
     45            (+ w1 w2)))))))
    4746
    4847(defun row-split (grid row)
     
    9695
    9796(defun draw (grid)
    98   (with-slots (data header-columns window column-scroll) grid
    99     (erase window)
    100     (let ((x 0))
    101       (dotimes (i header-columns)
    102         (draw-column grid i x)
    103         (incf x (column-width data i)))
    104       (do ((i (+ header-columns column-scroll) (incf i)))
    105           ((or (>= i (columns data))
    106                (> x (nth-value 1 (size window)))))
    107         (draw-column grid i x)
    108         (incf x (column-width data i))))))
     97  (with-slots (data window column-scroll) grid
     98    (let ((header-columns (header-columns data)))
     99      (erase window)
     100      (let ((x 0))
     101        (dotimes (i header-columns)
     102          (draw-column grid i x)
     103          (incf x (column-width data i)))
     104        (do ((i (+ header-columns column-scroll) (incf i)))
     105            ((or (>= i (columns data))
     106                 (> x (nth-value 1 (size window)))))
     107          (draw-column grid i x)
     108          (incf x (column-width data i)))))))
    109109
    110110
     
    121121
    122122(defmethod max-column-scroll ((grid grid))
    123   (with-slots (data header-columns window) grid
    124     (- (columns data) header-columns 1)))
     123  (with-slots (data window) grid
     124    (- (columns data) (header-columns data) 1)))
    125125
    126126(defmethod (setf column-scroll) :around (i (grid grid))
  • main/grid/model.lisp

    r56 r57  
    1818   "Returns the number of columns of data."))
    1919
    20 #|(defgeneric header-columns (grid-data)
     20(defgeneric header-columns (grid-data)
    2121  (:documentation
    2222   "Returns the number of columns that contain header data, and may be
    2323considered for locking in place during scrolling operations.  Header
    2424columns are always at the left of the grid (from column 0).")
    25   (:method (grid-data) 0))|#
     25  (:method (grid-data) 0))
    2626
    2727(defgeneric column-width (grid-data column)
  • main/grid/package.lisp

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

    r56 r57  
    1515
    1616(defmethod columns ((gd test)) 10)
     17
     18(defmethod header-columns ((gd test))
     19  1)
    1720
    1821(defmethod column-width ((gd test) column)
     
    4447      (clear screen)
    4548      (with-subwindow (window screen 5 16 0 0)
    46         (let ((grid (make-grid window data :header-columns 1)))
     49        (let ((grid (make-grid window data)))
    4750          (flet ((try (i)
    4851                   (setf (row-scroll grid) i)
     
    6063            (try 99))))
    6164      (clear screen)
    62       (let ((grid (make-grid screen data :header-columns 1)))
     65      (let ((grid (make-grid screen data)))
    6366        (draw grid)
    6467        (read-key screen)))))
Note: See TracChangeset for help on using the changeset viewer.