(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 record-variants) (import (s9fes char-canvas) (s9fes char-canvas rect) (s9fes char-canvas shape shape)) (include-relative "s9fes.char-canvas.types") (include-relative "s9fes.char-canvas.inlines") (: real-shape-hgroup (#!rest real-shape-plotter -> real-shape-plotter)) (: shape-hgroup (#!rest shape-plotter -> shape-plotter)) ;; Private (define (*info-elements info) (the (list-of shape-plotter) (@info 0 info))) (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 #!rest shps) #!optional cv x0 y0) (if cv (begin (*canvas-draw-hgroup cv x0 y0 shps) cv ) (^real-info hgroup shps) ) ) ;; (define ((shape-hgroup #!rest shps) #!optional cv x0 y0) (if cv (begin (*canvas-plot-hgroup cv x0 y0 shps) cv ) (^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) ;FIXME ;descendents collect minium size - tree walk ;calc available size = bb - minimum size ;descendents distribute available size - tree walk shp ) (define (class-shape-justified? shp info) ;FIXME (let loop ((shps (*info-elements info))) (or (null? shps) (let ((shp (car shps))) (and (shape-justified? shp) (loop (cdr shps))) ) ) ) #f ) (register-shape-method 'hgroup 'size class-shape-size) (register-shape-method 'hgroup 'cardinality (lambda (shp info) (vector-length (@info 0 info)))) (register-shape-method 'hgroup 'elements (lambda (shp info) (@info 0 info))) (register-shape-method 'hgroup 'layout class-shape-layout) (register-shape-method 'hgroup 'justified? class-shape-justified?) ) ;module (s9fes char-canvas shape hgroup)