capy-ui / capy

💻Build one codebase and get native UI on Windows, Linux and Web
https://capy-ui.org
Mozilla Public License 2.0
1.6k stars 60 forks source link

Button callback not invoked #49

Closed HaSa1002 closed 12 months ago

HaSa1002 commented 1 year ago

The button callback gets not invoked on Windows. Maybe I am stupid (I am just toying around with zig and capy and learn as I go).

const std = @import("std");
const capy = @import("capy");
pub usingnamespace capy.cross_platform;

pub fn main() !void {
    try capy.backend.init();
    var window = try capy.Window.init();
    window.setPreferredSize(600, 800);
    window.setTitle("ArtGit");
    std.debug.print("Hello?", .{});
    try window.set(capy.Button(.{ .label = "Some text", .onclick = onButtonClicked }));
    window.show();
    capy.runEventLoop();
}

fn onButtonClicked(button: *anyopaque) !void {
    std.debug.print("wow", .{});
    var btn = @as(*capy.Button_Impl, @ptrCast(@alignCast(button)));
    btn.setLabel("Was clicked");
}

Observed behaviour

Window is created, the button has the label "Some text" and on click nothing happens.

Expected behaviour

Windows is created, the button has the label "Some text" and on click "wow" is printed and the label text is set to "Was clicked".

Sys Info

Windows 10 Zig: 0.11.0-dev.3937+78eb3c561

wukgdu commented 1 year ago

Window doesn't process BN_CLICKED directly on Windows now, wrapping the button with a container will work as a workaround.

try window.set(capy.Row(
    .{ .wrapping = true },
    .{capy.Button(.{ .label = "Some text", .onclick = onButtonClicked })},
));
HaSa1002 commented 1 year ago

Yeah I did that later, but the getting started guide does so hence the confusion. It should get documented probably?