Sprites.Ui.Image

Provide functions for inserting images into the user interface.

Sprites.Ui.Image

Sprites.Ui.Image.Bitmap Element

Sprites.Ui.Image.Bitmap(width, height, build)

A canvas image of the given pixel size. The commands inside draw in canvas pixels. It puts the canvas rendering implementation in context, so the Sprites.Image commands draw on the canvas, and repaints when a value they read changes.

InputTypeDescription
widthNumberThe canvas width in pixels.
heightNumberThe canvas height in pixels.
buildFunctionBuilds the drawing with Sprites.Image commands.

Returns the canvas element.

const radius = Sprites.Reactive.Value(40);
Sprites.Ui.Image.Bitmap(240, 160, () => {
  Sprites.Image.FillStyle('#fcd34d', () => {
    Sprites.Image.Circle(120, 80, radius);
  });
});
Sprites.Ui.Input.Slider(radius, 10, 70);
The slider sets the radius; the canvas repaints as it changes.

Sprites.Ui.Image.PanAndScale Void

Sprites.Ui.Image.PanAndScale(active, pan, show)

An invisible overlay over a Vector, present only while active, that turns drags into pan and the wheel into show. Place it after the Vector, over the same frame, so a move-and-zoom tool is just this overlay switched on.

InputTypeDescription
activeBoolean, Sprites.Reactive.Value or FunctionShows the overlay while true.
panSprites.Reactive.ValueThe pan point { x, y }, moved by dragging.
showSprites.Reactive.ValueThe units shown across the smaller axis, changed by the wheel.

Returns nothing.

const pan = Sprites.Reactive.Value({ x: 16, y: 16 });
const show = Sprites.Reactive.Value(36);
const resetView = Sprites.Reactive.Value(null, () => {
  Sprites.Reactive.Set(pan, { x: 16, y: 16 });
  Sprites.Reactive.Set(show, 36);
});
Sprites.Ui.Dom.Tag('div', () => {
  Sprites.Ui.Dom.Class('image-frame');
  Sprites.Ui.Dom.Style('width', '100%');
  Sprites.Ui.Dom.Style('height', '160px');
  Sprites.Ui.Image.Vector(pan, show, () => {
    Sprites.Image.FillStyle('#93c5fd', () => {
      Sprites.Image.Rectangle(12, 8, 8, 16);
    });
  });
  Sprites.Ui.Image.PanAndScale(true, pan, show);
});
Sprites.Ui.Layout.Row(() => {
  Sprites.Ui.Layout.Column(() => {
    Sprites.Ui.Content.Text('Drag to pan around.');
    Sprites.Ui.Content.Text('Mouse wheel or scroll to zoom.');
  });
  Sprites.Ui.Button.Act(resetView, 'Reset view');
});
Drag the image to pan and use the wheel to zoom. Reset view returns to the start.

Sprites.Ui.Image.Vector Element

Sprites.Ui.Image.Vector(pan, show, build)

An SVG image that fills its container. It shows a square of show units on the smaller axis, centred on pan, and more on the longer axis, so the show-by-show square around pan always stays visible. It follows pan, show and the container size. It puts the SVG rendering implementation in context, so the Sprites.Image commands draw as SVG.

InputTypeDescription
panSprites.Reactive.ValueThe centre point { x, y } in drawing units.
showNumber or Sprites.Reactive.ValueThe units shown across the smaller axis.
buildFunctionBuilds the drawing with Sprites.Image commands.

Returns the svg element.

const radius = Sprites.Reactive.Value(8);
Sprites.Ui.Dom.Tag('div', () => {
  Sprites.Ui.Dom.Class('image-frame');
  Sprites.Ui.Dom.Style('width', '100%');
  Sprites.Ui.Dom.Style('height', '160px');
  Sprites.Ui.Image.Vector({ x: 16, y: 16 }, 36, () => {
    Sprites.Image.FillStyle('#93c5fd', () => {
      Sprites.Image.Circle(16, 16, radius);
    });
  });
});
Sprites.Ui.Input.Slider(radius, 2, 16);
The slider sets the radius; the vector image repaints as it changes.