► |  | 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 | Filesystem
10 | Find
11 | Flonums
12 | Futures
13 | Functions
14 | Hash Tables
15 | Interface-Oriented Programming for Classes
16 | Lazy Require
17 | Lists
18 | Logging
19 | Mark Parameters
20 | Match
21 | Parameter Groups
22 | Pretty-Printing
23 | Sequences
24 | Strings
25 | Structs
26 | Syntax
27 | Temporal Contracts: Explicit Contract Monitors
28 | GUI Libraries

▼ | 28 | GUI Libraries

28.1 | Notify-boxes
28.2 | Preferences
28.3 | Pict Utilities
28.4 | Slideshow Presentations
28.5 | Progressive Picts and Slides
28.6 | Snip Utilities

On this page:

snip-canvas%
get-snip
on-size

Version: 5.3
top← prev up next →

#### 28.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 →