From 39aac1a1c41cdede20b55d7987c7931a4b8186a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tarkan=20sar=C4=B1ta=C5=9F?= Date: Thu, 1 May 2025 09:41:00 +0300 Subject: [PATCH 1/3] add some functions --- src/gui.zig | 92 ++++++++++++++++++++++++++++++++++++++++ src/zgui.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+) diff --git a/src/gui.zig b/src/gui.zig index dd5ac0f..ac583cc 100644 --- a/src/gui.zig +++ b/src/gui.zig @@ -699,6 +699,9 @@ pub fn setNextWindowSize(args: SetNextWindowSize) void { } extern fn zguiSetNextWindowSize(w: f32, h: f32, cond: Condition) void; //-------------------------------------------------------------------------------------------------- +extern fn zguiSetNextWindowContentSize(w: f32, h: f32) void; +pub const setNextWindowContentSize = zguiSetNextWindowContentSize; +//-------------------------------------------------------------------------------------------------- const SetNextWindowCollapsed = struct { collapsed: bool, cond: Condition = .none, @@ -712,6 +715,9 @@ extern fn zguiSetNextWindowCollapsed(collapsed: bool, cond: Condition) void; pub const setNextWindowFocus = zguiSetNextWindowFocus; extern fn zguiSetNextWindowFocus() void; //-------------------------------------------------------------------------------------------------- +extern fn zguiSetNextWindowScroll(scroll_x: f32, scroll_y: f32) void; +pub const setNextWindowScroll = zguiSetNextWindowScroll; +//-------------------------------------------------------------------------------------------------- const SetNextWindowBgAlpha = struct { alpha: f32, }; @@ -730,6 +736,11 @@ pub fn setKeyboardFocusHere(offset: i32) void { } extern fn zguiSetKeyboardFocusHere(offset: c_int) void; +extern fn zguiSetNavCursorVisible(visible: bool) void; +pub const setNavCursorVisible = zguiSetNavCursorVisible; + +extern fn zguiSetNextItemAllowOverlap() void; +pub const setNextItemAllowOverlap = zguiSetNextItemAllowOverlap; //-------------------------------------------------------------------------------------------------- const Begin = struct { popen: ?*bool = null, @@ -1457,6 +1468,9 @@ pub const getMouseCursor = zguiGetMouseCursor; pub const setMouseCursor = zguiSetMouseCursor; extern fn zguiGetMouseCursor() Cursor; extern fn zguiSetMouseCursor(cursor: Cursor) void; + +extern fn zguiSetNextFrameWantCaptureMouse(want_capture_mouse: bool) void; +pub const setNextFrameWantCaptureMouse = zguiSetNextFrameWantCaptureMouse; //-------------------------------------------------------------------------------------------------- pub fn getMousePos() [2]f32 { var pos: [2]f32 = undefined; @@ -1746,6 +1760,13 @@ pub fn progressBar(args: ProgressBar) void { zguiProgressBar(args.fraction, args.w, args.h, if (args.overlay) |o| o else null); } extern fn zguiProgressBar(fraction: f32, w: f32, h: f32, overlay: ?[*:0]const u8) void; +//-------------------------------------------------------------------------------------------------- +extern fn zguiTextLink(label: [*:0]const u8) bool; +pub const textLink = zguiTextLink; + +extern fn zguiTextLinkOpenURL(label: [*:0]const u8, url: ?[*:0]const u8) void; +pub const textLinkOpenURL = zguiTextLinkOpenURL; + //-------------------------------------------------------------------------------------------------- // // Widgets: Combo Box @@ -2995,6 +3016,9 @@ extern fn zguiTreePushPtrId(ptr_id: *const anyopaque) void; pub const treePop = zguiTreePop; extern fn zguiTreePop() void; //-------------------------------------------------------------------------------------------------- +extern fn zguiGetTreeNodeToLabelSpacing() f32; +pub const getTreeNodeToLabelSpacing = zguiGetTreeNodeToLabelSpacing; +//-------------------------------------------------------------------------------------------------- const CollapsingHeaderStatePtr = struct { pvisible: *bool, flags: TreeNodeFlags = .{}, @@ -3080,6 +3104,15 @@ pub fn beginListBox(label: [:0]const u8, args: BeginListBox) bool { pub const endListBox = zguiEndListBox; extern fn zguiBeginListBox(label: [*:0]const u8, w: f32, h: f32) bool; extern fn zguiEndListBox() void; +extern fn zguiListBox(label: [*:0]const u8, current_item: *i32, items: [*]const [*:0]const u8, item_count: i32, height_in_items: i32) bool; +pub const ListBox = struct { + current_item: *i32, + items: []const [*:0]const u8, + height_in_items: i32 = -1, +}; +pub fn listBox(label: [*:0]const u8, args: ListBox) bool { + return zguiListBox(label, args.current_item, args.items.ptr, @intCast(args.items.len), args.height_in_items); +} //-------------------------------------------------------------------------------------------------- // // Widgets: Tables @@ -3313,6 +3346,12 @@ extern fn zguiTableGetColumnFlags(column_n: i32) TableColumnFlags; pub const tableSetColumnEnabled = zguiTableSetColumnEnabled; extern fn zguiTableSetColumnEnabled(column_n: i32, v: bool) void; +extern fn zguiTableGetHoveredColumn() i32; +pub fn tableGetHoveredColumn() ?i32 { + const index = zguiTableGetHoveredColumn(); + if (index == -1) return null else return index; +} + pub fn tableSetBgColor(args: struct { target: TableBgTarget, color: u32, @@ -3322,6 +3361,45 @@ pub fn tableSetBgColor(args: struct { } extern fn zguiTableSetBgColor(target: TableBgTarget, color: c_uint, column_n: c_int) void; +pub const Columns = struct { + count: i32 = 1, + id: ?[*:0]const u8 = null, + borders: bool = true, +}; +extern fn zguiColumns(count: i32, id: ?[*:0]const u8, borders: bool) void; +pub fn columns(args: Columns) void { + zguiColumns(args.count, args.id, args.borders); +} + +extern fn zguiNextColumn() void; +pub const nextColumn = zguiNextColumn; + +extern fn zguiGetColumnIndex() i32; +pub const getColumnIndex = zguiGetColumnIndex; + +pub const ColumnArgs = struct { + column_index: i32 = -1, +}; + +extern fn zguiGetColumnWidth(column_index: i32) f32; +pub fn getColumnWidth(args: ColumnArgs) f32 { + return zguiGetColumnWidth(args.column_index); +} + +extern fn zguiSetColumnWidth(column_index: i32, width: f32) void; +pub const setColumnWidth = zguiSetColumnWidth; + +extern fn zguiGetColumnOffset(column_index: i32) f32; +pub fn getColumnOffset(args: ColumnArgs) f32 { + return zguiGetColumnOffset(args.column_index); +} + +extern fn zguiSetColumnOffset(column_index: i32, offset_x: f32) void; +pub const setColumnOffset = zguiSetColumnOffset; + +extern fn zguiGetColumnsCount() i32; +pub const getColumnsCount = zguiGetColumnsCount; + //-------------------------------------------------------------------------------------------------- // // Item/Widgets Utilities and Query Functions @@ -3350,6 +3428,7 @@ pub const isMouseReleased = zguiIsMouseReleased; pub const isMouseDoubleClicked = zguiIsMouseDoubleClicked; /// `pub fn getMouseClickedCount(mouse_button: MouseButton) bool` pub const getMouseClickedCount = zguiGetMouseClickedCount; +pub const isAnyMouseDown = zguiIsAnyMouseDown; /// `pub fn isMouseDragging(mouse_button: MouseButton, lock_threshold: f32) bool` pub const isMouseDragging = zguiIsMouseDragging; /// `pub fn isItemClicked(mouse_button: MouseButton) bool` @@ -3377,6 +3456,7 @@ extern fn zguiIsMouseClicked(mouse_button: MouseButton) bool; extern fn zguiIsMouseReleased(mouse_button: MouseButton) bool; extern fn zguiIsMouseDoubleClicked(mouse_button: MouseButton) bool; extern fn zguiGetMouseClickedCount(mouse_button: MouseButton) u32; +extern fn zguiIsAnyMouseDown() bool; extern fn zguiIsMouseDragging(mouse_button: MouseButton, lock_threshold: f32) bool; extern fn zguiIsItemHovered(flags: HoveredFlags) bool; extern fn zguiIsItemActive() bool; @@ -3452,6 +3532,11 @@ pub fn isKeyReleased(key: Key) bool { pub fn setNextFrameWantCaptureKeyboard(want_capture_keyboard: bool) void { zguiSetNextFrameWantCaptureKeyboard(want_capture_keyboard); } +extern fn zguiGetKeyPressedAmount(key: Key, repeat_delay: f32, rate: f32) i32; +pub const getKeyPressedAmount = zguiGetKeyPressedAmount; + +extern fn zguiSetItemKeyOwner(key: Key) void; +pub const setItemKeyOwner = zguiSetItemKeyOwner; extern fn zguiIsKeyDown(key: Key) bool; extern fn zguiIsKeyPressed(key: Key, repeat: bool) bool; @@ -3652,6 +3737,10 @@ extern fn zguiBeginTabItem(label: [*:0]const u8, p_open: ?*bool, flags: TabItemF extern fn zguiEndTabItem() void; extern fn zguiEndTabBar() void; extern fn zguiSetTabItemClosed(tab_or_docked_window_label: [*:0]const u8) void; + +extern fn zguiTabItemButton(label: [*:0]const u8, flags: TabItemFlags) bool; +pub const tabItemButton = zguiTabItemButton; + //-------------------------------------------------------------------------------------------------- // // Viewport @@ -3885,6 +3974,9 @@ pub const getWindowDrawList = zguiGetWindowDrawList; pub const getBackgroundDrawList = zguiGetBackgroundDrawList; pub const getForegroundDrawList = zguiGetForegroundDrawList; +extern fn zguiGetWindowDpiScale() f32; +pub const getWindowDpiScale = zguiGetWindowDpiScale; + pub const createDrawList = zguiCreateDrawList; pub fn destroyDrawList(draw_list: DrawList) void { if (draw_list.getOwnerName()) |owner| { diff --git a/src/zgui.cpp b/src/zgui.cpp index c69f9dd..85a723d 100644 --- a/src/zgui.cpp +++ b/src/zgui.cpp @@ -49,6 +49,11 @@ extern "C" ImGui::SetNextWindowSize({w, h}, cond); } + ZGUI_API void zguiSetNextWindowContentSize(float w, float h) + { + ImGui::SetNextWindowContentSize({w, h}); + } + ZGUI_API void zguiSetNextWindowCollapsed(bool collapsed, ImGuiCond cond) { ImGui::SetNextWindowCollapsed(collapsed, cond); @@ -58,6 +63,11 @@ extern "C" { ImGui::SetNextWindowFocus(); } + + ZGUI_API void zguiSetNextWindowScroll(float scroll_x, float scroll_y) + { + ImGui::SetNextWindowScroll({scroll_x, scroll_y}); + } ZGUI_API void zguiSetNextWindowBgAlpha(float alpha) { @@ -74,6 +84,16 @@ extern "C" ImGui::SetKeyboardFocusHere(offset); } + ZGUI_API void zguiSetNavCursorVisible(bool visible) + { + ImGui::SetNavCursorVisible(visible); + } + + ZGUI_API void zguiSetNextItemAllowOverlap() + { + ImGui::SetNextItemAllowOverlap(); + } + ZGUI_API bool zguiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags) { return ImGui::Begin(name, p_open, flags); @@ -337,6 +357,11 @@ extern "C" ImGui::SetMouseCursor(cursor); } + ZGUI_API void zguiSetNextFrameWantCaptureMouse(bool want_capture_mouse) + { + ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse); + } + ZGUI_API void zguiGetMousePos(float pos[2]) { const ImVec2 p = ImGui::GetMousePos(); @@ -619,6 +644,11 @@ extern "C" ImGui::EndListBox(); } + ZGUI_API bool zguiListBox(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items) + { + return ImGui::ListBox(label, current_item, items, items_count, height_in_items); + } + ZGUI_API bool zguiSelectable(const char *label, bool selected, ImGuiSelectableFlags flags, float w, float h) { return ImGui::Selectable(label, selected, flags, {w, h}); @@ -1127,6 +1157,14 @@ extern "C" return ImGui::ProgressBar(fraction, {w, h}, overlay); } + ZGUI_API bool zguiTextLink(const char* label) { + return ImGui::TextLink(label) ; + } + + ZGUI_API void zguiTextLinkOpenURL(const char* label, const char* url) { + ImGui::TextLinkOpenURL(label, url) ; + } + ZGUI_API ImGuiContext *zguiCreateContext(ImFontAtlas *shared_font_atlas) { return ImGui::CreateContext(shared_font_atlas); @@ -1384,6 +1422,11 @@ extern "C" ImGui::TreePush(str_id); } + ZGUI_API float zguiGetTreeNodeToLabelSpacing() + { + return ImGui::GetTreeNodeToLabelSpacing(); + } + ZGUI_API void zguiTreePushPtrId(const void *ptr_id) { ImGui::TreePush(ptr_id); @@ -1651,6 +1694,11 @@ extern "C" return ImGui::GetMouseClickedCount(button); } + ZGUI_API bool zguiIsAnyMouseDown() + { + return ImGui::IsAnyMouseDown(); + } + ZGUI_API bool zguiIsMouseDragging(ImGuiMouseButton button, float lock_threshold) { return ImGui::IsMouseDragging(button, lock_threshold); @@ -1764,6 +1812,11 @@ extern "C" ImGui::EndTabBar(); } + ZGUI_API bool zguiTabItemButton(const char* label, ImGuiTabItemFlags flags ) + { + return ImGui::TabItemButton(label, flags); + } + ZGUI_API void zguiSetTabItemClosed(const char *tab_or_docked_window_label) { ImGui::SetTabItemClosed(tab_or_docked_window_label); @@ -1952,10 +2005,56 @@ extern "C" ImGui::TableSetColumnEnabled(column_n, v); } + ZGUI_API int zguiTableGetHoveredColumn() + { + return ImGui::TableGetHoveredColumn(); + } + ZGUI_API void zguiTableSetBgColor(ImGuiTableBgTarget target, ImU32 color, int column_n) { ImGui::TableSetBgColor(target, color, column_n); } + + ZGUI_API void zguiColumns(int count , const char* id , bool borders) + { + ImGui::Columns(); + } + + ZGUI_API void zguiNextColumn() + { + ImGui::NextColumn(); + } + + ZGUI_API int zguiGetColumnIndex() + { + return ImGui::GetColumnIndex(); + } + + ZGUI_API float zguiGetColumnWidth(int column_index) //-1 + { + return ImGui::GetColumnWidth(column_index); + } + + ZGUI_API void zguiSetColumnWidth(int column_index, float width) + { + ImGui::SetColumnWidth(column_index, width); + } + + ZGUI_API float zguiGetColumnOffset(int column_index ) //-1 + { + return ImGui::GetColumnOffset(column_index); + } + + ZGUI_API void zguiSetColumnOffset(int column_index, float offset_x) + { + ImGui::SetColumnOffset(column_index, offset_x); + } + + ZGUI_API int zguiGetColumnsCount() + { + return ImGui::GetColumnsCount(); + } + //-------------------------------------------------------------------------------------------------- // // Color Utilities @@ -1993,18 +2092,31 @@ extern "C" { return ImGui::IsKeyDown(key); } + ZGUI_API bool zguiIsKeyPressed(ImGuiKey key, bool repeat) { return ImGui::IsKeyPressed(key, repeat); } + ZGUI_API bool zguiIsKeyReleased(ImGuiKey key) { return ImGui::IsKeyReleased(key); } + ZGUI_API void zguiSetNextFrameWantCaptureKeyboard(bool want_capture_keyboard) { ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } + + ZGUI_API int zguiGetKeyPressedAmount(ImGuiKey key, float repeat_delay, float rate) + { + return ImGui::GetKeyPressedAmount(key, repeat_delay, rate); + } + + ZGUI_API void zguiSetItemKeyOwner(ImGuiKey key) + { + ImGui::SetItemKeyOwner(key); + } //-------------------------------------------------------------------------------------------------- // // DrawList @@ -2015,6 +2127,11 @@ extern "C" return ImGui::GetWindowDrawList(); } + ZGUI_API float zguiGetWindowDpiScale(void) + { + return ImGui::GetWindowDpiScale(); + } + ZGUI_API ImDrawList *zguiGetBackgroundDrawList(void) { return ImGui::GetBackgroundDrawList(); From 88d7a04cd4c386fd89709778889319076b8ed1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tarkan=20sar=C4=B1ta=C5=9F?= Date: Thu, 1 May 2025 09:45:43 +0300 Subject: [PATCH 2/3] added setWindowFontScale --- src/gui.zig | 3 +++ src/zgui.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/gui.zig b/src/gui.zig index ac583cc..503e645 100644 --- a/src/gui.zig +++ b/src/gui.zig @@ -731,6 +731,9 @@ pub fn setWindowFocus(name: ?[:0]const u8) void { } extern fn zguiSetWindowFocus(name: ?[*:0]const u8) void; //------------------------------------------------------------------------------------------------- +extern fn zguiSetWindowFontScale(scale: f32) void; +pub const setWindowFontScale = zguiSetWindowFontScale; +//------------------------------------------------------------------------------------------------- pub fn setKeyboardFocusHere(offset: i32) void { zguiSetKeyboardFocusHere(offset); } diff --git a/src/zgui.cpp b/src/zgui.cpp index 85a723d..4764ea2 100644 --- a/src/zgui.cpp +++ b/src/zgui.cpp @@ -79,6 +79,11 @@ extern "C" ImGui::SetWindowFocus(name); } + ZGUI_API void zguiSetWindowFontScale(float scale) + { + ImGui::SetWindowFontScale(scale); + } + ZGUI_API void zguiSetKeyboardFocusHere(int offset) { ImGui::SetKeyboardFocusHere(offset); From 2883ec31a995ec91e0227415e6f42baa9569b48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tarkan=20sar=C4=B1ta=C5=9F?= Date: Mon, 5 May 2025 04:17:25 +0300 Subject: [PATCH 3/3] cleanup --- src/gui.zig | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/gui.zig b/src/gui.zig index 503e645..ee540fb 100644 --- a/src/gui.zig +++ b/src/gui.zig @@ -3350,10 +3350,7 @@ pub const tableSetColumnEnabled = zguiTableSetColumnEnabled; extern fn zguiTableSetColumnEnabled(column_n: i32, v: bool) void; extern fn zguiTableGetHoveredColumn() i32; -pub fn tableGetHoveredColumn() ?i32 { - const index = zguiTableGetHoveredColumn(); - if (index == -1) return null else return index; -} +pub const tableGetHoveredColumn = zguiTableGetHoveredColumn; pub fn tableSetBgColor(args: struct { target: TableBgTarget, @@ -3380,22 +3377,14 @@ pub const nextColumn = zguiNextColumn; extern fn zguiGetColumnIndex() i32; pub const getColumnIndex = zguiGetColumnIndex; -pub const ColumnArgs = struct { - column_index: i32 = -1, -}; - extern fn zguiGetColumnWidth(column_index: i32) f32; -pub fn getColumnWidth(args: ColumnArgs) f32 { - return zguiGetColumnWidth(args.column_index); -} +pub const getColumnWidth = zguiGetColumnWidth; extern fn zguiSetColumnWidth(column_index: i32, width: f32) void; pub const setColumnWidth = zguiSetColumnWidth; extern fn zguiGetColumnOffset(column_index: i32) f32; -pub fn getColumnOffset(args: ColumnArgs) f32 { - return zguiGetColumnOffset(args.column_index); -} +pub const getColumnOffset = zguiGetColumnOffset; extern fn zguiSetColumnOffset(column_index: i32, offset_x: f32) void; pub const setColumnOffset = zguiSetColumnOffset;