Fusuma

Components / Components

image

An image of width x height pixels.

Try it

This is the Images page of the gallery, running in your browser: image is on it, and it is the real widget. Press Run, then use it.

Live: Images, where image is usedOpen full size

An image of width x height pixels. A picture whose bytes are not width * height * 4 is left out (the build fails with BuildError::BadImage, which a view reports like any other).

rgba is straight RGBA, 4 bytes a pixel, width * height * 4 of them. .fit(..) and .anchor(..) say how it fills a box of another shape; .boxed(w, h), .wide(w) and .high(h) size the box.

Signature

pub const fn image(width: u32, height: u32, rgba: &'static [u8]) -> Image

Methods

  • .boxed(width: u32, height: u32) -> Self — A box of width x height pixels for the picture: it sits in the middle, cut to the box.
  • .wide(width: u32) -> Self — A box width pixels wide and as high as the picture's shape makes it (aspect-ratio): a 32 x 20 picture wide(64) is 64 x 40.
  • .high(height: u32) -> Self — A box height pixels high and as wide as the picture's shape makes it.
  • .fit(fit: fusuma_ui::Fit) -> Self — How the picture fills its box: stretched (Fit::Fill), as big as goes in (Fit::Contain), covering it (Fit::Cover), or at its own size (Fit::Own, what it is without this).
  • .anchor(at: fusuma_ui::Anchor) -> Self — Where the picture sits in its box, along each side (object-position): the middle by default.

Example

use fusuma::image;
// A 2 by 1 picture: a red pixel and a blue one.
static PIXELS: [u8; 8] = [255, 0, 0, 255, 0, 0, 255, 255];
let view = image(2, 1, &PIXELS).boxed(64, 32);
let built = fusuma::doc::built::<(), _>(&view);
assert_eq!(built.nodes(), 1);

All components · Source