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
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
| Option | Type | Default | What it does |
|---|---|---|---|
width | Length | kAuto | Its box. Either left kAuto takes the picture's own size in that direction, so an image with neither set is drawn at 1:1. |
height | Length | kAuto | |
fit | ImageFit | ImageFit::Contain | How the picture meets a box that is not its shape. |
radius | float | 0.0f | Rounded corners, cut from the picture itself — an avatar is this and a radius of half its size. |
opacity | float | 1.0f | |
background optional | std::optional<Fill> | Behind the picture, which is what shows through a transparent one and what fills the letterboxing Contain leaves. | |
padding | Edges | ||
grow | float | 0.0f | Kept out of the flow's stretch, like an icon: a picture has a size and a container has no business overriding it. |
shrink | float | 0.0f | |
alt | std::string_view | Drawn 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. |