toastAdd
Add a toast. Use toast for a simple message.
If subwindow_id is null, the toast will be shown during Window.end. If
subwindow_id is the id of a FloatingWindowWidget, it will be shown when
that widget runs init(). Otherwise separate code must call toastsShow or
toastsFor with that subwindow_id to retrieve this toast and display it.
Returns an id and locked mutex that must be unlocked by the caller. Caller
does any dataSet calls before unlocking the mutex to ensure that data is
available before the toast 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 toast to.
Parameters
- win:?*Window
- ?*Window
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- id_extra:usize
- usize
- subwindow_id:?Id
- ?Id
- display:Dialog.DisplayFn
- Dialog.DisplayFn
- timeout:?i32
- ?i32
Source
Implementation
pub fn toastAdd(win: ?*Window, src: std.builtin.SourceLocation, id_extra: usize, subwindow_id: ?Id, display: Dialog.DisplayFn, timeout: ?i32) 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} toastAdd current_window was null, pass a *Window as first parameter if calling from other thread or outside window.begin()/end()", .{ src.file, src.line });
};
const mutex = w.toasts.add(w.gpa, .{ .id = id, .subwindow_id = subwindow_id, .display = display }) catch |err| {
logError(@src(), err, "failed to add toast", .{});
w.toasts.mutex.lockUncancelable(io);
return .{ .id = .zero, .mutex = &w.toasts.mutex };
};
refresh(win, @src(), id);
if (timeout) |tt| {
w.timer(id, tt);
} else {
w.timerRemove(id);
}
return .{ .id = id, .mutex = mutex };
}