Container
Component which is capable of holding other components inside of it.
It is not instantiated directly, rather you must use shorthands like Row, Column or Stack.
Functions
getChildAt
fn getChildAt(self: *Container_Impl, n: usize) !*Widget
This function returns the n-th child of the container, counting from 0. If n is too big for the component, the function returns error.OutOfBounds
.
Usage:
const container = try capy.Row(.{}, .{
capy.Button(.{ .label = "A" }),
capy.Button(.{ .label = "B" }),
capy.Button(.{ .label = "C" }),
});
const child = try container.getChildAt(2);
// 'child' holds a pointer to capy.Button(.{ .label = "C" })
getChild
fn getChild(self: *Container_Impl, name: []const u8) ?*Widget
This function searches recursively for a component named name
. It returns the first it finds. If no component is found, it returns null
.
Usage:
const container = try capy.Column(.{}, .{
capy.CheckBox(.{ .name = "me" }),
});
// In Zig, '.?' is equivalent to 'orelse unreachable'
const child = container.getChild("me").?;
// 'child' holds a pointer to capy.CheckBox(.{ .name = "me" })
getChildAs
fn getChildAs(self: *Container_Impl, comptime T: type, name: []const u8) ?*T
This function is a shorthand that is equivalent to:
container.getChild(name).as(T);
relayout
fn relayout(self: *Container_Impl) void
This function forces the container to trigger a re-layout. That is call the layouter and reposition and resize its children.
It shouldn't need to be called as all functions that affect a child's position should also trigger a relayout. If it doesn't please file an issue.
add
fn add(self: *Container_Impl, widget: anytype) !void
This function adds the given component to the container.
Example:
container.add(
capy.Button(.{ .label = "Hello, World!" })
);
removeByIndex
fn removeByIndex(self: *Container_Impl, index: usize) void
This function removes the component at the given index. Basically, this removes the component that would otherwise have been returned by getChildAt()
.
removeAll
fn removeAll(self: *Container_Impl) void
This function removes all children from thz container.
Properties
Name | Description |
---|---|
layout | The function that handles layouting |
Examples
Canvas(.{})
.addDrawHandler(drawCanvas);