@@ -59,6 +59,27 @@ pub fn init(allocator: std.mem.Allocator) void {
5959 }
6060 }
6161}
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+ }
6283pub fn deinit () void {
6384 if (zguiGetCurrentContext () != null ) {
6485 temp_buffer .? .deinit ();
@@ -104,6 +125,7 @@ pub fn deinitNoContext() void {
104125extern fn zguiCreateContext (shared_font_atlas : ? * const anyopaque ) Context ;
105126extern fn zguiDestroyContext (ctx : ? Context ) void ;
106127extern fn zguiGetCurrentContext () ? Context ;
128+ extern fn zguiSetCurrentContext (ctx : ? Context ) void ;
107129//--------------------------------------------------------------------------------------------------
108130var mem_allocator : ? std.mem.Allocator = null ;
109131var mem_allocations : ? std .AutoHashMap (usize , usize ) = null ;
@@ -405,7 +427,7 @@ pub fn getClipboardText() [:0]const u8 {
405427extern fn zguiSetClipboardText (text : [* :0 ]const u8 ) void ;
406428extern fn zguiGetClipboardText () [* :0 ]const u8 ;
407429//--------------------------------------------------------------------------------------------------
408- const Context = * opaque {};
430+ pub const Context = * opaque {};
409431pub const DrawData = * extern struct {
410432 valid : bool ,
411433 cmd_lists_count : c_int ,
0 commit comments