Compare commits
12 Commits
5149d4b1de
...
25fa193b1f
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | 25fa193b1f | |
Rekai Nyangadzayi Musuka | 334c021350 | |
Rekai Nyangadzayi Musuka | 2894f69c2f | |
Rekai Nyangadzayi Musuka | be835bb15b | |
Rekai Nyangadzayi Musuka | a2e5652678 | |
Rekai Nyangadzayi Musuka | 925ff4b50a | |
Rekai Nyangadzayi Musuka | 1ff2abf816 | |
Rekai Nyangadzayi Musuka | 367dd7a99e | |
Rekai Nyangadzayi Musuka | c7d1c329a1 | |
Rekai Nyangadzayi Musuka | 6c56505fa6 | |
Rekai Nyangadzayi Musuka | 9964c55136 | |
Rekai Nyangadzayi Musuka | 159dd03964 |
|
@ -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();
|
||||
|
|
34
src/gui.zig
34
src/gui.zig
|
@ -51,7 +51,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 },
|
||||
|
@ -96,7 +96,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;
|
||||
}
|
||||
|
@ -107,8 +107,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);
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,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;
|
||||
|
||||
|
@ -193,7 +193,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,
|
||||
|
@ -844,10 +844,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`
|
||||
|
@ -3361,10 +3361,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;
|
||||
|
@ -3748,7 +3750,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,
|
||||
|
@ -3771,7 +3773,7 @@ pub const DrawList = *opaque {
|
|||
zguiDrawList_AddConvexPolyFilled(
|
||||
draw_list,
|
||||
points.ptr,
|
||||
@intCast(u32, points.len),
|
||||
@as(u32, @intCast(points.len)),
|
||||
col,
|
||||
);
|
||||
}
|
||||
|
@ -4153,5 +4155,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;
|
||||
};
|
||||
|
|
68
src/plot.zig
68
src/plot.zig
|
@ -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`
|
||||
|
|
36
src/zgui.cpp
36
src/zgui.cpp
|
@ -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" */
|
||||
|
|
Loading…
Reference in New Issue