WARNING: Cushy is in early alpha. This guide doubly so.

Image

The Image widget displays an image/texture with configurable scaling options.

ImageCornerRadius

Use ImageCornerRadius component to set the corner/border radius of an image. CornerRadius is not used.

image
  .with_dynamic(&ImageCornerRadius, CornerRadius) // CornerRadius is a Dynamic(Lp) here
  .with(&ImageCornerRadius, Lp::points(6)) // or, a static corner radius

Dynamic textures

Use a Dynamic(AnyTexture).

You can default to a empty texture like so:

let dynamic_texture = Dynamic::new(
    AnyTexture::Lazy(
        LazyTexture::from_image(
            image::DynamicImage::ImageRgba8(
                image::ImageBuffer::new(1, 1)
            ),
            cushy::kludgine::wgpu::FilterMode::Linear
        )
    )
);
let widget = Image::new(dynamic_texture); // Creates image widget with an empty texture, that can later be changed

To load an image from bytes, use the image crate and then pass it to LazyTexture:

let image = image::load_from_memory(&bytes).unwrap();
let texture = LazyTexture::from_image(
    image,
    cushy::kludgine::wgpu::FilterMode::Linear
);
let texture = AnyTexture::Lazy(texture);
dynamic_texture.set(texture);

FilterMode

FilterMode enum specifies the sampler to be used for when an image is scaled.
Linear smooths the version, making it blurry at the extremes but with less grain.
Nearest makes the result more pixelated with hard edges.