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
Show file tree
Hide file tree
Changes from 2 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
95 changes: 95 additions & 0 deletions src/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = .{},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3313,6 +3349,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,
Expand All @@ -3322,6 +3364,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
Expand Down Expand Up @@ -3350,6 +3431,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`
Expand Down Expand Up @@ -3377,6 +3459,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;
Expand Down Expand Up @@ -3452,6 +3535,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;
Expand Down Expand Up @@ -3652,6 +3740,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
Expand Down Expand Up @@ -3885,6 +3977,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| {
Expand Down
Loading
Loading