mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
35 lines
775 B
Zig
35 lines
775 B
Zig
const std = @import("std");
|
|
const c = @import("c.zig");
|
|
const Allocator = std.mem.Allocator;
|
|
|
|
pub const Context = opaque {
|
|
pub fn create() Allocator.Error!*Context {
|
|
return @ptrCast(
|
|
?*Context,
|
|
c.igCreateContext(null),
|
|
) orelse Allocator.Error.OutOfMemory;
|
|
}
|
|
|
|
pub fn destroy(self: *Context) void {
|
|
c.igDestroyContext(self.cval());
|
|
}
|
|
|
|
pub fn setCurrent(self: *Context) void {
|
|
c.igSetCurrentContext(self.cval());
|
|
}
|
|
|
|
pub inline fn cval(self: *Context) *c.ImGuiContext {
|
|
return @ptrCast(
|
|
*c.ImGuiContext,
|
|
@alignCast(@alignOf(c.ImGuiContext), self),
|
|
);
|
|
}
|
|
};
|
|
|
|
test {
|
|
var ctx = try Context.create();
|
|
defer ctx.destroy();
|
|
|
|
ctx.setCurrent();
|
|
}
|