diff --git a/collects/mrlib/aligned-pasteboard.ss b/collects/mrlib/aligned-pasteboard.ss index 69aa8b17..93ddfcbd 100644 --- a/collects/mrlib/aligned-pasteboard.ss +++ b/collects/mrlib/aligned-pasteboard.ss @@ -10,4 +10,5 @@ aligned-editor-canvas% aligned-pasteboard<%> aligned-pasteboard-parent<%> - aligned-snip<%>)) + aligned-snip<%> + aligned-snip-mixin)) diff --git a/collects/mrlib/private/aligned-pasteboard/aligned-editor-container.ss b/collects/mrlib/private/aligned-pasteboard/aligned-editor-container.ss index d0e570a0..b406a199 100644 --- a/collects/mrlib/private/aligned-pasteboard/aligned-editor-container.ss +++ b/collects/mrlib/private/aligned-pasteboard/aligned-editor-container.ss @@ -17,7 +17,8 @@ (provide aligned-editor-canvas% - aligned-editor-snip%) + aligned-editor-snip% + aligned-snip-mixin) ;; a canvas that can contain an aligned-pasteboard<%> (define aligned-editor-canvas% @@ -153,4 +154,59 @@ (super-instantiate ()) )) + + (define (aligned-snip-mixin super%) + (class* super% (aligned-snip<%>) + (inherit get-editor get-margin) + + (init + (stretchable-width true) + (stretchable-height true)) + + (field + (stretchable-width-field stretchable-width) + (stretchable-height-field stretchable-height)) + + (public (stretchable-width-method stretchable-width) + (stretchable-height-method stretchable-height)) + + ;; stretchable-width (case-> (Boolean . -> . (void)) (-> Boolean)) + ;; get or set the stretchablity of the pasteboards width + (define stretchable-width-method + (case-lambda + [(value) (set! stretchable-width-field value)] + [() stretchable-width-field])) + + ;; stretchable-height (case-> (Boolean . -> .(void)) (-> Boolean)) + ;; get or set the stretchablity of the pasteboards height + (define stretchable-height-method + (case-lambda + [(value) (set! stretchable-height-field value)] + [() stretchable-height-field])) + + ;; get-aligned-min-width (-> number?) + ;; the minimum width of the snip based on the children + (define/public (get-aligned-min-width) + (let ([left (box 0)] + [top (box 0)] + [right (box 0)] + [bottom (box 0)]) + (get-margin left top right bottom) + (+ (unbox left) (unbox right)))) + + ;; get-aligned-min-height (-> number?) + ;; the minimum height of the snip based on the children + (define/public (get-aligned-min-height) + (let ([left (box 0)] + [top (box 0)] + [right (box 0)] + [bottom (box 0)] + [editor (get-editor)]) + (get-margin left top right bottom) + (+ (unbox top) (unbox bottom) + (* (send editor line-location 0 false) + (add1 (send editor last-line)))))) + + (super-instantiate ()) + )) ) \ No newline at end of file diff --git a/collects/mrlib/private/aligned-pasteboard/geometry-managed-pasteboard.ss b/collects/mrlib/private/aligned-pasteboard/geometry-managed-pasteboard.ss index 400fe0ca..dda18738 100644 --- a/collects/mrlib/private/aligned-pasteboard/geometry-managed-pasteboard.ss +++ b/collects/mrlib/private/aligned-pasteboard/geometry-managed-pasteboard.ss @@ -20,11 +20,13 @@ begin-edit-sequence end-edit-sequence) (field - (alloted-width 0) - (alloted-height 0) - (aligned-min-width 0) - (aligned-min-height 0) - (aligned-rects empty)) + [needs-realign? false] + [ignore-resizing? false] + [alloted-width 0] + [alloted-height 0] + [aligned-min-width 0] + [aligned-min-height 0] + [aligned-rects empty]) ;; get-aligned-min-width (-> number?) ;; the aligned-min-width of the pasteboard @@ -47,6 +49,7 @@ [() (when (and (positive? alloted-width) (positive? alloted-height)) + (set! needs-realign? false) (realign-to-alloted))])) ;; realign-to-alloted (-> void?) @@ -57,14 +60,18 @@ (align type alloted-width alloted-height (map-snip build-rect first-snip))) (begin-edit-sequence) + (set! ignore-resizing? true) (for-each-snip move/resize first-snip aligned-rects) + (set! ignore-resizing? false) (end-edit-sequence))) ;; set-algined-min-sizes (-> void?) ;; set the aligned min width and height of the pasteboard based on it's children snips (define/public (set-aligned-min-sizes) + (set! ignore-resizing? true) (set!-values (aligned-min-width aligned-min-height) - (get-aligned-min-sizes type (find-first-snip)))) + (get-aligned-min-sizes type (find-first-snip))) + (set! ignore-resizing? false)) ;;move/resize (snip-pos? rect? . -> . void?) ;;moves and resizes the snips with in pasteboard diff --git a/collects/mrlib/private/aligned-pasteboard/snip-lib.ss b/collects/mrlib/private/aligned-pasteboard/snip-lib.ss index 9972d2eb..ed700ef6 100644 --- a/collects/mrlib/private/aligned-pasteboard/snip-lib.ss +++ b/collects/mrlib/private/aligned-pasteboard/snip-lib.ss @@ -20,6 +20,8 @@ (define editor? (is-a?/c editor<%>)) (provide/contract + (snip-width (snip? . -> . number?)) + (snip-height (snip? . -> . number?)) (snip-min-width (snip? . -> . number?)) (snip-min-height (snip? . -> . number?)) (snip-parent (snip? . -> . editor?)) @@ -30,7 +32,6 @@ (stretchable-height? (snip? . -> . boolean?))) ;; the width of a snip in the parent pasteboard - ;; snip-width (snip? . -> . number?) (define (snip-width snip) (let ([left (box 0)] [right (box 0)] @@ -40,7 +41,6 @@ (- (unbox right) (unbox left)))) ;; the height of a snip in the parent pasteboard - ;; snip-height (snip? . -> . number?) (define (snip-height snip) (let ([top (box 0)] [bottom (box 0)]