chore: update to zgui b8e6fff08f4c68265efa127ffcb9de652aeba9db

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-08-06 21:47:17 +01:00
parent 159dd03964
commit ddca95a721
4 changed files with 130 additions and 24 deletions

View File

@ -9,6 +9,10 @@ pub const Backend = enum {
pub const Options = struct {
backend: Backend,
shared: bool = false,
/// use bundled imgui source
with_imgui: bool = true,
/// use bundled implot source
with_implot: bool = true,
};
pub const Package = struct {
@ -65,36 +69,51 @@ pub fn package(
.optimize = optimize,
});
zgui_c_cpp.addIncludePath(thisDir() ++ "/libs");
zgui_c_cpp.addIncludePath(thisDir() ++ "/libs/imgui");
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs" });
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs/imgui" });
zgui_c_cpp.linkLibC();
zgui_c_cpp.linkLibCpp();
const cflags = &.{"-fno-sanitize=undefined"};
zgui_c_cpp.addCSourceFile(thisDir() ++ "/src/zgui.cpp", cflags);
zgui_c_cpp.addCSourceFile(.{
.file = .{ .path = thisDir() ++ "/src/zgui.cpp" },
.flags = cflags,
});
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_widgets.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_tables.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_draw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_demo.cpp", cflags);
if (args.options.with_imgui) {
zgui_c_cpp.addCSourceFiles(&.{
thisDir() ++ "/libs/imgui/imgui.cpp",
thisDir() ++ "/libs/imgui/imgui_widgets.cpp",
thisDir() ++ "/libs/imgui/imgui_tables.cpp",
thisDir() ++ "/libs/imgui/imgui_draw.cpp",
thisDir() ++ "/libs/imgui/imgui_demo.cpp",
}, cflags);
}
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_demo.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_items.cpp", cflags);
if (args.options.with_implot) {
zgui_c_cpp.addCSourceFiles(&.{
thisDir() ++ "/libs/imgui/implot_demo.cpp",
thisDir() ++ "/libs/imgui/implot.cpp",
thisDir() ++ "/libs/imgui/implot_items.cpp",
}, cflags);
}
switch (args.options.backend) {
.glfw_wgpu => {
zgui_c_cpp.addIncludePath(thisDir() ++ "/../zglfw/libs/glfw/include");
zgui_c_cpp.addIncludePath(thisDir() ++ "/../zgpu/libs/dawn/include");
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp", cflags);
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/../zglfw/libs/glfw/include" });
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/../zgpu/libs/dawn/include" });
zgui_c_cpp.addCSourceFiles(&.{
thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp",
thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp",
}, cflags);
},
.win32_dx12 => {
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_win32.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_dx12.cpp", cflags);
zgui_c_cpp.addCSourceFiles(&.{
thisDir() ++ "/libs/imgui/backends/imgui_impl_win32.cpp",
thisDir() ++ "/libs/imgui/backends/imgui_impl_dx12.cpp",
}, cflags);
zgui_c_cpp.linkSystemLibraryName("d3dcompiler_47");
zgui_c_cpp.linkSystemLibraryName("dwmapi");
},

View File

@ -539,11 +539,14 @@ static void ImGui_ImplWGPU_CreateFontsTexture()
// Create the associated sampler
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
{
const WGPUMipmapFilterMode mipmap_filter_mode = g_config.texture_filter_mode == 1 ? WGPUMipmapFilterMode_Linear : WGPUMipmapFilterMode_Nearest;
const WGPUFilterMode filter_mode = g_config.texture_filter_mode == 1 ? WGPUFilterMode_Linear : WGPUFilterMode_Nearest;
WGPUSamplerDescriptor sampler_desc = {};
sampler_desc.minFilter = filter_mode;
sampler_desc.magFilter = filter_mode;
sampler_desc.mipmapFilter = filter_mode;
sampler_desc.mipmapFilter = mipmap_filter_mode;
sampler_desc.addressModeU = WGPUAddressMode_Repeat;
sampler_desc.addressModeV = WGPUAddressMode_Repeat;
sampler_desc.addressModeW = WGPUAddressMode_Repeat;

View File

@ -224,6 +224,10 @@ pub const io = struct {
pub const getFontsTexId = zguiIoGetFontsTexId;
extern fn zguiIoGetFontsTexId() TextureIdent;
/// `pub fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool) void`
pub const setConfigWindowsMoveFromTitleBarOnly = zguiIoSetConfigWindowsMoveFromTitleBarOnly;
extern fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(enabled: bool) void;
/// `pub fn zguiIoGetWantCaptureMouse() bool`
pub const getWantCaptureMouse = zguiIoGetWantCaptureMouse;
extern fn zguiIoGetWantCaptureMouse() bool;
@ -1159,6 +1163,13 @@ pub const setMouseCursor = zguiSetMouseCursor;
extern fn zguiGetMouseCursor() Cursor;
extern fn zguiSetMouseCursor(cursor: Cursor) void;
//--------------------------------------------------------------------------------------------------
pub fn getMousePos() [2]f32 {
var pos: [2]f32 = undefined;
zguiGetMousePos(&pos);
return pos;
}
extern fn zguiGetMousePos(pos: *[2]f32) void;
//--------------------------------------------------------------------------------------------------
/// `pub fn alignTextToFramePadding() void`
pub const alignTextToFramePadding = zguiAlignTextToFramePadding;
/// `pub fn getTextLineHeight() f32`
@ -1450,6 +1461,43 @@ pub fn combo(label: [:0]const u8, args: Combo) bool {
args.popup_max_height_in_items,
);
}
/// creates a combo box directly from a pointer to an enum value using zig's
/// comptime mechanics to infer the items for the list at compile time
pub fn comboFromEnum(
label: [:0]const u8,
/// must be a pointer to an enum value (var my_enum: *FoodKinds = .Banana)
/// that is backed by some kind of integer that can safely cast into an
/// i32 (the underlying imgui restriction)
current_item: anytype,
) bool {
const item_names = comptime lbl: {
const item_type = @typeInfo(@TypeOf(current_item.*));
switch (item_type) {
.Enum => |e| {
comptime var str: [:0]const u8 = "";
inline for (e.fields) |f| {
str = str ++ f.name ++ "\x00";
}
break :lbl str;
},
else => {
@compileError("Error: current_item must be a pointer-to-an-enum, not a " ++ @TypeOf(current_item));
},
}
};
var item: i32 = @intCast(@intFromEnum(current_item.*));
const result = combo(label, .{
.items_separated_by_zeros = item_names,
.current_item = &item,
});
current_item.* = @enumFromInt(item);
return result;
}
extern fn zguiCombo(
label: [*:0]const u8,
current_item: *i32,
@ -2859,8 +2907,8 @@ pub const BeginTable = struct {
outer_size: [2]f32 = .{ 0, 0 },
inner_width: f32 = 0,
};
pub fn beginTable(name: [:0]const u8, args: BeginTable) void {
zguiBeginTable(name, args.column, args.flags, &args.outer_size, args.inner_width);
pub fn beginTable(name: [:0]const u8, args: BeginTable) bool {
return zguiBeginTable(name, args.column, args.flags, &args.outer_size, args.inner_width);
}
extern fn zguiBeginTable(
str_id: [*:0]const u8,
@ -2868,7 +2916,7 @@ extern fn zguiBeginTable(
flags: TableFlags,
outer_size: *const [2]f32,
inner_width: f32,
) void;
) bool;
pub fn endTable() void {
zguiEndTable();
@ -2968,6 +3016,11 @@ pub const MouseButton = enum(u32) {
right = 1,
middle = 2,
};
/// `pub fn isMouseDown(mouse_button: MouseButton) bool`
pub const isMouseDown = zguiIsMouseDown;
/// `pub fn isMouseClicked(mouse_button: MouseButton) bool`
pub const isMouseClicked = zguiIsMouseClicked;
/// `pub fn isMouseDoubleClicked(mouse_button: MouseButton) bool`
pub const isMouseDoubleClicked = zguiIsMouseDoubleClicked;
/// `pub fn isItemClicked(mouse_button: MouseButton) bool`
@ -2990,6 +3043,8 @@ pub const isAnyItemHovered = zguiIsAnyItemHovered;
pub const isAnyItemActive = zguiIsAnyItemActive;
/// `pub fn isAnyItemFocused() bool`
pub const isAnyItemFocused = zguiIsAnyItemFocused;
extern fn zguiIsMouseDown(mouse_button: MouseButton) bool;
extern fn zguiIsMouseClicked(mouse_button: MouseButton) bool;
extern fn zguiIsMouseDoubleClicked(mouse_button: MouseButton) bool;
extern fn zguiIsItemHovered(flags: HoveredFlags) bool;
extern fn zguiIsItemActive() bool;
@ -3174,6 +3229,8 @@ pub fn beginPopupModal(name: [:0]const u8, args: Begin) bool {
pub fn openPopup(str_id: [:0]const u8, flags: PopupFlags) void {
zguiOpenPopup(str_id, flags);
}
/// `pub fn beginPopup(str_id: [:0]const u8, flags: WindowFlags) bool`
pub const beginPopup = zguiBeginPopup;
/// `pub fn endPopup() void`
pub const endPopup = zguiEndPopup;
/// `pub fn closeCurrentPopup() void`
@ -3181,6 +3238,7 @@ pub const closeCurrentPopup = zguiCloseCurrentPopup;
extern fn zguiBeginPopupContextWindow() bool;
extern fn zguiBeginPopupContextItem() bool;
extern fn zguiBeginPopupModal(name: [*:0]const u8, popen: ?*bool, flags: WindowFlags) bool;
extern fn zguiBeginPopup(str_id: [*:0]const u8, flags: WindowFlags) bool;
extern fn zguiEndPopup() void;
extern fn zguiOpenPopup(str_id: [*:0]const u8, flags: PopupFlags) void;
extern fn zguiCloseCurrentPopup() void;

View File

@ -260,6 +260,12 @@ ZGUI_API void zguiSetMouseCursor(int cursor) {
ImGui::SetMouseCursor(cursor);
}
ZGUI_API void zguiGetMousePos(float pos[2]) {
const ImVec2 p = ImGui::GetMousePos();
pos[0] = p.x;
pos[1] = p.y;
}
ZGUI_API void zguiAlignTextToFramePadding(void) {
ImGui::AlignTextToFramePadding();
}
@ -1078,6 +1084,10 @@ ZGUI_API bool zguiTreeNode(const char* label) {
return ImGui::TreeNode(label);
}
ZGUI_API bool zguiTreeNodeFlags(const char* label, ImGuiTreeNodeFlags flags) {
return ImGui::TreeNodeEx(label, flags);
}
ZGUI_API bool zguiTreeNodeStrId(const char* str_id, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
@ -1232,6 +1242,10 @@ ZGUI_API ImTextureID zguiIoGetFontsTexId(void) {
return ImGui::GetIO().Fonts->TexID;
}
ZGUI_API void zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool enabled) {
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = enabled;
}
ZGUI_API bool zguiIoGetWantCaptureMouse(void) {
return ImGui::GetIO().WantCaptureMouse;
}
@ -1315,6 +1329,14 @@ ZGUI_API bool zguiIsItemClicked(ImGuiMouseButton mouse_button) {
return ImGui::IsItemClicked(mouse_button);
}
ZGUI_API bool zguiIsMouseDown(ImGuiMouseButton button) {
return ImGui::IsMouseDown(button);
}
ZGUI_API bool zguiIsMouseClicked(ImGuiMouseButton button) {
return ImGui::IsMouseClicked(button);
}
ZGUI_API bool zguiIsMouseDoubleClicked(ImGuiMouseButton button) {
return ImGui::IsMouseDoubleClicked(button);
}
@ -1447,6 +1469,10 @@ ZGUI_API void zguiEndTooltip(void) {
ImGui::EndTooltip();
}
ZGUI_API bool zguiBeginPopup(const char* str_id, ImGuiWindowFlags flags){
return ImGui::BeginPopup(str_id, flags);
}
ZGUI_API bool zguiBeginPopupContextWindow(void) {
return ImGui::BeginPopupContextWindow();
}
@ -1475,14 +1501,14 @@ ZGUI_API void zguiCloseCurrentPopup(void) {
// Tables
//
//--------------------------------------------------------------------------------------------------
ZGUI_API void zguiBeginTable(
ZGUI_API bool zguiBeginTable(
const char* str_id,
int column,
ImGuiTableFlags flags,
const float outer_size[2],
float inner_width
) {
ImGui::BeginTable(str_id, column, flags, { outer_size[0], outer_size[1] }, inner_width);
return ImGui::BeginTable(str_id, column, flags, { outer_size[0], outer_size[1] }, inner_width);
}
ZGUI_API void zguiEndTable(void) {
@ -2381,7 +2407,7 @@ ZGUI_API bool zguiPlot_DragPoint(
}
ZGUI_API void zguiPlot_PlotText(
const char* text,
const char* text,
double x, double y,
const float pix_offset[2],
ImPlotTextFlags flags=0