► |  | Unstable: May Change Without Warning

1 | Guidelines for Developing unstable Libraries
2 | Automata: Compiling State Machines
3 | Bytes
4 | Contracts
5 | Converting Values to Strings
6 | Contracts for Macro Subexpressions
7 | Debugging
8 | Definitions
9 | Errors
10 | Filesystem
11 | Find
12 | Flonums
13 | Futures
14 | Functions
15 | Hash Tables
16 | Interface-Oriented Programming for Classes
17 | Lazy Require
18 | Lists
19 | Logging
20 | Mark Parameters
21 | Match
22 | Open place expressions
23 | Parameter Groups
24 | Pretty-Printing
25 | Re-Contracting Identifiers
26 | Sandbox
27 | Sequences
28 | Strings
29 | Structs
30 | Struct Printing
31 | Syntax
32 | Temporal Contracts: Explicit Contract Monitors
33 | GUI Libraries

▼ | 33 | GUI Libraries

33.1 | Notify-boxes
33.2 | Preferences
33.3 | Pict Utilities
33.4 | Slideshow Presentations
33.5 | Progressive Picts and Slides
33.6 | Snip Utilities
33.7 | Scribble Utilities

On this page:

snip-canvas%
new
get-snip
on-size

Version: 5.3.1
top ← prev up next →

#### 33.6`` Snip Utilities

Neil Toronto <neil.toronto@gmail.com>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

( require unstable/gui/snip )

> class

> snip-canvas% : class?

superclass: editor-canvas%

A canvas that contains a single snip.
Snips cannot be placed directly on dialogs, frames and panels. To use an interactive snip (such as one returned by plot-snip) in a GUI, it must be inserted into an editor, which itself must be placed on a special canvas, which can be placed in a GUI container. To provide a seamless user experience, the editor should be enabled but not writable, not be able to receive focus, not have scrollbars, and other small details.
The snip-canvas% class handles these details, making it easy to use interactive snips as normal GUI elements.

> > > constructor

> > > ( new snip-canvas% |
> > > |  | [parent parent] |
> > > |  | [make-snip make-snip] |
> > > | [ | [style style] |
> > > |  | [label label] |
> > > |  | [horizontal-inset horizontal-inset] |
> > > |  | [vertical-inset vertical-inset] |
> > > |  | [enabled enabled] |
> > > |  | [vert-margin vert-margin] |
> > > |  | [horiz-margin horiz-margin] |
> > > |  | [min-width min-width] |
> > > |  | [min-height min-height] |
> > > |  | [stretchable-width stretchable-width] |
> > > |  | [stretchable-height stretchable-height]]) |

> > → ( is-a?/c snip-canvas% )

> > parent

> > :

> > ( or/c ( is-a?/c frame% ) ( is-a?/c dialog% )
> > ( is-a?/c panel% ) ( is-a?/c pane% ))

> > make-snip : (( integer-in 0 10000) ( integer-in 0 10000) . -> . snip% )

> > style

> > :

> > ( listof ( one-of/c 'no-border 'control-border 'combo
> > 'resize-corner 'no-focus 'deleted
> > 'transparent))

> > |  |  | = |  | null

> > label : ( or/c label-string? false/c ) = #f
> > horizontal-inset : ( integer-in 0 1000) = 5
> > vertical-inset : ( integer-in 0 1000) = 5
> > enabled : any/c = #t
> > vert-margin : ( integer-in 0 1000) = 0
> > horiz-margin : ( integer-in 0 1000) = 0
> > min-width : ( integer-in 0 10000) = 0
> > min-height : ( integer-in 0 10000) = 0
> > stretchable-width : any/c = #t
> > stretchable-height : any/c = #t

> Unlike instances of editor-canvas%, each instance of this class creates and manages its own editor. The editor contains one object: a snip% instance created by make-snip.

> The make-snip function receives the requested width and height of the snip, which are calculated from the size of the snip canvas. It is called the first time the snip canvas is resized, which most likely coincides with the first time the snip canvas is shown. The snip is thus created lazily: only when needed, at the size needed. See on-size for more details and an example.

> The style list is prepended with 'no-hscroll and 'no-vscroll before being passed to the editor-canvas% constructor. The other constructor arguments are passed untouched.

> > > method

> > > ( send a-snip-canvas get-snip ) → ( or/c ( is-a?/c snip% ) #f)

> Returns the wrapped snip, or #f if make-snip has not been called yet.

> > > method

> > > ( send a-snip-canvas on-size width height) → void?

> > width : ( integer-in 0 10000)
> > height : ( integer-in 0 10000)

> Overrides on-size in editor-canvas%.
> This is called when the snip canvas is resized.

> On the first call, on-size calls make-snip with width and height arguments respectively ( max 0 ( - width ( * 2 horizontal-inset))) and ( max 0 ( - height ( * 2 vertical-inset))). It then inserts the resulting snip into its editor.

> On subsequent calls, on-size calls the snip’s resize method, calculating the width and height arguments the same way.

> When a snip-canvas% instance is intended to wrap an existing snip% instance, make-snip should simply resize it and return it.

> Example: plot-frame and plot3d-frame create snips and call a function similar to the following to place them in a frame:

> > ( define (make-snip-frame snip w h label)
> > ( define (make-snip width height)
> > ( send snip resize width height)
> > snip)
> > ( define frame
> > ( new frame%
> > [label label]
> > [width ( + 5 5 5 5 w)]
> > [height ( + 5 5 5 5 h)]))
> > ( new snip-canvas%
> > [parent frame]
> > [make-snip make-snip]
> > [horiz-margin 5] [vert-margin 5]
> > [horizontal-inset 5] [vertical-inset 5])
> > frame)

top ← prev up next →