Skip to main content

Scroll and clip

.clip hides whatever overflows an element, and its .childOffset scrolls the contents. CC_ScrollUpdate moves that offset from the mouse wheel and dragging, and keeps it within the content. Keep the CC_Scroll state across frames.

Example​

static CC_Scroll list_scroll; // persists across frames

static void list(void) {
CC_ScrollUpdate(&list_scroll, "List", .vertical = true, .wheel = true, .drag = true);
Column("List", .layout = { .sizing = { Grow(), Fixed(200) }, .childGap = 4 },
.clip = ClipY(list_scroll.offset)) {
for (int i = 0; i < 50; ++i) {
char row[16];
snprintf(row, sizeof row, "Row %d", i);
Text(row);
}
}
}

Reference​

NameFormWhat it doesPage
CC_ScrollUpdateCC_ScrollUpdate(CC_Scroll *s, "id", .horizontal, .vertical, .wheel, .drag, .wheelSpeed, .noClamp)Drive a scroll offset from wheel and drag input, clamped to the content. Call before the element. No-op headless.Scroll and clip
CC_Scrollstruct { CC_Vector2 offset; bool dragging; }Your persistent scroll state. Feed offset into .clip.Scroll and clip
CC_ScrollConfigstructFields for CC_ScrollUpdate. wheelSpeed defaults to 40 px.Scroll and clip
ClipX.clip = ClipX(CC_Vector2 offset)Clip and scroll horizontally.Scroll and clip
ClipY.clip = ClipY(offset)Clip and scroll vertically.Scroll and clip
ClipXY.clip = ClipXY(offset)Both axes.Scroll and clip