CapyZig 的 GUI 库

联合创作 · 2023-09-28

Capy 是一个用于在 Zig 中制作真正的原生 GUI 的跨平台库。目前,Capy 尚在积极开发中,还没有准备好应用于生产。

Capy 主要用于使用操作系统的本地控件来创建应用程序。它是一个声明式的 UI 库,旨在使其易于编写并具有多样性。目标是为独立的 UI 应用提供支持,在游戏或任何其他渲染过程中的集成是一个非目标。

const capy = @import("capy");
const std = @import("std");

pub fn main() !void {
    try capy.backend.init();

    var window = try capy.Window.init();
    try window.set(
        capy.Column(.{ .spacing = 10 }, .{ // have 10px spacing between each column's element
            capy.Row(.{ .spacing = 5 }, .{ // have 5px spacing between each row's element
                capy.Button(.{ .label = "Save", .onclick = buttonClicked }),
                capy.Button(.{ .label = "Run",  .onclick = buttonClicked })
            }),
            // Expanded means the widget will take all the space it can
            // in the parent container
            capy.Expanded(
                capy.TextArea(.{ .text = "Hello World!" })
            )
        })
    );

    window.resize(800, 600);
    window.show();
    capy.runEventLoop();
}

fn buttonClicked(button: *capy.Button_Impl) !void {
    std.log.info("You clicked button with text {s}", .{button.getLabel()});
}
浏览 7
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报