Repository navigation
Progress
Use LinearProgress for a bar and CircularProgress for a ring. Both take no id or child block and are safe to call in loops.
LinearProgress(0.4f); // bar, 40% full
LinearProgress(CC_PROGRESS_INFINITE); // bar, animated, unknown length
CircularProgress(0.75f); // ring, 75% full
CircularProgress(CC_PROGRESS_INFINITE); // ring, animatedThe first argument is required. It is a float from 0 to 1.
| Value | Result |
|---|---|
0 |
Empty track |
0 to 1
|
Filled to that fraction |
Above 1
|
Clamped to full |
CC_PROGRESS_INFINITE, or any negative value |
Animated indicator for work of unknown length |
The infinite animation runs off the backend clock. You keep no state and call nothing per frame beyond the macro itself.
if (download.total > 0)
LinearProgress((float)download.done / download.total);
else
LinearProgress(CC_PROGRESS_INFINITE);
.sizingarrived inv0.1.3. If you pinv0.1.2, use the float options listed under Migrating from v0.1.2.
Both indicators take .sizing, the same CC_Sizing that containers take in .layout, so every helper from Layout applies: Grow(), Fixed(), Percent() and SizingAll().
LinearProgress(v); // grows wide, 4px high
LinearProgress(v, .sizing = {.height = Fixed(8)}); // grows wide, 8px high
LinearProgress(v, .sizing = {Percent(0.5f), Fixed(6)});
CircularProgress(v); // 40 by 40
CircularProgress(v, .sizing = SizingAll(Fixed(48)));
CircularProgress(v, .sizing = {Grow(), Grow()}); // largest ring that fitsEach axis you leave out gets that component's default, so setting only .height on a bar keeps its growing width. Fit() counts as left out, because a leaf has no content to fit.
The bar fills horizontally and keeps rounded ends:
LinearProgress(ratio,
.sizing = {Fixed(240), Fixed(6)},
.color = Color(111, 173, 162, 255),
.trackColor = Color( 36, 38, 46, 255));| Option | Meaning | Default |
|---|---|---|
.sizing.width |
Track width |
Grow(), fills the parent's width |
.sizing.height |
Track height | Fixed(4) |
.color |
Fill color | The global font color |
.trackColor |
Track color |
.color at 25% of its alpha |
With the default width the bar grows like HDivider(), so put it in a parent that has a width (a Column with Grow() or Fixed() sizing). Inside a Fit()-width parent with nothing else to size it, a growing bar has no width to fill.
The ends stay rounded at any height, including a Grow() or Percent() height.
In infinite mode a segment 30% of the track wide sweeps left to right every 1.5 seconds.
The bar is plain layout: a track element with a fill sized by Percent(). It emits ordinary rectangle commands, so it works in headless mode too. The headless clock is fixed at 0, so an infinite bar there shows only its track.
The arc fills clockwise from 12 o'clock:
CircularProgress(ratio,
.sizing = SizingAll(Fixed(48)),
.thickness = 5,
.color = Color(111, 173, 162, 255),
.trackColor = Color( 36, 38, 46, 255));| Option | Meaning | Default |
|---|---|---|
.sizing |
The ring's box, per axis |
Fixed(40) on both axes |
.thickness |
Stroke width in pixels | 4 |
.color |
Arc color | The global font color |
.trackColor |
Color of the full ring behind the arc |
.color at 25% of its alpha |
The ring's diameter is the smaller side of its box, and it sits in the center. A non-square .sizing such as {Fixed(120), Fixed(40)} still draws a circle, 40 pixels across.
In infinite mode a 90 degree arc turns once per second.
The ring is painted with raylib through the same slot pool as Draw, so it needs the raylib backend. In headless mode it reserves its box in the layout and draws nothing.
Column("Upload", .layout = { .sizing = { Fixed(260), Fit() }, .childGap = 6 }) {
Text("Uploading 3 of 8", .fontSize = 14);
LinearProgress(3.0f / 8.0f);
}Row("Loading", .layout = { .childGap = 10,
.childAlignment = { .y = AlignYCenter() } }) {
CircularProgress(CC_PROGRESS_INFINITE, .sizing = SizingAll(Fixed(18)),
.thickness = 2);
Text("Loading", .fontSize = 14);
}Replace v0.1.2's float sizing options with .sizing:
| v0.1.2 | Now |
|---|---|
LinearProgress(v, .length = 240) |
LinearProgress(v, .sizing = {.width = Fixed(240)}) |
LinearProgress(v, .thickness = 6) |
LinearProgress(v, .sizing = {.height = Fixed(6)}) |
CircularProgress(v, .size = 48) |
CircularProgress(v, .sizing = SizingAll(Fixed(48))) |
.thickness on CircularProgress is unchanged. Old call sites fail to compile with has no member named 'length' (or size, thickness).
- An omitted axis or
Fit()uses the component's default size. - A
Grow()height fills the available layout height. Give the parent a bounded height to control it. - The animation periods are fixed.
-
LinearProgresssupports horizontal bars only. - The ring's stroke ends are square.
- Rings share the per-frame draw-slot pool with
Draw. When the pool is full, a ring keeps its layout space but draws nothing. - A zero value still draws the track. Skip the call to hide the indicator.