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.

File:
1 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))
Note: See TracChangeset for help on using the changeset viewer.