(module (s9fes char-canvas shape hgroup) (;export ; real-shape-hgroup ; shape-hgroup) (import scheme utf8) (import (chicken base)) (import (chicken fixnum)) (import (chicken type)) (import (only (srfi 1) list-copy)) (import record-variants) (import (s9fes char-canvas) (s9fes char-canvas rect) (s9fes char-canvas shape shape) (s9fes char-canvas shape shape group)) (include-relative "s9fes.char-canvas.types") (include-relative "s9fes.char-canvas.inlines") (include-relative "s9fes.char-canvas.shape.types") (include-relative "s9fes.char-canvas.shape.inlines") ;group rest arg is (list-of shape-plotter) or (list (list-ofshape-plotter)) ;due to new group not using `apply' (: real-shape-hgroup (#!rest real-shape-plotter -> real-shape-plotter)) (: shape-hgroup (#!rest shape-plotter -> shape-plotter)) ;; Private (define-inline (%info-elements info) (the shape-plotters (@info 0 info))) (define (*new-hgroup info elms) (case (@info-coords info) ((real) (real-shape-hgroup elms)) (else (shape-hgroup elms))) ) (define (*canvas-draw-hgroup cv x0 y0 shps) ;FIXME (define (next shp x y) (receive (w h) (shape-size shp) (values (fx+ x w) y))) (let loop ((shps shps) (x x0) (y y0)) (unless (null? shps) (let ((shp (car shps))) (shp cv x y) (receive (x y) (next shp x y) (loop (cdr shps) x y) ) ) ) ) cv ) (define (*canvas-plot-hgroup cv x0 y0 shps) ;FIXME (define (next shp x y) (receive (w h) (shape-size shp) (values x (+ y h)))) (let loop ((shps shps) (x x0) (y y0)) (unless (null? shps) (let ((shp (car shps))) (shp cv x y) (receive (x y) (next shp x y) (loop (cdr shps) x y) ) ) ) ) cv ) ;; Public (define (real-shape-hgroup . args) (let ((shps (if (%length-1/kind? args list?) (car args) args))) (assert (%shapes? shps) 'real-shape-hgroup "bad argument type - not list-of shape" shps) (shape-lambda-info! (lambda (#!optional cv x0 y0) (if cv (*canvas-draw-hgroup cv x0 y0 shps) (^real-info 'hgroup shps) ) ) ) ) ) (define (shape-hgroup . args) (let ((shps (if (%length-1/kind? args list?) (car args) args))) (assert (%shapes? shps) 'shape-hgroup "bad argument type - not list-of shape" shps) (shape-lambda-info! (lambda (#!optional cv x0 y0) (if cv (*canvas-plot-hgroup cv x0 y0 shps) (^virtual-info 'hgroup shps) ) ) ) ) ) ;; (define (class-shape-size shp info) (let* ((shps (%info-elements info)) (sizs (map (lambda (shp) (receive (shape-size shp))) shps)) ) (values (apply + (map car sizs)) (apply max (map cadr sizs))) ) ) (define (class-shape-layout shp info bb parent) (receive (jshps ret-wd ret-ht) (group-layout shp (%info-elements info) bb parent (lambda (lbb) (let ((lbb-x (%rect-x lbb)) (lbb-y (%rect-y lbb)) (lbb-wd (%rect-wd lbb)) (lbb-ht (%rect-ht lbb)) ) (values (%rect lbb-x (%rect-y bb) lbb-wd (%rect-ht bb)) (+ lbb-x lbb-wd) (%rect-y bb))))) ;(print "hgroup layout res " ret-wd " " ret-ht) (if jshps (*new-hgroup info jshps) (error 'hgroup-layout "overflows bounding-box" ret-wd ret-ht bb)) ) ) (register-shape 'hgroup shape-hgroup real-shape-hgroup) (register-shape-method 'hgroup 'size class-shape-size) (register-shape-method 'hgroup 'cardinality class-group-cardinality) (register-shape-method 'hgroup 'elements class-group-elements) (register-shape-method 'hgroup 'layout class-shape-layout) (register-shape-method 'hgroup 'justified? class-group-justified?) (register-shape-method 'hgroup 'reify-args class-group-reify-args) (register-shape-method 'hgroup 'reflect class-group-reflect) ) ;module (s9fes char-canvas shape hgroup)