feat: update to 51bf33b8eb3e8bf5d42f6192b49df5571923e6a0
This commit is contained in:
46
src/backend_glfw_opengl.zig
Normal file
46
src/backend_glfw_opengl.zig
Normal file
@@ -0,0 +1,46 @@
|
||||
const gui = @import("gui.zig");
|
||||
|
||||
pub fn initWithGlSlVersion(
|
||||
window: *const anyopaque, // zglfw.Window
|
||||
glsl_version: ?[:0]const u8, // e.g. "#version 130"
|
||||
) void {
|
||||
if (!ImGui_ImplGlfw_InitForOpenGL(window, true)) {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Init(@ptrCast(glsl_version));
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
window: *const anyopaque, // zglfw.Window
|
||||
) void {
|
||||
initWithGlSlVersion(window, null);
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
}
|
||||
|
||||
pub fn newFrame(fb_width: u32, fb_height: u32) void {
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
gui.io.setDisplaySize(@as(f32, @floatFromInt(fb_width)), @as(f32, @floatFromInt(fb_height)));
|
||||
gui.io.setDisplayFramebufferScale(1.0, 1.0);
|
||||
|
||||
gui.newFrame();
|
||||
}
|
||||
|
||||
pub fn draw() void {
|
||||
gui.render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(gui.getDrawData());
|
||||
}
|
||||
|
||||
extern fn ImGui_ImplGlfw_InitForOpenGL(window: *const anyopaque, install_callbacks: bool) bool;
|
||||
extern fn ImGui_ImplGlfw_NewFrame() void;
|
||||
extern fn ImGui_ImplGlfw_Shutdown() void;
|
||||
extern fn ImGui_ImplOpenGL3_Init(glsl_version: [*c]const u8) void;
|
||||
extern fn ImGui_ImplOpenGL3_Shutdown() void;
|
||||
extern fn ImGui_ImplOpenGL3_NewFrame() void;
|
||||
extern fn ImGui_ImplOpenGL3_RenderDrawData(data: *const anyopaque) void;
|
||||
36
src/gui.zig
36
src/gui.zig
@@ -4,11 +4,10 @@
|
||||
// named parameters and Zig style text formatting.
|
||||
//
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
pub const version = @import("std").SemanticVersion{ .major = 1, .minor = 89, .patch = 6 };
|
||||
|
||||
pub const plot = @import("plot.zig");
|
||||
pub const backend = switch (@import("zgui_options").backend) {
|
||||
.glfw_wgpu => @import("backend_glfw_wgpu.zig"),
|
||||
.glfw_opengl3 => @import("backend_glfw_opengl.zig"),
|
||||
.win32_dx12 => .{}, // TODO:
|
||||
.no_backend => .{},
|
||||
};
|
||||
@@ -1476,7 +1475,7 @@ pub fn comboFromEnum(
|
||||
.Enum => |e| {
|
||||
comptime var str: [:0]const u8 = "";
|
||||
|
||||
inline for (e.fields) |f| {
|
||||
for (e.fields) |f| {
|
||||
str = str ++ f.name ++ "\x00";
|
||||
}
|
||||
break :lbl str;
|
||||
@@ -2703,7 +2702,7 @@ extern fn zguiSetNextItemOpen(is_open: bool, cond: Condition) void;
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
pub const SelectableFlags = packed struct(u32) {
|
||||
dont_close_popups: bool = false,
|
||||
span_all_colums: bool = false,
|
||||
span_all_columns: bool = false,
|
||||
allow_double_click: bool = false,
|
||||
disabled: bool = false,
|
||||
allow_item_overlap: bool = false,
|
||||
@@ -3086,12 +3085,14 @@ pub fn colorConvertFloat3ToU32(in: [3]f32) u32 {
|
||||
|
||||
pub fn colorConvertRgbToHsv(r: f32, g: f32, b: f32) [3]f32 {
|
||||
var hsv: [3]f32 = undefined;
|
||||
return zguiColorConvertRGBtoHSV(r, g, b, &hsv[0], &hsv[1], &hsv[2]);
|
||||
zguiColorConvertRGBtoHSV(r, g, b, &hsv[0], &hsv[1], &hsv[2]);
|
||||
return hsv;
|
||||
}
|
||||
|
||||
pub fn colorConvertHsvToRgb(h: f32, s: f32, v: f32) [3]f32 {
|
||||
var rgb: [3]f32 = undefined;
|
||||
return zguiColorConvertHSVtoRGB(h, s, v, &rgb[0], &rgb[1], &rgb[2]);
|
||||
zguiColorConvertHSVtoRGB(h, s, v, &rgb[0], &rgb[1], &rgb[2]);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
extern fn zguiColorConvertU32ToFloat4(in: u32, rgba: *[4]f32) void;
|
||||
@@ -3465,19 +3466,32 @@ pub const DrawList = *opaque {
|
||||
pub const getVertexBufferLength = zguiDrawList_GetVertexBufferLength;
|
||||
extern fn zguiDrawList_GetVertexBufferLength(draw_list: DrawList) i32;
|
||||
pub const getVertexBufferData = zguiDrawList_GetVertexBufferData;
|
||||
extern fn zguiDrawList_GetVertexBufferData(draw_list: DrawList) [*]const DrawVert;
|
||||
extern fn zguiDrawList_GetVertexBufferData(draw_list: DrawList) [*]DrawVert;
|
||||
pub fn getVertexBuffer(draw_list: DrawList) []DrawVert {
|
||||
const len: usize = @intCast(draw_list.getVertexBufferLength());
|
||||
return draw_list.getVertexBufferData()[0..len];
|
||||
}
|
||||
|
||||
pub const getIndexBufferLength = zguiDrawList_GetIndexBufferLength;
|
||||
extern fn zguiDrawList_GetIndexBufferLength(draw_list: DrawList) i32;
|
||||
pub const getIndexBufferData = zguiDrawList_GetIndexBufferData;
|
||||
extern fn zguiDrawList_GetIndexBufferData(draw_list: DrawList) [*]const DrawIdx;
|
||||
extern fn zguiDrawList_GetIndexBufferData(draw_list: DrawList) [*]DrawIdx;
|
||||
pub fn getIndexBuffer(draw_list: DrawList) []DrawIdx {
|
||||
const len: usize = @intCast(draw_list.getIndexBufferLength());
|
||||
return draw_list.getIndexBufferData()[0..len];
|
||||
}
|
||||
|
||||
pub const getCurrentIndex = zguiDrawList_GetCurrentIndex;
|
||||
extern fn zguiDrawList_GetCurrentIndex(draw_list: DrawList) u32;
|
||||
|
||||
pub const getCmdBufferLength = zguiDrawList_GetCmdBufferLength;
|
||||
extern fn zguiDrawList_GetCmdBufferLength(draw_list: DrawList) i32;
|
||||
pub const getCmdBufferData = zguiDrawList_GetCmdBufferData;
|
||||
extern fn zguiDrawList_GetCmdBufferData(draw_list: DrawList) [*]const DrawCmd;
|
||||
extern fn zguiDrawList_GetCmdBufferData(draw_list: DrawList) [*]DrawCmd;
|
||||
pub fn getCmdBuffer(draw_list: DrawList) []DrawCmd {
|
||||
const len: usize = @intCast(draw_list.getCmdBufferLength());
|
||||
return draw_list.getCmdBufferData()[0..len];
|
||||
}
|
||||
|
||||
pub const DrawListFlags = packed struct(u32) {
|
||||
anti_aliased_lines: bool = false,
|
||||
@@ -4223,3 +4237,7 @@ pub const DrawList = *opaque {
|
||||
}
|
||||
extern fn zguiDrawList_AddResetRenderStateCallback(draw_list: DrawList) void;
|
||||
};
|
||||
|
||||
test {
|
||||
std.testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
@@ -574,17 +574,17 @@ const PlotText = struct {
|
||||
pix_offset: [2]f32 = .{ 0, 0 },
|
||||
flags: PlotTextFlags = .{},
|
||||
};
|
||||
pub fn plotText(text: [*:0]const u8, args:PlotText) void {
|
||||
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,
|
||||
text: [*:0]const u8,
|
||||
x: f64,
|
||||
y: f64,
|
||||
pix_offset: *const [2]f32,
|
||||
flags: PlotTextFlags,
|
||||
) void;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
/// `pub fn showDemoWindow(popen: ?*bool) void`
|
||||
pub const showDemoWindow = zguiPlot_ShowDemoWindow;
|
||||
|
||||
10
src/zgui.cpp
10
src/zgui.cpp
@@ -1,5 +1,8 @@
|
||||
#include "./imgui/imgui.h"
|
||||
#include "./imgui/implot.h"
|
||||
#include "imgui.h"
|
||||
|
||||
#if ZGUI_IMPLOT
|
||||
#include "implot.h"
|
||||
#endif
|
||||
|
||||
#ifndef ZGUI_API
|
||||
#define ZGUI_API
|
||||
@@ -2155,6 +2158,8 @@ ZGUI_API void zguiViewport_GetWorkSize(ImGuiViewport* viewport, float p[2]) {
|
||||
p[0] = sz.x;
|
||||
p[1] = sz.y;
|
||||
}
|
||||
|
||||
#if ZGUI_IMPLOT
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// ImPlot
|
||||
@@ -2415,6 +2420,7 @@ ZGUI_API void zguiPlot_PlotText(
|
||||
const ImVec2 p(pix_offset[0], pix_offset[1]);
|
||||
ImPlot::PlotText(text, x, y, p, flags);
|
||||
}
|
||||
#endif /* #ifdef ZGUI_IMPLOT */
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
} /* extern "C" */
|
||||
|
||||
Reference in New Issue
Block a user