feat: update to 068e90b418b7da440a15db6495f2a37239d30bff

This commit is contained in:
2024-09-08 18:52:23 -05:00
parent c461e29eaa
commit 58b5f87a95
66 changed files with 41337 additions and 5176 deletions

300
src/gizmo.zig Normal file
View File

@@ -0,0 +1,300 @@
const gui = @import("gui.zig");
const DrawList = gui.DrawList;
pub const Matrix = [16]f32;
pub const Vector = [3]f32;
/// [-x, -y, -z, x, y, z]
pub const Bounds = [6]f32;
pub const Operation = packed struct(u32) {
translate_x: bool = false,
translate_y: bool = false,
translate_z: bool = false,
rotate_x: bool = false,
rotate_y: bool = false,
rotate_z: bool = false,
rotate_screen: bool = false,
scale_x: bool = false,
scale_y: bool = false,
scale_z: bool = false,
bounds: bool = false,
scale_xu: bool = false,
scale_yu: bool = false,
scale_zu: bool = false,
_padding: u18 = 0,
pub fn translate() Operation {
return .{ .translate_x = true, .translate_y = true, .translate_z = true };
}
pub fn rotate() Operation {
return .{ .rotate_x = true, .rotate_y = true, .rotate_z = true };
}
pub fn scale() Operation {
return .{ .scale_x = true, .scale_y = true, .scale_z = true };
}
pub fn scaleU() Operation {
return .{ .scale_xu = true, .scale_yu = true, .scale_zu = true };
}
pub fn universal() Operation {
return .{
.translate_x = true,
.translate_y = true,
.translate_z = true,
.rotate_x = true,
.rotate_y = true,
.rotate_z = true,
.scale_xu = true,
.scale_yu = true,
.scale_zu = true,
};
}
};
pub const Mode = enum(u32) {
local,
world,
};
pub const Color = enum(u32) {
direction_x,
direction_y,
direction_z,
plane_x,
plane_y,
plane_z,
selection,
inactive,
translation_line,
scale_line,
rotation_using_border,
rotation_using_fill,
hatched_axis_lines,
text,
text_shadow,
};
pub const Style = extern struct {
translation_line_thickness: f32,
translation_line_arrow_size: f32,
rotation_line_thickness: f32,
rotation_outer_line_thickness: f32,
scale_line_thickness: f32,
scale_line_circle_size: f32,
hatched_axis_line_thickness: f32,
center_circle_size: f32,
colors: [@typeInfo(Color).Enum.fields.len][4]f32,
};
//---------------------------------------------------------------------------------------------------------------------|
pub fn setDrawList(draw_list: ?DrawList) void {
zguiGizmo_SetDrawlist(draw_list);
}
pub fn beginFrame() void {
zguiGizmo_BeginFrame();
}
pub fn setImGuiContext(ctx: *anyopaque) void {
zguiGizmo_SetImGuiContext(ctx);
}
pub fn isOver() bool {
return zguiGizmo_IsOver();
}
pub fn isUsing() bool {
return zguiGizmo_IsUsing();
}
pub fn isUsingAny() bool {
return zguiGizmo_IsUsingAny();
}
pub fn setEnabled(enable: bool) void {
zguiGizmo_Enable(enable);
}
pub fn decomposeMatrixToComponents(
matrix: *const Matrix,
translation: *Vector,
rotation: *Vector,
scale: *Vector,
) void {
zguiGizmo_DecomposeMatrixToComponents(&matrix[0], &translation[0], &rotation[0], &scale[0]);
}
pub fn recomposeMatrixFromComponents(
translation: *const Vector,
rotation: *const Vector,
scale: *const Vector,
matrix: *Matrix,
) void {
zguiGizmo_RecomposeMatrixFromComponents(&translation[0], &rotation[0], &scale[0], &matrix[0]);
}
pub fn setRect(x: f32, y: f32, width: f32, height: f32) void {
zguiGizmo_SetRect(x, y, width, height);
}
pub fn setOrthographic(is_orthographic: bool) void {
zguiGizmo_SetOrthographic(is_orthographic);
}
pub fn drawCubes(view: *const Matrix, projection: *const Matrix, matrices: []const Matrix) void {
zguiGizmo_DrawCubes(&view[0], &projection[0], &matrices[0][0], @as(i32, @intCast(matrices.len)));
}
pub fn drawGrid(view: *const Matrix, projection: *const Matrix, matrix: *const Matrix, grid_size: f32) void {
zguiGizmo_DrawGrid(&view[0], &projection[0], &matrix[0], grid_size);
}
pub fn manipulate(
view: *const Matrix,
projection: *const Matrix,
operation: Operation,
mode: Mode,
matrix: *Matrix,
opt: struct {
delta_matrix: ?*Matrix = null,
snap: ?*const Vector = null,
local_bounds: ?*const Bounds = null,
bounds_snap: ?*const Vector = null,
},
) bool {
return zguiGizmo_Manipulate(
&view[0],
&projection[0],
operation,
mode,
&matrix[0],
if (opt.delta_matrix) |arr| &arr[0] else null,
if (opt.snap) |arr| &arr[0] else null,
if (opt.local_bounds) |arr| &arr[0] else null,
if (opt.bounds_snap) |arr| &arr[0] else null,
);
}
/// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
/// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
/// other software are using the same mechanics. But just in case, you are now warned!
pub fn viewManipulate(
view: *Matrix,
length: f32,
position: *const [2]f32,
size: *const [2]f32,
background_color: u32,
) void {
zguiGizmo_ViewManipulate(&view[0], length, position, size, background_color);
}
/// Use this version if you did not call `manipulate` before and you are just using `viewManipulate`
pub fn viewManipulateIndependent(
view: *Matrix,
projection: *const Matrix,
operation: Operation,
mode: Mode,
matrix: *Matrix,
length: f32,
position: *const [2]f32,
size: *const [2]f32,
background_color: u32,
) void {
zguiGizmo_ViewManipulateIndependent(
&view[0],
&projection[0],
operation,
mode,
&matrix[0],
length,
position,
size,
background_color,
);
}
pub fn setID(id: i32) void {
zguiGizmo_SetID(id);
}
pub fn isOverOperation(op: Operation) bool {
return zguiGizmo_IsOverOperation(op);
}
pub fn allowAxisFlip(allowed: bool) void {
zguiGizmo_AllowAxisFlip(allowed);
}
pub fn setAxisLimit(limit: f32) void {
zguiGizmo_SetAxisLimit(limit);
}
pub fn setPlaneLimit(limit: f32) void {
zguiGizmo_SetPlaneLimit(limit);
}
pub fn getStyle() *Style {
return zguiGizmo_GetStyle();
}
//---------------------------------------------------------------------------------------------------------------------|
extern fn zguiGizmo_SetDrawlist(draw_list: ?DrawList) void;
extern fn zguiGizmo_BeginFrame() void;
extern fn zguiGizmo_SetImGuiContext(ctx: *anyopaque) void;
extern fn zguiGizmo_IsOver() bool;
extern fn zguiGizmo_IsUsing() bool;
extern fn zguiGizmo_IsUsingAny() bool;
extern fn zguiGizmo_Enable(enable: bool) void;
extern fn zguiGizmo_DecomposeMatrixToComponents(
matrix: *const f32,
translation: *f32,
rotation: *f32,
scale: *f32,
) void;
extern fn zguiGizmo_RecomposeMatrixFromComponents(
translation: *const f32,
rotation: *const f32,
scale: *const f32,
matrix: *f32,
) void;
extern fn zguiGizmo_SetRect(x: f32, y: f32, width: f32, height: f32) void;
extern fn zguiGizmo_SetOrthographic(is_orthographic: bool) void;
extern fn zguiGizmo_DrawCubes(view: *const f32, projection: *const f32, matrices: *const f32, matrix_count: i32) void;
extern fn zguiGizmo_DrawGrid(view: *const f32, projection: *const f32, matrix: *const f32, grid_size: f32) void;
extern fn zguiGizmo_Manipulate(
view: *const f32,
projection: *const f32,
operation: Operation,
mode: Mode,
matrix: *f32,
delta_matrix: ?*f32,
snap: ?*const f32,
local_bounds: ?*const f32,
bounds_snap: ?*const f32,
) bool;
extern fn zguiGizmo_ViewManipulate(
view: *f32,
length: f32,
position: *const [2]f32,
size: *const [2]f32,
background_color: u32,
) void;
extern fn zguiGizmo_ViewManipulateIndependent(
view: *f32,
projection: *const f32,
operation: Operation,
mode: Mode,
matrix: *f32,
length: f32,
position: *const [2]f32,
size: *const [2]f32,
background_color: u32,
) void;
extern fn zguiGizmo_SetID(id: i32) void;
extern fn zguiGizmo_IsOverOperation(op: Operation) bool;
extern fn zguiGizmo_AllowAxisFlip(value: bool) void;
extern fn zguiGizmo_SetAxisLimit(value: f32) void;
extern fn zguiGizmo_SetPlaneLimit(value: f32) void;
extern fn zguiGizmo_GetStyle() *Style;

View File

