Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ pub fn init(allocator: std.mem.Allocator) void {
}
}
}
/// Allows sharing a context across static/DLL boundaries. This is useful for
/// hot-reloading mechanisms which rely on shared libraries.
/// See "CONTEXT AND MEMORY ALLOCATORS" section of ImGui docs.
pub fn initWithExistingContext(allocator: std.mem.Allocator, ctx: Context) void {
mem_allocator = allocator;
mem_allocations = std.AutoHashMap(usize, usize).init(allocator);
mem_allocations.?.ensureTotalCapacity(32) catch @panic("zgui: out of memory");
zguiSetAllocatorFunctions(zguiMemAlloc, zguiMemFree);

zguiSetCurrentContext(ctx);

temp_buffer = std.ArrayList(u8).init(allocator);
temp_buffer.?.resize(3 * 1024 + 1) catch unreachable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this has been copied from init fn but I don't like it. Just making a note.


if (te_enabled) {
te.init();
}
}
pub fn getCurrentContext() ?Context {
return zguiGetCurrentContext();
}
pub fn deinit() void {
if (zguiGetCurrentContext() != null) {
temp_buffer.?.deinit();
Expand Down Expand Up @@ -104,6 +125,7 @@ pub fn deinitNoContext() void {
extern fn zguiCreateContext(shared_font_atlas: ?*const anyopaque) Context;
extern fn zguiDestroyContext(ctx: ?Context) void;
extern fn zguiGetCurrentContext() ?Context;
extern fn zguiSetCurrentContext(ctx: ?Context) void;
//--------------------------------------------------------------------------------------------------
var mem_allocator: ?std.mem.Allocator = null;
var mem_allocations: ?std.AutoHashMap(usize, usize) = null;
Expand Down Expand Up @@ -405,7 +427,7 @@ pub fn getClipboardText() [:0]const u8 {
extern fn zguiSetClipboardText(text: [*:0]const u8) void;
extern fn zguiGetClipboardText() [*:0]const u8;
//--------------------------------------------------------------------------------------------------
const Context = *opaque {};
pub const Context = *opaque {};
pub const DrawData = *extern struct {
valid: bool,
cmd_lists_count: c_int,
Expand Down
Loading