chore: update to zgui v1.89.6

(there were some zig language changes)
This commit is contained in:
Rekai Nyangadzayi Musuka 2023-07-10 21:36:27 -05:00
parent fc608f4798
commit 159dd03964
4 changed files with 118 additions and 22 deletions

View File

@ -41,7 +41,7 @@ pub fn newFrame(fb_width: u32, fb_height: u32) void {
ImGui_ImplWGPU_NewFrame();
ImGui_ImplGlfw_NewFrame();
gui.io.setDisplaySize(@intToFloat(f32, fb_width), @intToFloat(f32, fb_height));
gui.io.setDisplaySize(@as(f32, @floatFromInt(fb_width)), @as(f32, @floatFromInt(fb_height)));
gui.io.setDisplayFramebufferScale(1.0, 1.0);
gui.newFrame();

View File

@ -49,7 +49,7 @@ pub fn deinit() void {
while (it.next()) |kv| {
const address = kv.key_ptr.*;
const size = kv.value_ptr.*;
mem_allocator.?.free(@intToPtr([*]align(mem_alignment) u8, address)[0..size]);
mem_allocator.?.free(@as([*]align(mem_alignment) u8, @ptrFromInt(address))[0..size]);
std.log.info(
"[zgui] Possible memory leak or static memory usage detected: (address: 0x{x}, size: {d})",
.{ address, size },
@ -94,7 +94,7 @@ fn zguiMemAlloc(size: usize, _: ?*anyopaque) callconv(.C) ?*anyopaque {
size,
) catch @panic("zgui: out of memory");
mem_allocations.?.put(@ptrToInt(mem.ptr), size) catch @panic("zgui: out of memory");
mem_allocations.?.put(@intFromPtr(mem.ptr), size) catch @panic("zgui: out of memory");
return mem.ptr;
}
@ -105,8 +105,8 @@ fn zguiMemFree(maybe_ptr: ?*anyopaque, _: ?*anyopaque) callconv(.C) void {
defer mem_mutex.unlock();
if (mem_allocations != null) {
const size = mem_allocations.?.fetchRemove(@ptrToInt(ptr)).?.value;
const mem = @ptrCast([*]align(mem_alignment) u8, @alignCast(mem_alignment, ptr))[0..size];
const size = mem_allocations.?.fetchRemove(@intFromPtr(ptr)).?.value;
const mem = @as([*]align(mem_alignment) u8, @ptrCast(@alignCast(ptr)))[0..size];
mem_allocator.?.free(mem);
}
}
@ -179,7 +179,7 @@ pub const io = struct {
) Font;
pub fn addFontFromMemory(fontdata: []const u8, size_pixels: f32) Font {
return zguiIoAddFontFromMemory(fontdata.ptr, @intCast(i32, fontdata.len), size_pixels);
return zguiIoAddFontFromMemory(fontdata.ptr, @as(i32, @intCast(fontdata.len)), size_pixels);
}
extern fn zguiIoAddFontFromMemory(font_data: *const anyopaque, font_size: i32, size_pixels: f32) Font;
@ -191,7 +191,7 @@ pub const io = struct {
) Font {
return zguiIoAddFontFromMemoryWithConfig(
fontdata.ptr,
@intCast(i32, fontdata.len),
@as(i32, @intCast(fontdata.len)),
size_pixels,
if (config) |c| &c else null,
ranges,
@ -842,10 +842,10 @@ pub const Style = extern struct {
extern fn zguiStyle_ScaleAllSizes(style: *Style, scale_factor: f32) void;
pub fn getColor(style: Style, idx: StyleCol) [4]f32 {
return style.colors[@enumToInt(idx)];
return style.colors[@intFromEnum(idx)];
}
pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void {
style.colors[@enumToInt(idx)] = color;
style.colors[@intFromEnum(idx)] = color;
}
};
/// `pub fn getStyle() *Style`
@ -3359,10 +3359,12 @@ pub const DrawCmd = extern struct {
vtx_offset: u32,
idx_offset: u32,
elem_count: u32,
user_callback: ?*anyopaque,
user_callback: ?DrawCallback,
user_callback_data: ?*anyopaque,
};
pub const DrawCallback = *const fn (*const anyopaque, *const DrawCmd) callconv(.C) void;
pub const getWindowDrawList = zguiGetWindowDrawList;
pub const getBackgroundDrawList = zguiGetBackgroundDrawList;
pub const getForegroundDrawList = zguiGetForegroundDrawList;
@ -3746,7 +3748,7 @@ pub const DrawList = *opaque {
zguiDrawList_AddPolyline(
draw_list,
points.ptr,
@intCast(u32, points.len),
@as(u32, @intCast(points.len)),
args.col,
args.flags,
args.thickness,
@ -3769,7 +3771,7 @@ pub const DrawList = *opaque {
zguiDrawList_AddConvexPolyFilled(
draw_list,
points.ptr,
@intCast(u32, points.len),
@as(u32, @intCast(points.len)),
col,
);
}
@ -4151,5 +4153,15 @@ pub const DrawList = *opaque {
draw_list: DrawList,
idx: DrawIdx,
) void;
//----------------------------------------------------------------------------------------------
pub fn addCallback(draw_list: DrawList, callback: DrawCallback, callback_data: ?*anyopaque) void {
zguiDrawList_AddCallback(draw_list, callback, callback_data);
}
extern fn zguiDrawList_AddCallback(draw_list: DrawList, callback: DrawCallback, callback_data: ?*anyopaque) void;
pub fn addResetRenderStateCallback(draw_list: DrawList) void {
zguiDrawList_AddResetRenderStateCallback(draw_list);
}
extern fn zguiDrawList_AddResetRenderStateCallback(draw_list: DrawList) void;
};

View File

@ -92,10 +92,10 @@ pub const Style = extern struct {
extern fn zguiPlotStyle_Init() Style;
pub fn getColor(style: Style, idx: StyleCol) [4]f32 {
return style.colors[@enumToInt(idx)];
return style.colors[@intFromEnum(idx)];
}
pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void {
style.colors[@enumToInt(idx)] = color;
style.colors[@intFromEnum(idx)] = color;
}
};
/// `pub fn getStyle() *Style`
@ -281,9 +281,9 @@ pub fn setupAxis(axis: Axis, args: SetupAxis) void {
extern fn zguiPlot_SetupAxis(axis: Axis, label: ?[*:0]const u8, flags: AxisFlags) void;
//----------------------------------------------------------------------------------------------
pub const Condition = enum(u32) {
none = @enumToInt(gui.Condition.none),
always = @enumToInt(gui.Condition.always),
once = @enumToInt(gui.Condition.once),
none = @intFromEnum(gui.Condition.none),
always = @intFromEnum(gui.Condition.always),
once = @intFromEnum(gui.Condition.once),
};
const SetupAxisLimits = struct {
min: f64,
@ -363,7 +363,7 @@ pub fn plotLineValues(label_id: [:0]const u8, comptime T: type, args: PlotLineVa
label_id,
gui.typeToDataTypeEnum(T),
args.v.ptr,
@intCast(i32, args.v.len),
@as(i32, @intCast(args.v.len)),
args.xscale,
args.xstart,
args.flags,
@ -399,7 +399,7 @@ pub fn plotLine(label_id: [:0]const u8, comptime T: type, args: PlotLineGen(T))
gui.typeToDataTypeEnum(T),
args.xv.ptr,
args.yv.ptr,
@intCast(i32, args.xv.len),
@as(i32, @intCast(args.xv.len)),
args.flags,
args.offset,
args.stride,
@ -445,7 +445,7 @@ pub fn plotScatterValues(label_id: [:0]const u8, comptime T: type, args: PlotSca
label_id,
gui.typeToDataTypeEnum(T),
args.v.ptr,
@intCast(i32, args.v.len),
@as(i32, @intCast(args.v.len)),
args.xscale,
args.xstart,
args.flags,
@ -481,7 +481,7 @@ pub fn plotScatter(label_id: [:0]const u8, comptime T: type, args: PlotScatterGe
gui.typeToDataTypeEnum(T),
args.xv.ptr,
args.yv.ptr,
@intCast(i32, args.xv.len),
@as(i32, @intCast(args.xv.len)),
args.flags,
args.offset,
args.stride,
@ -518,7 +518,7 @@ pub fn plotShaded(label_id: [:0]const u8, comptime T: type, args: PlotShadedGen(
gui.typeToDataTypeEnum(T),
args.xv.ptr,
args.yv.ptr,
@intCast(i32, args.xv.len),
@as(i32, @intCast(args.xv.len)),
args.yref,
args.flags,
args.offset,
@ -536,6 +536,54 @@ extern fn zguiPlot_PlotShaded(
offset: i32,
stride: i32,
) void;
//----------------------------------------------------------------------------------------------
pub const DragToolFlags = packed struct(u32) {
no_cursors: bool = false,
no_fit: bool = false,
no_no_inputs: bool = false,
delayed: bool = false,
_padding: u28 = 0,
};
const DragPoint = struct {
x: *f64,
y: *f64,
col: [4]f32,
size: f32 = 4,
flags: DragToolFlags = .{},
};
pub fn dragPoint(id: i32, args: DragPoint) bool {
return zguiPlot_DragPoint(
id,
args.x,
args.y,
&args.col,
args.size,
args.flags,
);
}
extern fn zguiPlot_DragPoint(id: i32, x: *f64, y: *f64, *const [4]f32, size: f32, flags: DragToolFlags) bool;
//----------------------------------------------------------------------------------------------
// PlotText
const PlotTextFlags = packed struct(u32) {
vertical: bool = false,
_padding: u31 = 0,
};
const PlotText = struct {
x: f64,
y: f64,
pix_offset: [2]f32 = .{ 0, 0 },
flags: PlotTextFlags = .{},
};
pub fn plotText(text: [*:0]const u8, args:PlotText) void {
zguiPlot_PlotText(text, args.x, args.y, &args.pix_offset, args.flags);
}
extern fn zguiPlot_PlotText(
text:[*:0]const u8,
x:f64, y:f64,
pix_offset: *const [2]f32,
flags: PlotTextFlags,
) void;
//----------------------------------------------------------------------------------------------
/// `pub fn showDemoWindow(popen: ?*bool) void`

View File

@ -2089,6 +2089,14 @@ ZGUI_API void zguiDrawList_PrimWriteVtx(
ZGUI_API void zguiDrawList_PrimWriteIdx( ImDrawList* draw_list, ImDrawIdx idx) {
draw_list->PrimWriteIdx(idx);
}
ZGUI_API void zguiDrawList_AddCallback(ImDrawList* draw_list, ImDrawCallback callback, void* callback_data) {
draw_list->AddCallback(callback, callback_data);
}
ZGUI_API void zguiDrawList_AddResetRenderStateCallback(ImDrawList* draw_list) {
draw_list->AddCallback(ImDrawCallback_ResetRenderState, NULL);
}
//--------------------------------------------------------------------------------------------------
//
// Viewport
@ -2354,5 +2362,33 @@ ZGUI_API void zguiPlot_ShowDemoWindow(bool* p_open) {
ZGUI_API void zguiPlot_EndPlot(void) {
ImPlot::EndPlot();
}
ZGUI_API bool zguiPlot_DragPoint(
int id,
double* x,
double* y,
float col[4],
float size,
ImPlotDragToolFlags flags
) {
return ImPlot::DragPoint(
id,
x,
y,
(*(const ImVec4*)&(col[0])),
size,
flags
);
}
ZGUI_API void zguiPlot_PlotText(
const char* text,
double x, double y,
const float pix_offset[2],
ImPlotTextFlags flags=0
) {
const ImVec2 p(pix_offset[0], pix_offset[1]);
ImPlot::PlotText(text, x, y, p, flags);
}
//--------------------------------------------------------------------------------------------------
} /* extern "C" */