Skip to content

Added some necessary functions #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/gui.zig
Original file line number Diff line number Diff line change
@@ -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,
};
@@ -725,11 +731,19 @@ 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);
}
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 +1471,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 +1763,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 +3019,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 +3107,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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a redundant field? Can we just use the length of items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height_in_items indicates how many lines are visible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense, thanks!
What do you think about using ?u16 here instead?

};
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 +3349,9 @@ 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 const tableGetHoveredColumn = zguiTableGetHoveredColumn;

pub fn tableSetBgColor(args: struct {
target: TableBgTarget,
color: u32,
@@ -3322,6 +3361,37 @@ 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;

extern fn zguiGetColumnWidth(column_index: i32) f32;
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 const getColumnOffset = zguiGetColumnOffset;

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 +3420,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 +3448,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 +3524,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 +3729,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 +3966,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| {
122 changes: 122 additions & 0 deletions src/zgui.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
@@ -69,11 +79,26 @@ extern "C"
ImGui::SetWindowFocus(name);
}

ZGUI_API void zguiSetWindowFontScale(float scale)
{
ImGui::SetWindowFontScale(scale);
}

ZGUI_API void zguiSetKeyboardFocusHere(int offset)
{
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 +362,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 +649,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 +1162,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 +1427,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 +1699,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 +1817,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 +2010,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 +2097,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 +2132,11 @@ extern "C"
return ImGui::GetWindowDrawList();
}

ZGUI_API float zguiGetWindowDpiScale(void)
{
return ImGui::GetWindowDpiScale();
}

ZGUI_API ImDrawList *zguiGetBackgroundDrawList(void)
{
return ImGui::GetBackgroundDrawList();