DVUI

dialogAdd

Add a dialog to be displayed on the GUI thread during Window.end.

Returns an id and locked mutex that must be unlocked by the caller. Caller does any Window.dataSet calls before unlocking the mutex to ensure that data is available before the dialog is displayed.

Can be called from any thread.

If called from non-GUI thread or outside Window.begin/Window.end, you must pass a pointer to the Window you want to add the dialog to.

Parameters

#
win:?*Window
?*Window
src:std.builtin.SourceLocation
std.builtin.SourceLocation
id_extra:usize
usize
display:Dialog.DisplayFn
Dialog.DisplayFn

Source

Implementation

#
pub fn dialogAdd(win: ?*Window, src: std.builtin.SourceLocation, id_extra: usize, display: Dialog.DisplayFn) IdMutex {
    const w: *Window, const id: Id = if (win) |w|
        // we are being called from non gui thread
        .{ w, Id.extendId(null, src, id_extra) }
    else if (current_window) |cw|
        .{ cw, parentGet().extendId(src, id_extra) }
    else {
        std.debug.panic("{s}:{d} dialogAdd current_window was null, pass a *Window as first parameter if calling from other thread or outside window.begin()/end()\n", .{ src.file, src.line });
    };
    const mutex = w.dialogs.add(w.gpa, .{ .id = id, .display = display }) catch |err| {
        logError(@src(), err, "failed to add dialog", .{});
        w.dialogs.mutex.lockUncancelable(io);
        return .{ .id = .zero, .mutex = &w.dialogs.mutex };
    };
    refresh(win, @src(), id);
    return .{ .id = id, .mutex = mutex };
}