osWindowImpl
Parameters
- src:std.builtin.SourceLocation
- std.builtin.SourceLocation
- child_win_opts:OsWindowWidget.InitOptions
- OsWindowWidget.InitOptions
- win_opts:Window.InitOptions
- Window.InitOptions
Source
Implementation
pub fn osWindowImpl(src: std.builtin.SourceLocation, child_win_opts: OsWindowWidget.InitOptions, win_opts: Window.InitOptions) OsWindowWidget {
const cw = dvui.currentWindow();
const hashval = cw.data().id.extendId(src, win_opts.id_extra);
const win_maybe = cw.child_os_wins.getOrPut(cw.gpa, hashval) catch @panic("OOM");
const os_win: *ChildOsWindow = if (win_maybe.found_existing)
win_maybe.value_ptr
else blk: {
const new_backend = cw.gpa.create(dvui.backend) catch @panic("OOM");
new_backend.* = cw.backend.impl.initWindowSecondary(child_win_opts) catch @panic("Failed to initialize new backend");
// this is just for easy debug but would be nice to have a nudge strategy where possible.
// But this as a whole other can of worms. Don't even know if this is possible on wayland for instance.
_ = dvui.backend.c.SDL_SetWindowPosition(new_backend.window, 850, 150);
const new_dvui_win = cw.gpa.create(dvui.Window) catch @panic("OOM");
new_dvui_win.* = dvui.Window.init(src, cw.gpa, new_backend.backend(), .{
.id_extra = win_opts.id_extra,
.theme = win_opts.theme orelse cw.theme,
.button_order = win_opts.button_order orelse cw.button_order,
// Do not grab the parent's one, because closing a child window is not the same as
// quitting the application. User should explicitly use the same open_flag for this behavior.
.open_flag = win_opts.open_flag,
}) catch
@panic("Failed to initialize new dvui.Window");
new_dvui_win.is_primary = false;
win_maybe.value_ptr.* = .{ .backend = new_backend, .dvui_win = new_dvui_win };
break :blk win_maybe.value_ptr;
};
std.debug.assert(os_win.dvui_win.data().id == hashval);
os_win.dvui_win.begin(cw.frame_time_ns) catch |err| {
dvui.logError(@src(), err, "Something wrong in child's dvui.Window.begin()", .{});
};
if (os_win.has_begin) {
dvui.log.err("duplicate os Window. id {f} (highlighted in red); you may need to pass .{{.id_extra=<loop index>}} as widget options (see https://github.com/david-vanderson/dvui/blob/master/readme-implementation.md#widget-ids )", .{hashval});
dvui.Debug.errorOutline(os_win.dvui_win.rectScale().r);
}
os_win.has_begin = true;
return .{ .inner = os_win };
}