Skip to content

Image

image · Elements

A picture in a box — HTML's <img>, with the parts of it that are a toolkit's business.

Import

cpp
#include "gbui/widgets/image.hpp"

Example

Nothing is downloaded until you press it.

cpp
NodeId image(Ui& ui, const Bitmap& source, const ImageOptions& options = {});

Draws source inside a box. The picture is sampled bilinearly and cut by the same rounded corners the boxes use, so an image in a card and the card agree about the curve. The pixels are borrowed for the frame: they are read when the frame is painted, not when this is called, and nothing here copies them. That is the same contract a label's string_view has, and the same one it breaks in the same way — a buffer that dies at the end of the enclosing scope is a picture of whatever the stack holds by the time anyone looks.

API

ImageOptions

OptionTypeDefaultWhat it does
widthLengthkAutoIts box. Either left kAuto takes the picture's own size in that direction, so an image with neither set is drawn at 1:1.
heightLengthkAuto
fitImageFitImageFit::ContainHow the picture meets a box that is not its shape.
radiusfloat0.0fRounded corners, cut from the picture itself — an avatar is this and a radius of half its size.
opacityfloat1.0f
background optionalstd::optional<Fill>Behind the picture, which is what shows through a transparent one and what fills the letterboxing Contain leaves.
paddingEdges
growfloat0.0fKept out of the flow's stretch, like an icon: a picture has a size and a container has no business overriding it.
shrinkfloat0.0f
altstd::string_viewDrawn instead when there are no pixels — HTML's alt, doing the job alt actually does in a browser rather than the one it is credited with. An empty one leaves the box empty, which is right for decoration. A missing logo in a list of companies is not decoration, and a row that silently loses its mark is worse than one showing three letters.

Released under the LGPL-3.0-or-later licence.