DVUI

button

Parameters

#
src:std.builtin.SourceLocation
std.builtin.SourceLocation
label_str:[]const u8
[]const u8
init_opts:ButtonWidget.InitOptions
ButtonWidget.InitOptions
opts:Options
Options

Source

Implementation

#
pub fn button(src: std.builtin.SourceLocation, label_str: []const u8, init_opts: ButtonWidget.InitOptions, opts: Options) bool {
    // initialize widget and get rectangle from parent and make ourselves the new parent
    var bw: ButtonWidget = undefined;
    bw.init(src, init_opts, opts);

    // process events (mouse and keyboard)
    bw.processEvents();

    // draw background/border
    bw.drawBackground();

    // use pressed text color if desired
    const click = bw.clicked();

    // this child widget:
    // - has bw as parent
    // - gets a rectangle from bw
    // - draws itself
    // - reports its min size to bw
    labelNoFmt(@src(), label_str, .{ .align_x = 0.5, .align_y = 0.5 }, opts.strip().override(bw.style()).override(.{ .gravity_x = 0.5, .gravity_y = 0.5 }));

    // draw focus
    bw.drawFocus();

    // restore previous parent
    // send our min size to parent
    bw.deinit();

    return click;
}