@@ -5,7 +5,10 @@
//
//--------------------------------------------------------------------------------------------------
pub const plot = @import("plot.zig");
pub const gizmo = @import("gizmo.zig");
pub const node_editor = @import("node_editor.zig");
pub const te = @import("te.zig");
pub const backend = switch (@import("zgui_options").backend) {
.glfw_wgpu => @import("backend_glfw_wgpu.zig"),
.glfw_opengl3 => @import("backend_glfw_opengl.zig"),
@@ -138,8 +141,9 @@ pub const ConfigFlags = packed struct(c_int) {
nav_no_capture_keyboard: bool = false,
no_mouse: bool = false,
no_mouse_cursor_change: bool = false,
no_keyboard: bool = false,
dock_enable: bool = false,
_pading0: u3 = 0,
_pading0: u2 = 0,
viewport_enable: bool = false,
_pading1: u3 = 0,
dpi_enable_scale_viewport: bool = false,
@@ -274,6 +278,9 @@ pub const io = struct {
pub const getWantTextInput = zguiIoGetWantTextInput;
extern fn zguiIoGetWantTextInput() bool;
pub const getFramerate = zguiIoFramerate;
extern fn zguiIoFramerate() f32;
pub fn setIniFilename(filename: ?[*:0]const u8) void {
zguiIoSetIniFilename(filename);
}
@@ -560,7 +567,6 @@ pub const WindowFlags = packed struct(c_int) {
pub const ChildFlags = packed struct(c_int) {
border: bool = false,
no_move: bool = false,
always_use_window_padding: bool = false,
resize_x: bool = false,
resize_y: bool = false,
@@ -568,6 +574,7 @@ pub const ChildFlags = packed struct(c_int) {
auto_resize_y: bool = false,
always_auto_resize: bool = false,
frame_style: bool = false,
nav_flattened: bool = false,
_padding: u23 = 0,
};
@@ -581,7 +588,8 @@ pub const SliderFlags = packed struct(c_int) {
logarithmic: bool = false,
no_round_to_format: bool = false,
no_input: bool = false,
_padding: u24 = 0,
wrap_around: bool = false,
_padding: u23 = 0,
};
//--------------------------------------------------------------------------------------------------
pub const ButtonFlags = packed struct(c_int) {
@@ -599,7 +607,7 @@ pub const Direction = enum(c_int) {
down = 3,
};
//--------------------------------------------------------------------------------------------------
pub const DataType = enum(c_int) { I8, U8, I16, U16, I32, U32, I64, U64, F32, F64 };
pub const DataType = enum(c_int) { I8, U8, I16, U16, I32, U32, I64, U64, F32, F64, BOOL };
//--------------------------------------------------------------------------------------------------
pub const Condition = enum(c_int) {
none = 0,
@@ -632,6 +640,9 @@ extern fn zguiGetDrawData() DrawData;
/// `pub fn showDemoWindow(popen: ?*bool) void`
pub const showDemoWindow = zguiShowDemoWindow;
extern fn zguiShowDemoWindow(popen: ?*bool) void;
pub const showMetricsWindow = zguiShowMetricsWindow;
extern fn zguiShowMetricsWindow(popen: ?*bool) void;
//--------------------------------------------------------------------------------------------------
//
// Windows
@@ -910,7 +921,8 @@ extern fn zguiDockSpace(str_id: [*:0]const u8, size: *const [2]f32, flags: DockN
pub fn DockSpace(str_id: [:0]const u8, size: [2]f32, flags: DockNodeFlags) Ident {
return zguiDockSpace(str_id.ptr, &size, flags);
}
extern fn zguiDockSpaceOverViewport(viewport: Viewport, flags: DockNodeFlags) Ident;
extern fn zguiDockSpaceOverViewport(dockspace_id: Ident, viewport: Viewport, flags: DockNodeFlags) Ident;
pub const DockSpaceOverViewport = zguiDockSpaceOverViewport;
//--------------------------------------------------------------------------------------------------
@@ -946,6 +958,38 @@ extern fn zguiDockBuilderSplitNode(
) Ident;
extern fn zguiDockBuilderFinish(node_id: Ident) void;
//--------------------------------------------------------------------------------------------------
//
// ListClipper
//
//--------------------------------------------------------------------------------------------------
pub const ListClipper = extern struct {
Ctx: *Context,
DisplayStart: c_int,
DisplayEnd: c_int,
ItemsCount: c_int,
ItemsHeight: f32,
StartPosY: f32,
TempData: *anyopaque,
pub const init = zguiListClipper_Init;
extern fn zguiListClipper_Init() ListClipper;
pub fn begin(self: *ListClipper, items_count: ?i32, items_height: ?f32) void {
zguiListClipper_Begin(self, items_count orelse std.math.maxInt(i32), items_height orelse -1.0);
}
extern fn zguiListClipper_Begin(self: *ListClipper, items_count: i32, items_height: f32) void;
pub const end = zguiListClipper_End;
extern fn zguiListClipper_End(self: *ListClipper) void;
pub const includeItemsByIndex = zguiListClipper_IncludeItemsByIndex;
extern fn zguiListClipper_IncludeItemsByIndex(self: *ListClipper, item_begin: i32, item_end: i32) void;
pub const step = zguiListClipper_Step;
extern fn zguiListClipper_Step(self: *ListClipper) bool;
};
//--------------------------------------------------------------------------------------------------
//
// Style
@@ -982,7 +1026,9 @@ pub const Style = extern struct {
tab_border_size: f32,
tab_min_width_for_close_button: f32,
tab_bar_border_size: f32,
tab_bar_overline_size: f32,
table_angled_header_angle: f32,
table_angled_headers_text_align: [2]f32,
color_button_position: Direction,
button_text_align: [2]f32,
selectable_text_align: [2]f32,
@@ -1061,11 +1107,13 @@ pub const StyleCol = enum(c_int) {
resize_grip,
resize_grip_hovered,
resize_grip_active,
tab,
tab_hovered,
tab_active,
tab_unfocused,
tab_unfocused_active,
tab,
tab_selected,
tab_selected_overline,
tab_dimmed,
tab_dimmed_selected,
tab_dimmed_selected_overline,
docking_preview,
docking_empty_bg,
plot_lines,
@@ -1077,6 +1125,7 @@ pub const StyleCol = enum(c_int) {
table_border_light,
table_row_bg,
table_row_bg_alt,
text_link,
text_selected_bg,
drag_drop_target,
nav_highlight,
@@ -1142,7 +1191,11 @@ pub const StyleVar = enum(c_int) {
grab_min_size, // 1f
grab_rounding, // 1f
tab_rounding, // 1f
tab_border_size, // 1f
tab_bar_border_size, // 1f
tab_bar_overline_size, // 1f
table_angled_headers_angle, // 1f
table_angled_headers_text_align, // 2f
button_text_align, // 2f
selectable_text_align, // 2f
separator_text_border_size, // 1f
@@ -2317,26 +2370,28 @@ extern fn zguiSliderAngle(
pub const InputTextFlags = packed struct(c_int) {
chars_decimal: bool = false,
chars_hexadecimal: bool = false,
chars_scientific: bool = false,
chars_uppercase: bool = false,
chars_no_blank: bool = false,
auto_select_all: bool = false,
allow_tab_input: bool = false,
enter_returns_true: bool = false,
escape_clears_all: bool = false,
ctrl_enter_for_new_line: bool = false,
read_only: bool = false,
password: bool = false,
always_overwrite: bool = false,
auto_select_all: bool = false,
parse_empty_ref_val: bool = false,
display_empty_ref_val: bool = false,
no_horizontal_scroll: bool = false,
no_undo_redo: bool = false,
callback_completion: bool = false,
callback_history: bool = false,
callback_always: bool = false,
callback_char_filter: bool = false,
allow_tab_input: bool = false,
ctrl_enter_for_new_line: bool = false,
no_horizontal_scroll: bool = false,
always_overwrite: bool = false,
read_only: bool = false,
password: bool = false,
no_undo_redo: bool = false,
chars_scientific: bool = false,
callback_resize: bool = false,
callback_edit: bool = false,
escape_clears_all: bool = false,
_padding: u11 = 0,
_padding: u9 = 0,
};
//--------------------------------------------------------------------------------------------------
pub const InputTextCallbackData = extern struct {
@@ -2790,9 +2845,10 @@ pub const TreeNodeFlags = packed struct(c_int) {
frame_padding: bool = false,
span_avail_width: bool = false,
span_full_width: bool = false,
span_text_width: bool = false,
span_all_columns: bool = false,
nav_left_jumps_back_here: bool = false,
_padding: u17 = 0,
_padding: u16 = 0,
pub const collapsing_header = TreeNodeFlags{
.framed = true,
@@ -2888,12 +2944,13 @@ extern fn zguiSetNextItemOpen(is_open: bool, cond: Condition) void;
//
//--------------------------------------------------------------------------------------------------
pub const SelectableFlags = packed struct(c_int) {
dont_close_popups: bool = false,
no_auto_close_popups: bool = false,
span_all_columns: bool = false,
allow_double_click: bool = false,
disabled: bool = false,
allow_overlap: bool = false,
_padding: u27 = 0,
highlight: bool = false,
_padding: u26 = 0,
};
//--------------------------------------------------------------------------------------------------
const Selectable = struct {
@@ -3022,7 +3079,10 @@ pub const TableFlags = packed struct(c_int) {
sort_multi: bool = false,
sort_tristate: bool = false,
_padding: u4 = 0,
// Miscellaneous
highlight_hovered_column: bool = false,
_padding: u3 = 0,
};
pub const TableRowFlags = packed struct(c_int) {
@@ -3206,8 +3266,14 @@ pub const MouseButton = enum(u32) {
pub const isMouseDown = zguiIsMouseDown;
/// `pub fn isMouseClicked(mouse_button: MouseButton) bool`
pub const isMouseClicked = zguiIsMouseClicked;
/// `pub fn isMouseReleased(mouse_button: MouseButton) bool`
pub const isMouseReleased = zguiIsMouseReleased;
/// `pub fn isMouseDoubleClicked(mouse_button: MouseButton) bool`
pub const isMouseDoubleClicked = zguiIsMouseDoubleClicked;
/// `pub fn getMouseClickedCount(mouse_button: MouseButton) bool`
pub const getMouseClickedCount = zguiGetMouseClickedCount;
/// `pub fn isMouseDragging(mouse_button: MouseButton, lock_threshold: f32) bool`
pub const isMouseDragging = zguiIsMouseDragging;
/// `pub fn isItemClicked(mouse_button: MouseButton) bool`
pub const isItemClicked = zguiIsItemClicked;
/// `pub fn isItemVisible() bool`
@@ -3230,7 +3296,10 @@ pub const isAnyItemActive = zguiIsAnyItemActive;
pub const isAnyItemFocused = zguiIsAnyItemFocused;
extern fn zguiIsMouseDown(mouse_button: MouseButton) bool;
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 zguiIsMouseDragging(mouse_button: MouseButton, lock_threshold: f32) bool;
extern fn zguiIsItemHovered(flags: HoveredFlags) bool;
extern fn zguiIsItemActive() bool;
extern fn zguiIsItemFocused() bool;
@@ -3244,6 +3313,9 @@ extern fn zguiIsItemToggledOpen() bool;
extern fn zguiIsAnyItemHovered() bool;
extern fn zguiIsAnyItemActive() bool;
extern fn zguiIsAnyItemFocused() bool;
pub const isRectVisible = zguiIsRectVisible;
extern fn zguiIsRectVisible(pos: *[2]f32) bool;
//--------------------------------------------------------------------------------------------------
//
// Color Utilities
@@ -3427,6 +3499,8 @@ pub const beginPopup = zguiBeginPopup;
pub const endPopup = zguiEndPopup;
/// `pub fn closeCurrentPopup() void`
pub const closeCurrentPopup = zguiCloseCurrentPopup;
/// `pub fn isPopupOpen(str_id: [:0]const u8, flags: PopupFlags) bool`
pub const isPopupOpen = zguiIsPopupOpen;
extern fn zguiBeginPopupContextWindow() bool;
extern fn zguiBeginPopupContextItem() bool;
extern fn zguiBeginPopupModal(name: [*:0]const u8, popen: ?*bool, flags: WindowFlags) bool;
@@ -3434,6 +3508,8 @@ 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;
extern fn zguiIsPopupOpen(str_id: [*:0]const u8, flags: PopupFlags) bool;
//--------------------------------------------------------------------------------------------------
//
// Tabs
@@ -3446,9 +3522,10 @@ pub const TabBarFlags = packed struct(c_int) {
no_close_with_middle_mouse_button: bool = false,
no_tab_list_scrolling_buttons: bool = false,
no_tooltip: bool = false,
draw_selected_overline: bool = false,
fitting_policy_resize_down: bool = false,
fitting_policy_scroll: bool = false,
_padding: u24 = 0,
_padding: u23 = 0,
};
pub const TabItemFlags = packed struct(c_int) {
unsaved_document: bool = false,
@@ -3566,9 +3643,11 @@ pub const DragDropFlags = packed struct(c_int) {
source_no_hold_open_to_others: bool = false,
source_allow_null_id: bool = false,
source_extern: bool = false,
source_auto_expire_payload: bool = false,
payload_auto_expire: bool = false,
payload_no_cross_context: bool = false,
payload_no_cross_process: bool = false,
_padding0: u4 = 0,
_padding0: u2 = 0,
accept_before_delivery: bool = false,
accept_no_draw_default_rect: bool = false,
@@ -4070,7 +4149,7 @@ pub const DrawList = *opaque {
&args.p,
args.r,
args.col,
args.num_segments,
@intCast(args.num_segments),
args.thickness,
);
}
@@ -4089,7 +4168,7 @@ pub const DrawList = *opaque {
col: u32,
num_segments: u32,
}) void {
zguiDrawList_AddNgonFilled(draw_list, &args.p, args.r, args.col, args.num_segments);
zguiDrawList_AddNgonFilled(draw_list, &args.p, args.r, args.col, @intCast(args.num_segments));
}
extern fn zguiDrawList_AddNgonFilled(
draw_list: DrawList,
@@ -4173,7 +4252,7 @@ pub const DrawList = *opaque {
&args.p4,
args.col,
args.thickness,
args.num_segments,
@intCast(args.num_segments),
);
}
extern fn zguiDrawList_AddBezierCubic(
@@ -4202,7 +4281,7 @@ pub const DrawList = *opaque {
&args.p3,
args.col,
args.thickness,
args.num_segments,
@intCast(args.num_segments),
);
}
extern fn zguiDrawList_AddBezierQuadratic(
@@ -4555,6 +4634,7 @@ test {
const testing = std.testing;
testing.refAllDeclsRecursive(@This());
if (@import("zgui_options").with_gizmo) testing.refAllDeclsRecursive(gizmo);
init(testing.allocator);
defer deinit();

501
src/node_editor.zig Normal file
View File

@@ -0,0 +1,501 @@
const std = @import("std");
const Style = extern struct {
node_padding: [4]f32 = .{ 8, 8, 8, 8 },
node_rounding: f32 = 12,
node_border_width: f32 = 1.5,
hovered_node_border_width: f32 = 3.5,
hover_node_border_offset: f32 = 0,
selected_node_border_width: f32 = 3.5,
selected_node_border_offset: f32 = 0,
pin_rounding: f32 = 4,
pin_border_width: f32 = 0,
link_strength: f32 = 100,
source_direction: [2]f32 = .{ 1, 0 },
target_direction: [2]f32 = .{ -1, 0 },
scroll_duration: f32 = 0.35,
flow_marker_distance: f32 = 30,
flow_speed: f32 = 150.0,
flow_duration: f32 = 2.0,
pivot_alignment: [2]f32 = .{ 0.5, 0.5 },
pivot_size: [2]f32 = .{ 0, 0 },
pivot_scale: [2]f32 = .{ 1, 1 },
pin_corners: f32 = 240,
pin_radius: f32 = 0,
pin_arrow_size: f32 = 0,
pin_arrow_width: f32 = 0,
group_rounding: f32 = 6,
group_border_width: f32 = 1,
highlight_connected_links: f32 = 0,
snap_link_to_pin_dir: f32 = 0,
colors: [@typeInfo(StyleColor).Enum.fields.len][4]f32,
pub fn getColor(style: Style, idx: StyleColor) [4]f32 {
return style.colors[@intCast(@intFromEnum(idx))];
}
pub fn setColor(style: *Style, idx: StyleColor, color: [4]f32) void {
style.colors[@intCast(@intFromEnum(idx))] = color;
}
};
const StyleColor = enum(c_int) {
bg,
grid,
node_bg,
node_border,
hov_node_border,
sel_node_border,
node_sel_rect,
node_sel_rect_border,
hov_link_border,
sel_link_border,
highlight_link_border,
link_sel_rect,
link_sel_rect_border,
pin_rect,
pin_rect_border,
flow,
flow_marker,
group_bg,
group_border,
count,
};
const StyleVar = enum(c_int) {
node_padding,
node_rounding,
node_border_width,
hovered_node_border_width,
selected_node_border_width,
pin_rounding,
pin_border_width,
link_strength,
source_direction,
target_direction,
scroll_duration,
flow_marker_distance,
flow_speed,
flow_duration,
pivot_alignment,
pivot_size,
pivot_scale,
pin_corners,
pin_radius,
pin_arrow_size,
pin_arrow_width,
group_rounding,
group_border_width,
highlight_connected_links,
snap_link_to_pin_dir,
hovered_node_border_offset,
selected_node_border_offset,
count,
};
pub const EditorContext = opaque {
pub fn create(config: Config) *EditorContext {
return node_editor_CreateEditor(&config);
}
extern fn node_editor_CreateEditor(config: *const Config) *EditorContext;
pub fn destroy(self: *EditorContext) void {
return node_editor_DestroyEditor(self);
}
extern fn node_editor_DestroyEditor(editor: *EditorContext) void;
};
const CanvasSizeMode = enum(c_int) {
FitVerticalView, // Previous view will be scaled to fit new view on Y axis
FitHorizontalView, // Previous view will be scaled to fit new view on X axis
CenterOnly, // Previous view will be centered on new view
};
const SaveNodeSettings = fn (nodeId: NodeId, data: [*]const u8, size: usize, reason: SaveReasonFlags, userPointer: *anyopaque) callconv(.C) bool;
const LoadNodeSettings = fn (nodeId: NodeId, data: [*]u8, userPointer: *anyopaque) callconv(.C) usize;
const SaveSettings = fn (data: [*]const u8, size: usize, reason: SaveReasonFlags, userPointer: *anyopaque) callconv(.C) bool;
const LoadSettings = fn (data: [*]u8, userPointer: *anyopaque) callconv(.C) usize;
const ConfigSession = fn (userPointer: *anyopaque) callconv(.C) void;
const _ImVector = extern struct {
Size: c_int = 0,
Capacity: c_int = 0,
Data: ?*anyopaque = null,
};
pub const Config = extern struct {
settings_file: ?*const u8 = null,
begin_save_session: ?*const ConfigSession = null,
end_save_session: ?*const ConfigSession = null,
save_settings: ?*const SaveSettings = null,
load_settings: ?*const LoadSettings = null,
save_node_settings: ?*const SaveNodeSettings = null,
load_node_settings: ?*const LoadNodeSettings = null,
user_pointer: ?*anyopaque = null,
custom_zoom_levels: _ImVector = .{},
canvas_size_mode: CanvasSizeMode = .FitVerticalView,
drag_button_index: c_int = 0,
select_button_index: c_int = 0,
navigate_button_index: c_int = 1,
context_menu_button_index: c_int = 1,
enable_smooth_zoom: bool = false,
smooth_zoom_power: f32 = 1.1,
};
//
// Editor
//
const SaveReasonFlags = packed struct(u32) {
navigation: bool,
position: bool,
size: bool,
selection: bool,
add_node: bool,
remove_node: bool,
user: bool,
_pad: u25,
};
pub fn setCurrentEditor(editor: ?*EditorContext) void {
node_editor_SetCurrentEditor(editor);
}
extern fn node_editor_SetCurrentEditor(editor: ?*EditorContext) void;
pub fn begin(id: [:0]const u8, size: [2]f32) void {
node_editor_Begin(id, &size);
}
extern fn node_editor_Begin(id: [*c]const u8, size: [*]const f32) void;
pub fn end() void {
node_editor_End();
}
extern fn node_editor_End() void;
pub fn showBackgroundContextMenu() bool {
return node_editor_ShowBackgroundContextMenu();
}
extern fn node_editor_ShowBackgroundContextMenu() bool;
pub fn showNodeContextMenu(id: *NodeId) bool {
return node_editor_ShowNodeContextMenu(id);
}
extern fn node_editor_ShowNodeContextMenu(id: *NodeId) bool;
pub fn showLinkContextMenu(id: *LinkId) bool {
return node_editor_ShowLinkContextMenu(id);
}
extern fn node_editor_ShowLinkContextMenu(id: *LinkId) bool;
pub fn showPinContextMenu(id: *PinId) bool {
return node_editor_ShowPinContextMenu(id);
}
extern fn node_editor_ShowPinContextMenu(id: *PinId) bool;
pub fn suspend_() void {
return node_editor_Suspend();
}
extern fn node_editor_Suspend() void;
pub fn resume_() void {
return node_editor_Resume();
}
extern fn node_editor_Resume() void;
pub fn navigateToContent(duration: f32) void {
node_editor_NavigateToContent(duration);
}
extern fn node_editor_NavigateToContent(duration: f32) void;
pub fn navigateToSelection(zoomIn: bool, duration: f32) void {
node_editor_NavigateToSelection(zoomIn, duration);
}
extern fn node_editor_NavigateToSelection(zoomIn: bool, duration: f32) void;
pub fn selectNode(nodeId: NodeId, append: bool) void {
node_editor_SelectNode(nodeId, append);
}
extern fn node_editor_SelectNode(nodeId: NodeId, append: bool) void;
pub fn selectLink(linkId: LinkId, append: bool) void {
node_editor_SelectLink(linkId, append);
}
extern fn node_editor_SelectLink(linkId: LinkId, append: bool) void;
//
// Node
//
const NodeId = u64;
pub fn beginNode(id: NodeId) void {
node_editor_BeginNode(id);
}
extern fn node_editor_BeginNode(id: NodeId) void;
pub fn endNode() void {
node_editor_EndNode();
}
extern fn node_editor_EndNode() void;
pub fn setNodePosition(id: NodeId, pos: [2]f32) void {
node_editor_SetNodePosition(id, &pos);
}
extern fn node_editor_SetNodePosition(id: NodeId, pos: [*]const f32) void;
pub fn getNodePosition(id: NodeId) [2]f32 {
var pos: [2]f32 = .{ 0, 0 };
node_editor_getNodePosition(id, &pos);
return pos;
}
extern fn node_editor_getNodePosition(id: NodeId, pos: [*]f32) void;
pub fn getNodeSize(id: NodeId) [2]f32 {
var size: [2]f32 = .{ 0, 0 };
node_editor_getNodeSize(id, &size);
return size;
}
extern fn node_editor_getNodeSize(id: NodeId, size: [*]f32) void;
pub fn deleteNode(id: NodeId) bool {
return node_editor_DeleteNode(id);
}
extern fn node_editor_DeleteNode(id: NodeId) bool;
//
// Pin
//
const PinId = u64;
const PinKind = enum(u32) {
input = 0,
output,
};
pub fn beginPin(id: PinId, kind: PinKind) void {
node_editor_BeginPin(id, kind);
}
extern fn node_editor_BeginPin(id: PinId, kind: PinKind) void;
pub fn endPin() void {
node_editor_EndPin();
}
extern fn node_editor_EndPin() void;
pub fn pinHadAnyLinks(pinId: PinId) bool {
return node_editor_PinHadAnyLinks(pinId);
}
extern fn node_editor_PinHadAnyLinks(pinId: PinId) bool;
pub fn pinRect(a: [2]f32, b: [2]f32) void {
node_editor_PinRect(&a, &b);
}
extern fn node_editor_PinRect(a: [*]const f32, b: [*]const f32) void;
pub fn pinPivotRect(a: [2]f32, b: [2]f32) void {
node_editor_PinPivotRect(&a, &b);
}
extern fn node_editor_PinPivotRect(a: [*]const f32, b: [*]const f32) void;
pub fn pinPivotSize(size: [2]f32) void {
node_editor_PinPivotSize(&size);
}
extern fn node_editor_PinPivotSize(size: [*]const f32) void;
pub fn pinPivotScale(scale: [2]f32) void {
node_editor_PinPivotScale(&scale);
}
extern fn node_editor_PinPivotScale(scale: [*]const f32) void;
pub fn pinPivotAlignment(alignment: [2]f32) void {
node_editor_PinPivotAlignment(&alignment);
}
extern fn node_editor_PinPivotAlignment(alignment: [*]const f32) void;
//
// Link
//
const LinkId = u64;
pub fn link(id: LinkId, startPinId: PinId, endPinId: PinId, color: [4]f32, thickness: f32) bool {
return node_editor_Link(id, startPinId, endPinId, &color, thickness);
}
extern fn node_editor_Link(id: LinkId, startPinId: PinId, endPinId: PinId, color: [*]const f32, thickness: f32) bool;
pub fn deleteLink(id: LinkId) bool {
return node_editor_DeleteLink(id);
}
extern fn node_editor_DeleteLink(id: LinkId) bool;
pub fn breakPinLinks(id: PinId) i32 {
return node_editor_BreakPinLinks(id);
}
extern fn node_editor_BreakPinLinks(id: PinId) c_int;
//
// Created
//
pub fn beginCreate() bool {
return node_editor_BeginCreate();
}
extern fn node_editor_BeginCreate() bool;
pub fn endCreate() void {
node_editor_EndCreate();
}
extern fn node_editor_EndCreate() void;
pub fn queryNewLink(startId: *?PinId, endId: *?PinId) bool {
var sid: PinId = 0;
var eid: PinId = 0;
const result = node_editor_QueryNewLink(&sid, &eid);
startId.* = if (sid == 0) null else sid;
endId.* = if (eid == 0) null else eid;
return result;
}
extern fn node_editor_QueryNewLink(startId: *PinId, endId: *PinId) bool;
pub fn acceptNewItem(color: [4]f32, thickness: f32) bool {
return node_editor_AcceptNewItem(&color, thickness);
}
extern fn node_editor_AcceptNewItem(color: [*]const f32, thickness: f32) bool;
pub fn rejectNewItem(color: [4]f32, thickness: f32) void {
node_editor_RejectNewItem(&color, thickness);
}
extern fn node_editor_RejectNewItem(color: [*]const f32, thickness: f32) void;
//
// Deleted
//
pub fn beginDelete() bool {
return node_editor_BeginDelete();
}
extern fn node_editor_BeginDelete() bool;
pub fn endDelete() void {
node_editor_EndDelete();
}
extern fn node_editor_EndDelete() void;
pub fn queryDeletedLink(linkId: *LinkId, startId: ?*PinId, endId: ?*PinId) bool {
const result = node_editor_QueryDeletedLink(linkId, startId, endId);
return result;
}
extern fn node_editor_QueryDeletedLink(linkId: *LinkId, startId: ?*PinId, endId: ?*PinId) bool;
pub fn queryDeletedNode(nodeId: *NodeId) bool {
var nid: LinkId = 0;
const result = node_editor_QueryDeletedNode(&nid);
nodeId.* = nid;
return result;
}
extern fn node_editor_QueryDeletedNode(nodeId: *NodeId) bool;
pub fn acceptDeletedItem(deleteDependencies: bool) bool {
return node_editor_AcceptDeletedItem(deleteDependencies);
}
extern fn node_editor_AcceptDeletedItem(deleteDependencies: bool) bool;
pub fn rejectDeletedItem() void {
node_editor_RejectDeletedItem();
}
extern fn node_editor_RejectDeletedItem() void;
//
// Style
//
pub fn getStyle() Style {
return node_editor_GetStyle();
}
extern fn node_editor_GetStyle() Style;
pub fn getStyleColorName(colorIndex: StyleColor) [*c]const u8 {
return node_editor_GetStyleColorName(colorIndex);
}
extern fn node_editor_GetStyleColorName(colorIndex: StyleColor) [*c]const u8;
pub fn pushStyleColor(colorIndex: StyleColor, color: [4]f32) void {
node_editor_PushStyleColor(colorIndex, &color);
}
extern fn node_editor_PushStyleColor(colorIndex: StyleColor, color: [*]const f32) void;
pub fn popStyleColor(count: c_int) void {
node_editor_PopStyleColor(count);
}
extern fn node_editor_PopStyleColor(count: c_int) void;
pub fn pushStyleVar1f(varIndex: StyleVar, value: f32) void {
node_editor_PushStyleVarF(varIndex, value);
}
extern fn node_editor_PushStyleVarF(varIndex: StyleVar, value: f32) void;
pub fn pushStyleVar2f(varIndex: StyleVar, value: [2]f32) void {
node_editor_PushStyleVar2f(varIndex, &value);
}
extern fn node_editor_PushStyleVar2f(varIndex: StyleVar, value: [*]const f32) void;
pub fn pushStyleVar4f(varIndex: StyleVar, value: [4]f32) void {
node_editor_PushStyleVar4f(varIndex, &value);
}
extern fn node_editor_PushStyleVar4f(varIndex: StyleVar, value: [*]const f32) void;
pub fn popStyleVar(count: c_int) void {
node_editor_PopStyleVar(count);
}
extern fn node_editor_PopStyleVar(count: c_int) void;
//
// Selection
//
pub fn hasSelectionChanged() bool {
return node_editor_HasSelectionChanged();
}
extern fn node_editor_HasSelectionChanged() bool;
pub fn getSelectedObjectCount() c_int {
return node_editor_GetSelectedObjectCount();
}
extern fn node_editor_GetSelectedObjectCount() c_int;
pub fn clearSelection() void {
node_editor_ClearSelection();
}
extern fn node_editor_ClearSelection() void;
pub fn getSelectedNodes(nodes: []NodeId) c_int {
return node_editor_GetSelectedNodes(nodes.ptr, @intCast(nodes.len));
}
extern fn node_editor_GetSelectedNodes(nodes: [*]NodeId, size: c_int) c_int;
pub fn getSelectedLinks(links: []LinkId) c_int {
return node_editor_GetSelectedLinks(links.ptr, @intCast(links.len));
}
extern fn node_editor_GetSelectedLinks(links: [*]LinkId, size: c_int) c_int;
pub fn group(size: [2]f32) void {
node_editor_Group(&size);
}
extern fn node_editor_Group(size: [*]const f32) void;
//
// Drawlist
//
pub fn getHintForegroundDrawList() *anyopaque {
return node_editor_GetHintForegroundDrawList();
}
extern fn node_editor_GetHintForegroundDrawList() *anyopaque;
pub fn getHintBackgroundDrawLis() *anyopaque {
return node_editor_GetHintBackgroundDrawList();
}
extern fn node_editor_GetHintBackgroundDrawList() *anyopaque;
pub fn getNodeBackgroundDrawList(node_id: NodeId) *anyopaque {
return node_editor_GetNodeBackgroundDrawList(node_id);
}
extern fn node_editor_GetNodeBackgroundDrawList(node_id: NodeId) *anyopaque;

View File

@@ -210,6 +210,13 @@ extern fn zguiPlot_PushStyleVar1f(idx: StyleVar, v: f32) void;
extern fn zguiPlot_PushStyleVar2f(idx: StyleVar, v: *const [2]f32) void;
extern fn zguiPlot_PopStyleVar(count: i32) void;
//--------------------------------------------------------------------------------------------------
pub fn getLastItemColor() [4]f32 {
var color: [4]f32 = undefined;
zguiPlot_GetLastItemColor(&color);
return color;
}
extern fn zguiPlot_GetLastItemColor(color: *[4]f32) void;
//----------------------------------------------------------------------------------------------
pub const PlotLocation = packed struct(u32) {
north: bool = false,
south: bool = false,
@@ -306,11 +313,10 @@ pub const Flags = packed struct(u32) {
no_inputs: bool = false,
no_menus: bool = false,
no_box_select: bool = false,
no_child: bool = false,
no_frame: bool = false,
equal: bool = false,
crosshairs: bool = false,
_padding: u22 = 0,
_padding: u23 = 0,
pub const canvas_only = Flags{
.no_title = true,
@@ -537,6 +543,92 @@ extern fn zguiPlot_PlotShaded(
stride: i32,
) void;
//----------------------------------------------------------------------------------------------
pub const BarsFlags = packed struct(u32) {
_reserved0: bool = false,
_reserved1: bool = false,
_reserved2: bool = false,
_reserved3: bool = false,
_reserved4: bool = false,
_reserved5: bool = false,
_reserved6: bool = false,
_reserved7: bool = false,
_reserved8: bool = false,
_reserved9: bool = false,
horizontal: bool = false,
_padding: u21 = 0,
};
fn PlotBarsGen(comptime T: type) type {
return struct {
xv: []const T,
yv: []const T,
bar_size: f64 = 0.67,
flags: BarsFlags = .{},
offset: i32 = 0,
stride: i32 = @sizeOf(T),
};
}
pub fn plotBars(label_id: [:0]const u8, comptime T: type, args: PlotBarsGen(T)) void {
assert(args.xv.len == args.yv.len);
zguiPlot_PlotBars(
label_id,
gui.typeToDataTypeEnum(T),
args.xv.ptr,
args.yv.ptr,
@as(i32, @intCast(args.xv.len)),
args.bar_size,
args.flags,
args.offset,
args.stride,
);
}
extern fn zguiPlot_PlotBars(
label_id: [*:0]const u8,
data_type: gui.DataType,
xv: *const anyopaque,
yv: *const anyopaque,
count: i32,
bar_size: f64,
flags: BarsFlags,
offset: i32,
stride: i32,
) void;
fn PlotBarsValuesGen(comptime T: type) type {
return struct {
v: []const T,
bar_size: f64 = 0.0,
shift: f64 = 0.0,
flags: BarsFlags = .{},
offset: i32 = 0,
stride: i32 = @sizeOf(T),
};
}
pub fn plotBarsValues(label_id: [:0]const u8, comptime T: type, args: PlotBarsValuesGen(T)) void {
assert(args.xv.len == args.yv.len);
zguiPlot_PlotBars(
label_id,
gui.typeToDataTypeEnum(T),
args.v.ptr,
@as(i32, @intCast(args.xv.len)),
args.bar_size,
args.shift,
args.flags,
args.offset,
args.stride,
);
}
extern fn zguiPlot_PlotBarsValues(
label_id: [*:0]const u8,
data_type: gui.DataType,
values: *const anyopaque,
count: i32,
bar_size: f64,
shift: f64,
flags: BarsFlags,
offset: i32,
stride: i32,
) void;
//----------------------------------------------------------------------------------------------
pub const DragToolFlags = packed struct(u32) {
no_cursors: bool = false,
no_fit: bool = false,
@@ -585,6 +677,11 @@ extern fn zguiPlot_PlotText(
flags: PlotTextFlags,
) void;
//----------------------------------------------------------------------------------------------
pub fn isPlotHovered() bool {
return zguiPlot_IsPlotHovered();
}
extern fn zguiPlot_IsPlotHovered() bool;
//----------------------------------------------------------------------------------------------
/// `pub fn showDemoWindow(popen: ?*bool) void`
pub const showDemoWindow = zguiPlot_ShowDemoWindow;

173
src/zgizmo.cpp Normal file
View File

@@ -0,0 +1,173 @@
#include "imgui.h"
#include "ImGuizmo.h"
#include "imgui_internal.h"
#ifndef ZGUI_API
#define ZGUI_API
#endif
//--------------------------------------------------------------------------------------------------
//
// ImGuizmo
//
//--------------------------------------------------------------------------------------------------
extern "C"
{
ZGUI_API void zguiGizmo_SetDrawlist(ImDrawList *drawlist)
{
ImGuizmo::SetDrawlist(drawlist);
}
ZGUI_API void zguiGizmo_BeginFrame()
{
ImGuizmo::BeginFrame();
}
ZGUI_API void zguiGizmo_SetImGuiContext(ImGuiContext *ctx)
{
ImGuizmo::SetImGuiContext(ctx);
}
ZGUI_API bool zguiGizmo_IsOver()
{
return ImGuizmo::IsOver();
}
ZGUI_API bool zguiGizmo_IsUsing()
{
return ImGuizmo::IsUsing();
}
ZGUI_API bool zguiGizmo_IsUsingAny()
{
return ImGuizmo::IsUsingAny();
}
ZGUI_API void zguiGizmo_Enable(bool enable)
{
ImGuizmo::Enable(enable);
}
ZGUI_API void zguiGizmo_DecomposeMatrixToComponents(
const float *matrix,
float *translation,
float *rotation,
float *scale)
{
ImGuizmo::DecomposeMatrixToComponents(matrix, translation, rotation, scale);
}
ZGUI_API void zguiGizmo_RecomposeMatrixFromComponents(
const float *translation,
const float *rotation,
const float *scale,
float *matrix)
{
ImGuizmo::RecomposeMatrixFromComponents(translation, rotation, scale, matrix);
}
ZGUI_API void zguiGizmo_SetRect(float x, float y, float width, float height)
{
ImGuizmo::SetRect(x, y, width, height);
}
ZGUI_API void zguiGizmo_SetOrthographic(bool isOrthographic)
{
ImGuizmo::SetOrthographic(isOrthographic);
}
ZGUI_API void zguiGizmo_DrawCubes(const float *view, const float *projection, const float *matrices, int matrixCount)
{
ImGuizmo::DrawCubes(view, projection, matrices, matrixCount);
}
ZGUI_API void zguiGizmo_DrawGrid(
const float *view,
const float *projection,
const float *matrix,
const float gridSize)
{
ImGuizmo::DrawGrid(view, projection, matrix, gridSize);
}
ZGUI_API bool zguiGizmo_Manipulate(
const float *view,
const float *projection,
ImGuizmo::OPERATION operation,
ImGuizmo::MODE mode,
float *matrix,
float *deltaMatrix = NULL,
const float *snap = NULL,
const float *localBounds = NULL,
const float *boundsSnap = NULL)
{
return ImGuizmo::Manipulate(view, projection, operation, mode, matrix, deltaMatrix, snap, localBounds, boundsSnap);
}
//
// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
// other software are using the same mechanics. But just in case, you are now warned!
//
ZGUI_API void zguiGizmo_ViewManipulate(
float *view,
float length,
const float position[2],
const float size[2],
ImU32 backgroundColor)
{
const ImVec2 p(position[0], position[1]);
const ImVec2 s(size[0], size[1]);
ImGuizmo::ViewManipulate(view, length, p, s, backgroundColor);
}
// use this version if you did not call Manipulate before and you are just using ViewManipulate
ZGUI_API void zguiGizmo_ViewManipulateIndependent(
float *view,
const float *projection,
ImGuizmo::OPERATION operation,
ImGuizmo::MODE mode,
float *matrix,
float length,
const float position[2],
const float size[2],
ImU32 backgroundColor)
{
const ImVec2 p(position[0], position[1]);
const ImVec2 s(size[0], size[1]);
ImGuizmo::ViewManipulate(view, projection, operation, mode, matrix, length, p, s, backgroundColor);
}
ZGUI_API void zguiGizmo_SetID(int id)
{
ImGuizmo::SetID(id);
}
ZGUI_API bool zguiGizmo_IsOverOperation(ImGuizmo::OPERATION op)
{
return ImGuizmo::IsOver(op);
}
ZGUI_API void zguiGizmo_AllowAxisFlip(bool value)
{
ImGuizmo::AllowAxisFlip(value);
}
ZGUI_API void zguiGizmo_SetAxisLimit(float value)
{
ImGuizmo::SetAxisLimit(value);
}
ZGUI_API void zguiGizmo_SetPlaneLimit(float value)
{
ImGuizmo::SetPlaneLimit(value);
}
ZGUI_API ImGuizmo::Style *zguiGizmo_GetStyle()
{
return &ImGuizmo::GetStyle();
}
} /* extern "C" */

File diff suppressed because it is too large Load Diff

339
src/znode_editor.cpp Normal file
View File

@@ -0,0 +1,339 @@
#include "imgui.h"
#include "../node_editor/imgui_node_editor.h"
#ifndef ZGUI_API
#define ZGUI_API
#endif
//--------------------------------------------------------------------------------------------------
//
// ImGUI Node editor
//
//--------------------------------------------------------------------------------------------------
namespace ed = ax::NodeEditor;
extern "C"
{
//
// Editor
//
ZGUI_API ed::EditorContext *node_editor_CreateEditor(ed::Config *cfg)
{
return ed::CreateEditor(cfg);
}
ZGUI_API void node_editor_DestroyEditor(ed::EditorContext *editor)
{
return ed::DestroyEditor(editor);
}
ZGUI_API void node_editor_SetCurrentEditor(ed::EditorContext *editor)
{
return ed::SetCurrentEditor(editor);
}
ZGUI_API void node_editor_Begin(const char *id, const float size[2])
{
ed::Begin(id, ImVec2(size[0], size[1]));
}
ZGUI_API void node_editor_End()
{
ed::End();
}
ZGUI_API bool node_editor_ShowBackgroundContextMenu()
{
return ed::ShowBackgroundContextMenu();
}
ZGUI_API bool node_editor_ShowNodeContextMenu(ed::NodeId *id)
{
return ed::ShowNodeContextMenu(id);
}
ZGUI_API bool node_editor_ShowLinkContextMenu(ed::LinkId *id)
{
return ed::ShowLinkContextMenu(id);
}
ZGUI_API bool node_editor_ShowPinContextMenu(ed::PinId *id)
{
return ed::ShowPinContextMenu(id);
}
ZGUI_API void node_editor_Suspend()
{
ed::Suspend();
}
ZGUI_API void node_editor_Resume()
{
ed::Resume();
}
ZGUI_API void node_editor_NavigateToContent(float duration)
{
ed::NavigateToContent(duration);
}
ZGUI_API void node_editor_NavigateToSelection(bool zoomIn, float duration)
{
ed::NavigateToSelection(zoomIn, duration);
}
ZGUI_API void node_editor_SelectNode(ed::NodeId nodeId, bool append)
{
ed::SelectNode(nodeId, append);
}
ZGUI_API void node_editor_SelectLink(ed::LinkId linkId, bool append)
{
ed::SelectLink(linkId, append);
}
//
// Node
//
ZGUI_API void node_editor_BeginNode(ed::NodeId id)
{
ed::BeginNode(id);
}
ZGUI_API void node_editor_EndNode()
{
ed::EndNode();
}
ZGUI_API void node_editor_SetNodePosition(ed::NodeId id, const float pos[2])
{
ed::SetNodePosition(id, ImVec2(pos[0], pos[1]));
}
ZGUI_API void node_editor_getNodePosition(ed::NodeId id, float *pos)
{
auto node_pos = ed::GetNodePosition(id);
pos[0] = node_pos.x;
pos[1] = node_pos.y;
}
ZGUI_API void node_editor_getNodeSize(ed::NodeId id, float *size)
{
auto node_size = ed::GetNodeSize(id);
size[0] = node_size.x;
size[1] = node_size.y;
}
ZGUI_API bool node_editor_DeleteNode(ed::NodeId id)
{
return ed::DeleteNode(id);
}
//
// Pin
//
ZGUI_API void node_editor_BeginPin(ed::PinId id, ed::PinKind kind)
{
ed::BeginPin(id, kind);
}
ZGUI_API void node_editor_EndPin()
{
ed::EndPin();
}
ZGUI_API bool node_editor_PinHadAnyLinks(ed::PinId pinId)
{
return ed::PinHadAnyLinks(pinId);
}
ZGUI_API void node_editor_PinRect(const float a[2], const float b[2])
{
ed::PinRect(ImVec2(a[0], a[1]), ImVec2(b[0], b[1]));
}
ZGUI_API void node_editor_PinPivotRect(const float a[2], const float b[2])
{
ed::PinPivotRect(ImVec2(a[0], a[1]), ImVec2(b[0], b[1]));
}
ZGUI_API void node_editor_PinPivotSize(const float size[2])
{
ed::PinPivotSize(ImVec2(size[0], size[1]));
}
ZGUI_API void node_editor_PinPivotScale(const float scale[2])
{
ed::PinPivotScale(ImVec2(scale[0], scale[1]));
}
ZGUI_API void node_editor_PinPivotAlignment(const float alignment[2])
{
ed::PinPivotAlignment(ImVec2(alignment[0], alignment[1]));
}
//
// Link
//
ZGUI_API bool node_editor_Link(ed::LinkId id, ed::PinId startPinId, ed::PinId endPinId, const float color[4], float thickness)
{
return ed::Link(id, startPinId, endPinId, ImVec4(color[0], color[1], color[2], color[3]), thickness);
}
ZGUI_API bool node_editor_DeleteLink(ed::LinkId id)
{
return ed::DeleteLink(id);
}
ZGUI_API int node_editor_BreakPinLinks(ed::PinId id)
{
return ed::BreakLinks(id);
}
// Groups
ZGUI_API void node_editor_Group(const float size[2])
{
ed::Group(ImVec2(size[0], size[1]));
}
// Created
ZGUI_API bool node_editor_BeginCreate()
{
return ed::BeginCreate();
}
ZGUI_API void node_editor_EndCreate()
{
ed::EndCreate();
}
ZGUI_API bool node_editor_QueryNewLink(ed::PinId *startId, ed::PinId *endId)
{
return ed::QueryNewLink(startId, endId);
}
ZGUI_API bool node_editor_AcceptNewItem(const float color[4], float thickness)
{
return ed::AcceptNewItem(ImVec4(color[0], color[1], color[2], color[3]), thickness);
}
ZGUI_API void node_editor_RejectNewItem(const float color[4], float thickness)
{
return ed::RejectNewItem(ImVec4(color[0], color[1], color[2], color[3]), thickness);
}
// Delete
ZGUI_API bool node_editor_BeginDelete()
{
return ed::BeginDelete();
}
ZGUI_API void node_editor_EndDelete()
{
ed::EndDelete();
}
ZGUI_API bool node_editor_QueryDeletedLink(ed::LinkId *linkId, ed::PinId *startId, ed::PinId *endId)
{
return ed::QueryDeletedLink(linkId, startId, endId);
}
ZGUI_API bool node_editor_QueryDeletedNode(ed::NodeId *nodeId)
{
return ed::QueryDeletedNode(nodeId);
}
ZGUI_API bool node_editor_AcceptDeletedItem(bool deleteDependencies)
{
return ed::AcceptDeletedItem(deleteDependencies);
}
ZGUI_API void node_editor_RejectDeletedItem()
{
ed::RejectDeletedItem();
}
// Style
ZGUI_API ax::NodeEditor::Style node_editor_GetStyle()
{
return ed::GetStyle();
}
ZGUI_API const char *node_editor_GetStyleColorName(ed::StyleColor colorIndex)
{
return ed::GetStyleColorName(colorIndex);
}
ZGUI_API void node_editor_PushStyleColor(ed::StyleColor colorIndex, const ImVec4 *color)
{
ed::PushStyleColor(colorIndex, *color);
}
ZGUI_API void node_editor_PopStyleColor(int count)
{
ed::PopStyleColor(count);
}
ZGUI_API void node_editor_PushStyleVarF(ed::StyleVar varIndex, float value)
{
ed::PushStyleVar(varIndex, value);
}
ZGUI_API void node_editor_PushStyleVar2f(ed::StyleVar varIndex, const ImVec2 *value)
{
ed::PushStyleVar(varIndex, *value);
}
ZGUI_API void node_editor_PushStyleVar4f(ed::StyleVar varIndex, const ImVec4 *value)
{
ed::PushStyleVar(varIndex, *value);
}
ZGUI_API void node_editor_PopStyleVar(int count)
{
ed::PopStyleVar(count);
}
// Selection
ZGUI_API bool node_editor_HasSelectionChanged()
{
return ed::HasSelectionChanged();
}
ZGUI_API int node_editor_GetSelectedObjectCount()
{
return ed::GetSelectedObjectCount();
}
ZGUI_API void node_editor_ClearSelection()
{
return ed::ClearSelection();
}
ZGUI_API int node_editor_GetSelectedNodes(ed::NodeId *nodes, int size)
{
return ed::GetSelectedNodes(nodes, size);
}
ZGUI_API int node_editor_GetSelectedLinks(ed::LinkId *links, int size)
{
return ed::GetSelectedLinks(links, size);
}
ZGUI_API ImDrawList *node_editor_GetHintForegroundDrawList()
{
return ed::GetHintForegroundDrawList();
}
ZGUI_API ImDrawList *node_editor_GetHintBackgroundDrawList()
{
return ed::GetHintBackgroundDrawList();
}
ZGUI_API ImDrawList *node_editor_GetNodeBackgroundDrawList(ed::NodeId nodeId)
{
return ed::GetNodeBackgroundDrawList(nodeId);
}
} /* extern "C" */

365
src/zplot.cpp Normal file
View File

@@ -0,0 +1,365 @@
#include "imgui.h"
#include "implot.h"
#include "imgui_internal.h"
#ifndef ZGUI_API
#define ZGUI_API
#endif
//--------------------------------------------------------------------------------------------------
//
// ImPlot
//
//--------------------------------------------------------------------------------------------------
extern "C"
{
ZGUI_API ImPlotContext *zguiPlot_CreateContext(void)
{
return ImPlot::CreateContext();
}
ZGUI_API void zguiPlot_DestroyContext(ImPlotContext *ctx)
{
ImPlot::DestroyContext(ctx);
}
ZGUI_API ImPlotContext *zguiPlot_GetCurrentContext(void)
{
return ImPlot::GetCurrentContext();
}
ZGUI_API ImPlotStyle zguiPlotStyle_Init(void)
{
return ImPlotStyle();
}
ZGUI_API ImPlotStyle *zguiPlot_GetStyle(void)
{
return &ImPlot::GetStyle();
}
ZGUI_API void zguiPlot_PushStyleColor4f(ImPlotCol idx, const float col[4])
{
ImPlot::PushStyleColor(idx, {col[0], col[1], col[2], col[3]});
}
ZGUI_API void zguiPlot_PushStyleColor1u(ImPlotCol idx, ImU32 col)
{
ImPlot::PushStyleColor(idx, col);
}
ZGUI_API void zguiPlot_PopStyleColor(int count)
{
ImPlot::PopStyleColor(count);
}
ZGUI_API void zguiPlot_PushStyleVar1i(ImPlotStyleVar idx, int var)
{
ImPlot::PushStyleVar(idx, var);
}
ZGUI_API void zguiPlot_PushStyleVar1f(ImPlotStyleVar idx, float var)
{
ImPlot::PushStyleVar(idx, var);
}
ZGUI_API void zguiPlot_PushStyleVar2f(ImPlotStyleVar idx, const float var[2])
{
ImPlot::PushStyleVar(idx, {var[0], var[1]});
}
ZGUI_API void zguiPlot_PopStyleVar(int count)
{
ImPlot::PopStyleVar(count);
}
ZGUI_API void zguiPlot_SetupLegend(ImPlotLocation location, ImPlotLegendFlags flags)
{
ImPlot::SetupLegend(location, flags);
}
ZGUI_API void zguiPlot_SetupAxis(ImAxis axis, const char *label, ImPlotAxisFlags flags)
{
ImPlot::SetupAxis(axis, label, flags);
}
ZGUI_API void zguiPlot_SetupAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond)
{
ImPlot::SetupAxisLimits(axis, v_min, v_max, cond);
}
ZGUI_API void zguiPlot_SetupFinish(void)
{
ImPlot::SetupFinish();
}
ZGUI_API bool zguiPlot_BeginPlot(const char *title_id, float width, float height, ImPlotFlags flags)
{
return ImPlot::BeginPlot(title_id, {width, height}, flags);
}
ZGUI_API void zguiPlot_PlotLineValues(
const char *label_id,
ImGuiDataType data_type,
const void *values,
int count,
double xscale,
double x0,
ImPlotLineFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotLine(label_id, (const ImS8 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotLine(label_id, (const ImU8 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotLine(label_id, (const ImS16 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotLine(label_id, (const ImU16 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotLine(label_id, (const ImS32 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotLine(label_id, (const ImU32 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotLine(label_id, (const float *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotLine(label_id, (const double *)values, count, xscale, x0, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotLine(
const char *label_id,
ImGuiDataType data_type,
const void *xv,
const void *yv,
int count,
ImPlotLineFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotLine(label_id, (const ImS8 *)xv, (const ImS8 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotLine(label_id, (const ImU8 *)xv, (const ImU8 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotLine(label_id, (const ImS16 *)xv, (const ImS16 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotLine(label_id, (const ImU16 *)xv, (const ImU16 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotLine(label_id, (const ImS32 *)xv, (const ImS32 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotLine(label_id, (const ImU32 *)xv, (const ImU32 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotLine(label_id, (const float *)xv, (const float *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotLine(label_id, (const double *)xv, (const double *)yv, count, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotScatter(
const char *label_id,
ImGuiDataType data_type,
const void *xv,
const void *yv,
int count,
ImPlotScatterFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotScatter(label_id, (const ImS8 *)xv, (const ImS8 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotScatter(label_id, (const ImU8 *)xv, (const ImU8 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotScatter(label_id, (const ImS16 *)xv, (const ImS16 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotScatter(label_id, (const ImU16 *)xv, (const ImU16 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotScatter(label_id, (const ImS32 *)xv, (const ImS32 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotScatter(label_id, (const ImU32 *)xv, (const ImU32 *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotScatter(label_id, (const float *)xv, (const float *)yv, count, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotScatter(label_id, (const double *)xv, (const double *)yv, count, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotScatterValues(
const char *label_id,
ImGuiDataType data_type,
const void *values,
int count,
double xscale,
double x0,
ImPlotScatterFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotScatter(label_id, (const ImS8 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotScatter(label_id, (const ImU8 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotScatter(label_id, (const ImS16 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotScatter(label_id, (const ImU16 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotScatter(label_id, (const ImS32 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotScatter(label_id, (const ImU32 *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotScatter(label_id, (const float *)values, count, xscale, x0, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotScatter(label_id, (const double *)values, count, xscale, x0, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotShaded(
const char *label_id,
ImGuiDataType data_type,
const void *xv,
const void *yv,
int count,
double yref,
ImPlotShadedFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotShaded(label_id, (const ImS8 *)xv, (const ImS8 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotShaded(label_id, (const ImU8 *)xv, (const ImU8 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotShaded(label_id, (const ImS16 *)xv, (const ImS16 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotShaded(label_id, (const ImU16 *)xv, (const ImU16 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotShaded(label_id, (const ImS32 *)xv, (const ImS32 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotShaded(label_id, (const ImU32 *)xv, (const ImU32 *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotShaded(label_id, (const float *)xv, (const float *)yv, count, yref, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotShaded(label_id, (const double *)xv, (const double *)yv, count, yref, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotBars(
const char *label_id,
ImGuiDataType data_type,
const void *xv,
const void *yv,
int count,
double bar_size,
ImPlotBarsFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotBars(label_id, (const ImS8 *)xv, (const ImS8 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotBars(label_id, (const ImU8 *)xv, (const ImU8 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotBars(label_id, (const ImS16 *)xv, (const ImS16 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotBars(label_id, (const ImU16 *)xv, (const ImU16 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotBars(label_id, (const ImS32 *)xv, (const ImS32 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotBars(label_id, (const ImU32 *)xv, (const ImU32 *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotBars(label_id, (const float *)xv, (const float *)yv, count, bar_size, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotBars(label_id, (const double *)xv, (const double *)yv, count, bar_size, flags, offset, stride);
else
assert(false);
}
ZGUI_API void zguiPlot_PlotBarsValues(
const char *label_id,
ImGuiDataType data_type,
const void *values,
int count,
double bar_size,
double shift,
ImPlotBarsFlags flags,
int offset,
int stride)
{
if (data_type == ImGuiDataType_S8)
ImPlot::PlotBars(label_id, (const ImS8 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_U8)
ImPlot::PlotBars(label_id, (const ImU8 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_S16)
ImPlot::PlotBars(label_id, (const ImS16 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_U16)
ImPlot::PlotBars(label_id, (const ImU16 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_S32)
ImPlot::PlotBars(label_id, (const ImS32 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_U32)
ImPlot::PlotBars(label_id, (const ImU32 *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_Float)
ImPlot::PlotBars(label_id, (const float *)values, count, bar_size, shift, flags, offset, stride);
else if (data_type == ImGuiDataType_Double)
ImPlot::PlotBars(label_id, (const double *)values, count, bar_size, shift, flags, offset, stride);
else
assert(false);
}
ZGUI_API bool zguiPlot_IsPlotHovered()
{
return ImPlot::IsPlotHovered();
}
ZGUI_API void zguiPlot_GetLastItemColor(float color[4])
{
const ImVec4 col = ImPlot::GetLastItemColor();
color[0] = col.x;
color[1] = col.y;
color[2] = col.z;
color[3] = col.w;
}
ZGUI_API void zguiPlot_ShowDemoWindow(bool *p_open)
{
ImPlot::ShowDemoWindow(p_open);
}
ZGUI_API void zguiPlot_EndPlot(void)
{
ImPlot::EndPlot();
}
ZGUI_API bool zguiPlot_DragPoint(
int id,
double *x,
double *y,
float col[4],
float size,
ImPlotDragToolFlags flags)
{
return ImPlot::DragPoint(
id,
x,
y,
(*(const ImVec4 *)&(col[0])),
size,
flags);
}
ZGUI_API void zguiPlot_PlotText(
const char *text,
double x, double y,
const float pix_offset[2],
ImPlotTextFlags flags = 0)
{
const ImVec2 p(pix_offset[0], pix_offset[1]);
ImPlot::PlotText(text, x, y, p, flags);
}
} /* extern "C" */

163
src/zte.cpp Normal file
View File

@@ -0,0 +1,163 @@
#include "imgui.h"
#include "imgui_te_engine.h"
#include "imgui_te_context.h"
#include "imgui_te_ui.h"
#include "imgui_te_utils.h"
#include "imgui_te_exporters.h"
#include "imgui_internal.h"
#ifndef ZGUI_API
#define ZGUI_API
#endif
//--------------------------------------------------------------------------------------------------
//
// ImGUI Test Engine
//
//--------------------------------------------------------------------------------------------------
extern "C"
{
ZGUI_API void *zguiTe_CreateContext(void)
{
ImGuiTestEngine *e = ImGuiTestEngine_CreateContext();
ImGuiTestEngine_Start(e, ImGui::GetCurrentContext());
ImGuiTestEngine_InstallDefaultCrashHandler();
return e;
}
ZGUI_API void zguiTe_DestroyContext(ImGuiTestEngine *engine)
{
ImGuiTestEngine_DestroyContext(engine);
}
ZGUI_API void zguiTe_EngineSetRunSpeed(ImGuiTestEngine *engine, ImGuiTestRunSpeed speed)
{
ImGuiTestEngine_GetIO(engine).ConfigRunSpeed = speed;
}
ZGUI_API void zguiTe_EngineExportJunitResult(ImGuiTestEngine *engine, const char *filename)
{
ImGuiTestEngine_GetIO(engine).ExportResultsFilename = filename;
ImGuiTestEngine_GetIO(engine).ExportResultsFormat = ImGuiTestEngineExportFormat_JUnitXml;
}
ZGUI_API void zguiTe_TryAbortEngine(ImGuiTestEngine *engine)
{
ImGuiTestEngine_TryAbortEngine(engine);
}
ZGUI_API void zguiTe_Stop(ImGuiTestEngine *engine)
{
ImGuiTestEngine_Stop(engine);
}
ZGUI_API void zguiTe_PostSwap(ImGuiTestEngine *engine)
{
ImGuiTestEngine_PostSwap(engine);
}
ZGUI_API bool zguiTe_IsTestQueueEmpty(ImGuiTestEngine *engine)
{
return ImGuiTestEngine_IsTestQueueEmpty(engine);
}
ZGUI_API void zguiTe_GetResult(ImGuiTestEngine *engine, int *count_tested, int *count_success)
{
int ct = 0;
int cs = 0;
ImGuiTestEngine_GetResult(engine, ct, cs);
*count_tested = ct;
*count_success = cs;
}
ZGUI_API void zguiTe_PrintResultSummary(ImGuiTestEngine *engine)
{
ImGuiTestEngine_PrintResultSummary(engine);
}
ZGUI_API void zguiTe_QueueTests(ImGuiTestEngine *engine, ImGuiTestGroup group, const char *filter_str, ImGuiTestRunFlags run_flags)
{
ImGuiTestEngine_QueueTests(engine, group, filter_str, run_flags);
}
ZGUI_API void zguiTe_ShowTestEngineWindows(ImGuiTestEngine *engine, bool *p_open)
{
ImGuiTestEngine_ShowTestEngineWindows(engine, p_open);
}
ZGUI_API void *zguiTe_RegisterTest(ImGuiTestEngine *engine, const char *category, const char *name, const char *src_file, int src_line, ImGuiTestGuiFunc *gui_fce, ImGuiTestTestFunc *gui_test_fce)
{
auto t = ImGuiTestEngine_RegisterTest(engine, category, name, src_file, src_line);
t->GuiFunc = gui_fce;
t->TestFunc = gui_test_fce;
return t;
}
ZGUI_API bool zguiTe_Check(const char *file, const char *func, int line, ImGuiTestCheckFlags flags, bool result, const char *expr)
{
return ImGuiTestEngine_Check(file, func, line, flags, result, expr);
}
// CONTEXT
ZGUI_API void zguiTe_ContextSetRef(ImGuiTestContext *ctx, const char *ref)
{
ctx->SetRef(ref);
}
ZGUI_API void zguiTe_ContextWindowFocus(ImGuiTestContext *ctx, const char *ref)
{
ctx->WindowFocus(ref);
}
ZGUI_API void zguiTe_ContextItemAction(ImGuiTestContext *ctx, ImGuiTestAction action, const char *ref, ImGuiTestOpFlags flags = 0, void *action_arg = NULL)
{
ctx->ItemAction(action, ref, flags, action_arg);
}
ZGUI_API void zguiTe_ContextItemInputStrValue(ImGuiTestContext *ctx, const char *ref, const char *value)
{
ctx->ItemInputValue(ref, value);
}
ZGUI_API void zguiTe_ContextItemInputIntValue(ImGuiTestContext *ctx, const char *ref, int value)
{
ctx->ItemInputValue(ref, value);
}
ZGUI_API void zguiTe_ContextItemInputFloatValue(ImGuiTestContext *ctx, const char *ref, float value)
{
ctx->ItemInputValue(ref, value);
}
ZGUI_API void zguiTe_ContextYield(ImGuiTestContext *ctx, int frame_count)
{
ctx->Yield(frame_count);
}
ZGUI_API void zguiTe_ContextMenuAction(ImGuiTestContext *ctx, ImGuiTestAction action, const char *ref)
{
ctx->MenuAction(action, ref);
}
ZGUI_API void zguiTe_ContextDragAndDrop(ImGuiTestContext *ctx, const char *ref_src, const char *ref_dst, ImGuiMouseButton button)
{
ctx->ItemDragAndDrop(ref_src, ref_dst, button);
}
ZGUI_API void zguiTe_ContextKeyDown(ImGuiTestContext *ctx, ImGuiKeyChord key_chord)
{
ctx->KeyDown(key_chord);
}
ZGUI_API void zguiTe_ContextKeyUp(ImGuiTestContext *ctx, ImGuiKeyChord key_chord)
{
ctx->KeyUp(key_chord);
}
} /* extern "C" */