Skip to main content

Images

Image draws a texture into an element's box. Load the texture once with CC_LoadImage, then each frame wrap its address in ImgFill, ImgFit or ImgCrop to choose how it scales. These names need the raylib backend.

raylib only, except CC_ImageScale.

Example​

static Texture2D avatar; // CC_LoadImage after CC_Init

static void profile(void) {
Row("Profile", .layout = { .childGap = 12 }) {
Image("Avatar", ImgCrop(&avatar),
.layout = { .sizing = { Fixed(64), Fixed(64) } },
.cornerRadius = RadiusAll(999)); // circle
Text("Display name", .fontSize = 20);
}
}

// startup: avatar = CC_LoadImage("resources/avatar.png");
// shutdown: CC_UnloadImage(avatar);

Reference​

NameFormWhat it doesPage
ImageImage("id", CC_ImageRef *ref, .field = ...)Image leaf drawn into the element's box.Images
ImgFillCC_ImageRef *ImgFill(Texture2D *tex)Stretch to fill the box, ignoring aspect ratio.Images
ImgFitCC_ImageRef *ImgFit(Texture2D *tex)Fit inside the box, keeping aspect ratio (letterboxed).Images
ImgCropCC_ImageRef *ImgCrop(Texture2D *tex)Cover the box, keeping aspect ratio, cropping overflow.Images
CC_AcquireImageRefCC_ImageRef *(Texture2D *tex, CC_ImageScale scale)The pool call behind ImgFill / ImgFit / ImgCrop. Returns NULL when the 128-entry per-frame pool is full.Images
CC_ImageRefstruct { Texture2D *texture; CC_ImageScale scale; }What Image draws.Images
CC_ImageScaleCC_IMAGE_FILL, CC_IMAGE_FIT, CC_IMAGE_CROPScale modes.Images
CC_LoadImageTexture2D (const char *path)Load an image file as a texture. Call after CC_Init.Images
CC_UnloadImagevoid (Texture2D texture)Free a texture from CC_LoadImage. Call before CC_Shutdown.Images