stretchable-snip
stretchable-editor-canvas-mixin
stretchable-editor-canvas%
stretchable<%>
hr%
stretchable-snip-mixin
new
stretchable-snip-static-mixin
canvas-client-size
7.1

stretchable-snip

Roman Klochkov <[email protected]>

 (require stretchable-snip) package: stretchable-snip

This package provides mixins to make stretchable snips. Stretchable snups have on-size method, that will be called, when the size of the canvas is changed. It can be used to implement snips, whose view depends on the size of the editor-canvas, such as horizontal rule.

All stretchable snips should implement stretchable<%> and be placed inside stretchable editor-canvas% (either stretchable-editor-canvas%, or result of stretchable-editor-canvas-mixin). To implement stretchable<%> one may use stretchable-snip-mixin or stretchable-snip-static-mixin. If you build stretchable<%>, remember, that on-size is called only when editor’s on-size is called. If your snip may be added to already shown editor, you should also override set-admin. See hr% source for example:

(define hr%
  (class* image-snip% (stretchable<%>)
    (inherit set-bitmap)
    (super-make-object (make-object bitmap% 1 1))
    (define/override (set-admin adm)
      (when adm
        (define-values (w h) (canvas-client-size (send (send adm get-editor) get-canvas)))
        (on-size w h))
      (super set-admin adm))
    (define/public (on-size w h)
      (set-bitmap (draw-line w)))))

canvas-client-size returns correct size of availaible space inside the canvas.

mixin

stretchable-editor-canvas-mixin : (class? . -> . class?)

  argument extends/implements: editor-canvas%
Returns stretchable version of its argument.

The stretchable<%> should be implemented by all snips, whose on-size method shoul be called, when editor’s size changes.

class

hr% : class?

  superclass: image-snip%

  extends: stretchable<%>
This is a snip, that display horizontal rule like <HR> tag in HTML.

mixin

stretchable-snip-mixin : (class? . -> . class?)

  argument extends/implements: snip%
Returns stretchable version of its argument with on-size argument.

constructor

(new stretchable-snip-mixin 
    [[on-size on-size]] 
    ...superclass-args...) 
  (is-a?/c stretchable-snip-mixin)
  on-size : ((is-a?/c stretchable<%>) dimension-integer? dimension-integer? . -> . any)
   = (λ (this w h) (void))
Returns snip with given on-size method

procedure

(stretchable-snip-static-mixin [call-on-size])

  (make-mixin-contract snip%)
  call-on-size : ((is-a?/c stretchable<%>) dimension-integer? dimension-integer? . -> . any)
   = (λ (this w h) (void))
Returns stretchable version of its argument with call-on-size, called from the on-size method.

Return client width and height for given canvas. Unlike get-client-size method of window<%>, canvas-client-size subtract canvas’s inset and return available to draw space.