@@ -59,6 +59,27 @@ pub fn init(allocator: std.mem.Allocator) void {
59
59
}
60
60
}
61
61
}
62
+ /// Allows sharing a context across static/DLL boundaries. This is useful for
63
+ /// hot-reloading mechanisms which rely on shared libraries.
64
+ /// See "CONTEXT AND MEMORY ALLOCATORS" section of ImGui docs.
65
+ pub fn initWithExistingContext (allocator : std.mem.Allocator , ctx : Context ) void {
66
+ mem_allocator = allocator ;
67
+ mem_allocations = std .AutoHashMap (usize , usize ).init (allocator );
68
+ mem_allocations .? .ensureTotalCapacity (32 ) catch @panic ("zgui: out of memory" );
69
+ zguiSetAllocatorFunctions (zguiMemAlloc , zguiMemFree );
70
+
71
+ zguiSetCurrentContext (ctx );
72
+
73
+ temp_buffer = std .ArrayList (u8 ).init (allocator );
74
+ temp_buffer .? .resize (3 * 1024 + 1 ) catch unreachable ;
75
+
76
+ if (te_enabled ) {
77
+ te .init ();
78
+ }
79
+ }
80
+ pub fn getCurrentContext () ? Context {
81
+ return zguiGetCurrentContext ();
82
+ }
62
83
pub fn deinit () void {
63
84
if (zguiGetCurrentContext () != null ) {
64
85
temp_buffer .? .deinit ();
@@ -104,6 +125,7 @@ pub fn deinitNoContext() void {
104
125
extern fn zguiCreateContext (shared_font_atlas : ? * const anyopaque ) Context ;
105
126
extern fn zguiDestroyContext (ctx : ? Context ) void ;
106
127
extern fn zguiGetCurrentContext () ? Context ;
128
+ extern fn zguiSetCurrentContext (ctx : ? Context ) void ;
107
129
//--------------------------------------------------------------------------------------------------
108
130
var mem_allocator : ? std.mem.Allocator = null ;
109
131
var mem_allocations : ? std .AutoHashMap (usize , usize ) = null ;
@@ -405,7 +427,7 @@ pub fn getClipboardText() [:0]const u8 {
405
427
extern fn zguiSetClipboardText (text : [* :0 ]const u8 ) void ;
406
428
extern fn zguiGetClipboardText () [* :0 ]const u8 ;
407
429
//--------------------------------------------------------------------------------------------------
408
- const Context = * opaque {};
430
+ pub const Context = * opaque {};
409
431
pub const DrawData = * extern struct {
410
432
valid : bool ,
411
433
cmd_lists_count : c_int ,
0 commit comments