toastsShow
Standard way of showing toasts. For the main window, this is called with null in Window.end().
For floating windows or other widgets, pass non-null id. Then it shows toasts that were previously added with non-null subwindow_id, and they are shown on top of the current subwindow.
Toasts are shown in rect centered horizontally and 70% down vertically.
Parameters
- self:*Self
- *Self
- subwindow_id:?Id
- ?Id
- rect:Rect.Natural
- Rect.Natural
Source
Implementation
pub fn toastsShow(self: *Self, subwindow_id: ?Id, rect: Rect.Natural) void {
var it = self.toasts.iterator(subwindow_id);
it.i = self.toasts.indexOfSubwindow(subwindow_id) orelse return;
var toast_win: dvui.FloatingWindowWidget = undefined;
toast_win.init(@src(), .{ .stay_above_parent_window = subwindow_id != null, .process_events_in_deinit = false }, .{ .role = .status, .background = false, .border = .{}, .label = .{ .label_widget = .next } });
defer toast_win.deinit();
toast_win.data().rectSet(dvui.placeIn(.cast(rect), toast_win.data().rect.size(), .none, .{ .x = 0.5, .y = 0.7 }));
toast_win.drawBackground();
toast_win.autoSize(); // affects next frame, always need as toasts can come and go
var vbox = dvui.box(@src(), .{}, .{});
defer vbox.deinit();
while (it.next()) |t| {
t.display(t.id) catch |err| {
dvui.logError(@src(), err, "Toast {x}", .{t.id});
};
}
}