Skip to content

Commit 9bba464

Browse files
author
Anthony Debucquoy
committed
0.15.1
1 parent 441f4ab commit 9bba464

File tree

1 file changed

+26
-117
lines changed

1 file changed

+26
-117
lines changed

src/gui.zig

Lines changed: 26 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn initWithExistingContext(allocator: std.mem.Allocator, ctx: Context) void
7272
cimgui.igSetCurrentContext(ctx);
7373

7474
temp_buffer = std.ArrayList(u8){};
75-
temp_buffer.?.resize(3 * 1024 + 1) catch unreachable;
75+
temp_buffer.?.resize(allocator, 3 * 1024 + 1) catch unreachable;
7676

7777
if (te_enabled) {
7878
te.init();
@@ -116,7 +116,7 @@ pub fn deinit() void {
116116
pub fn initNoContext() void {
117117
if (temp_buffer == null) {
118118
temp_buffer = std.ArrayList(u8){};
119-
temp_buffer.?.resize(3 * 1024 + 1) catch unreachable;
119+
temp_buffer.?.resize(mem_allocator, 3 * 1024 + 1) catch unreachable;
120120
}
121121
}
122122
pub fn deinitNoContext() void {
@@ -261,9 +261,8 @@ pub const io = struct {
261261
}
262262

263263
pub fn removeFont(font: Font) void {
264-
zguiIoRemoveFont(font);
264+
cimgui.ImFontAtlas_RemoveFont(GetIO().*.Fonts.*, font);
265265
}
266-
extern fn zguiIoRemoveFont(font: Font) void;
267266

268267
pub fn getFont(index: u32) Font {
269268
return GetIO().*.Fonts.*.Fonts.Data[index];
@@ -273,58 +272,9 @@ pub const io = struct {
273272
GetIO().*.FontDefault = font;
274273
}
275274

276-
277-
//TODO <tonitch>: Function not in imgui since 1.92.0
278-
// pub fn getFontsTextDataAsRgba32() struct {
279-
// width: i32,
280-
// height: i32,
281-
// pixels: ?[*]const u32,
282-
// } {
283-
// var width: i32 = undefined;
284-
// var height: i32 = undefined;
285-
// const ptr = zguiIoGetFontsTexDataAsRgba32(&width, &height);
286-
// return .{
287-
// .width = width,
288-
// .height = height,
289-
// .pixels = ptr,
290-
// };
291-
// }
292-
293-
294-
// TODO <tonitch>: can't find equivalent to ImGui::GetIO().Fonts->TexID = id;
295-
/// `pub fn setFontsTexId(id:TextureIdent) set the backend Id for the fonts atlas
296-
// pub const setFontsTexId = zguiIoSetFontsTexId;
297-
//
298-
// pub const getFontsTexId = zguiIoGetFontsTexId;
299-
300275
pub fn getGlyphRangesDefault() [*]const Wchar{
301276
return cimgui.ImFontAtlas_GetGlyphRangesDefault(GetIO().*.Fonts.*);
302277
}
303-
304-
// those functions are Obsolete since 1.92
305-
// pub const getGlyphRangesGreek = zguiIoGetGlyphRangesGreek;
306-
// pub fn getGlyphRangesGreek() [*]const Wchar;
307-
//
308-
// pub const getGlyphRangesKorean = zguiIoGetGlyphRangesKorean;
309-
// extern fn zguiIoGetGlyphRangesKorean() [*]const Wchar;
310-
//
311-
// pub const getGlyphRangesJapanese = zguiIoGetGlyphRangesJapanese;
312-
// extern fn zguiIoGetGlyphRangesJapanese() [*]const Wchar;
313-
//
314-
// pub const getGlyphRangesChineseFull = zguiIoGetGlyphRangesChineseFull;
315-
// extern fn zguiIoGetGlyphRangesChineseFull() [*]const Wchar;
316-
//
317-
// pub const getGlyphRangesChineseSimplifiedCommon = zguiIoGetGlyphRangesChineseSimplifiedCommon;
318-
// extern fn zguiIoGetGlyphRangesChineseSimplifiedCommon() [*]const Wchar;
319-
//
320-
// pub const getGlyphRangesCyrillic = zguiIoGetGlyphRangesCyrillic;
321-
// extern fn zguiIoGetGlyphRangesCyrillic() [*]const Wchar;
322-
//
323-
// pub const getGlyphRangesThai = zguiIoGetGlyphRangesThai;
324-
// extern fn zguiIoGetGlyphRangesThai() [*]const Wchar;
325-
//
326-
// pub const getGlyphRangesVietnamese = zguiIoGetGlyphRangesVietnamese;
327-
// extern fn zguiIoGetGlyphRangesVietnamese() [*]const Wchar;
328278

329279
pub fn setConfigWindowsMoveFromTitleBarOnly(enabled: bool) void{
330280
var IO = GetIO().*;
@@ -346,30 +296,16 @@ pub const io = struct {
346296
pub fn getFramerate() bool{
347297
return GetIO().*.Framerate;
348298
}
349-
// =======
350-
//
351-
// pub const getFontsTexRef = zguiIoGetFontsTexRef;
352-
// extern fn zguiIoGetFontsTexRef() TextureRef;
353-
//
354-
// /// `pub fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool) void`
355-
// pub const setConfigWindowsMoveFromTitleBarOnly = zguiIoSetConfigWindowsMoveFromTitleBarOnly;
356-
// extern fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(enabled: bool) void;
357-
//
358-
// /// `pub fn zguiIoGetWantCaptureMouse() bool`
359-
// pub const getWantCaptureMouse = zguiIoGetWantCaptureMouse;
360-
// extern fn zguiIoGetWantCaptureMouse() bool;
361-
//
362-
// /// `pub fn zguiIoGetWantCaptureKeyboard() bool`
363-
// pub const getWantCaptureKeyboard = zguiIoGetWantCaptureKeyboard;
364-
// extern fn zguiIoGetWantCaptureKeyboard() bool;
365-
//
366-
// /// `pub fn zguiIoGetWantTextInput() bool`
367-
// pub const getWantTextInput = zguiIoGetWantTextInput;
368-
// extern fn zguiIoGetWantTextInput() bool;
369-
//
370-
// pub const getFramerate = zguiIoFramerate;
371-
// extern fn zguiIoFramerate() f32;
372-
// >>>>>>> main
299+
300+
pub fn getFontsTexRef() TextureRef{
301+
return GetIO().*.Fonts.*.TexRef;
302+
303+
}
304+
305+
pub fn zguiIoGetWantTextInput() bool{
306+
return GetIO().*.WantTextInput;
307+
308+
}
373309

374310
pub fn setIniFilename(filename: ?[*:0]const u8) void {
375311
var IO = GetIO().*;
@@ -400,9 +336,10 @@ pub const io = struct {
400336
IO.DeltaTime = delta_time;
401337
}
402338

403-
/// `pub fn setBackendFlags(flags: BackendFlags) void`
404-
pub const setBackendFlags = zguiIoSetBackendFlags;
405-
extern fn zguiIoSetBackendFlags(flags: BackendFlags) void;
339+
pub fn setBackendFlags(flags: BackendFlags) void{
340+
var IO = GetIO().*;
341+
IO.BackendFlags = @bitCast(flags);
342+
}
406343

407344

408345
pub fn addFocusEvent(focused: bool) void{
@@ -451,28 +388,8 @@ pub const DrawData = *cimgui.ImDrawData;
451388
pub const Font = *cimgui.ImFont;
452389
pub const Ident = u32;
453390
pub const Vec2 = cimgui.ImVec2;
454-
pub const TextureIdent = cimgui.ImTextureID; //TODO <tonitch>: not sure, was *anyopaque
455-
// =======
456-
// pub const DrawData = *extern struct {
457-
// valid: bool,
458-
// cmd_lists_count: c_int,
459-
// total_idx_count: c_int,
460-
// total_vtx_count: c_int,
461-
// cmd_lists: Vector(DrawList),
462-
// display_pos: [2]f32,
463-
// display_size: [2]f32,
464-
// framebuffer_scale: [2]f32,
465-
// owner_viewport: ?*Viewport,
466-
// textures: *Vector(TextureIdent),
467-
// };
468-
// pub const Font = *opaque {};
469-
// pub const Ident = u32;
470-
// pub const TextureIdent = enum(u64) { _ };
471-
// pub const TextureRef = extern struct {
472-
// tex_data: ?*anyopaque,
473-
// tex_id: TextureIdent,
474-
// };
475-
// >>>>>>> main
391+
pub const TextureIdent = cimgui.ImTextureID;
392+
pub const TextureRef = cimgui.ImTextureRef;
476393
pub const Wchar = if (@import("zgui_options").use_wchar32) u32 else u16;
477394
pub const Key = enum(c_int) {
478395
none = 0,
@@ -955,7 +872,7 @@ pub const DockNodeFlags = packed struct(c_int) {
955872
};
956873

957874
pub fn DockSpace(str_id: [:0]const u8, size: Vec2, flags: DockNodeFlags) Ident {
958-
return cimgui.igDockSpace(cimgui.igGetID_Str, size, @bitCast(flags));
875+
return cimgui.igDockSpace(cimgui.igGetID_Str(str_id), size, @bitCast(flags));
959876
}
960877

961878
pub const DockSpaceOverViewport = cimgui.igDockSpaceOverViewport;
@@ -1657,21 +1574,13 @@ pub fn arrowButton(label: [:0]const u8, args: ArrowButton) bool {
16571574
extern fn zguiArrowButton(label: [*:0]const u8, dir: Direction) bool;
16581575
//--------------------------------------------------------------------------------------------------
16591576
const Image = struct {
1660-
w: f32,
1661-
h: f32,
1662-
uv0: [2]f32 = .{ 0.0, 0.0 },
1663-
uv1: [2]f32 = .{ 1.0, 1.0 },
1577+
size: Vec2,
1578+
uv0: Vec2 = .{ 0.0, 0.0 },
1579+
uv1: Vec2 = .{ 1.0, 1.0 },
16641580
};
16651581
pub fn image(user_texture_ref: TextureRef, args: Image) void {
1666-
zguiImage(user_texture_ref, args.w, args.h, &args.uv0, &args.uv1);
1582+
cimgui.igImage(user_texture_ref, args.size, args.uv0, args.uv1);
16671583
}
1668-
extern fn zguiImage(
1669-
user_texture_ref: TextureRef,
1670-
w: f32,
1671-
h: f32,
1672-
uv0: *const [2]f32,
1673-
uv1: *const [2]f32,
1674-
) void;
16751584
//--------------------------------------------------------------------------------------------------
16761585
const ImageWithBg = struct {
16771586
w: f32,
@@ -3615,12 +3524,12 @@ var temp_buffer: ?std.ArrayList(u8) = null;
36153524

36163525
pub fn format(comptime fmt: []const u8, args: anytype) []const u8 {
36173526
const len = std.fmt.count(fmt, args);
3618-
if (len > temp_buffer.?.items.len) temp_buffer.?.resize(@intCast(len + 64)) catch unreachable;
3527+
if (len > temp_buffer.?.items.len) temp_buffer.?.resize(mem_allocator.?, @intCast(len + 64)) catch unreachable;
36193528
return std.fmt.bufPrint(temp_buffer.?.items, fmt, args) catch unreachable;
36203529
}
36213530
pub fn formatZ(comptime fmt: []const u8, args: anytype) [:0]const u8 {
36223531
const len = std.fmt.count(fmt ++ "\x00", args);
3623-
if (len > temp_buffer.?.items.len) temp_buffer.?.resize(@intCast(len + 64)) catch unreachable;
3532+
if (len > temp_buffer.?.items.len) temp_buffer.?.resize(mem_allocator.?, @intCast(len + 64)) catch unreachable;
36243533
return std.fmt.bufPrintZ(temp_buffer.?.items, fmt, args) catch unreachable;
36253534
}
36263535
//--------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)