Skip to content

Commit 18eb01c

Browse files
author
Anthony Debucquoy
committed
Doing 14% of gui.zig file with cimgui function
I'm tired...
1 parent a96c137 commit 18eb01c

File tree

1 file changed

+135
-152
lines changed

1 file changed

+135
-152
lines changed

src/gui.zig

Lines changed: 135 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ pub const FontBuilderFlags = packed struct(c_uint) {
198198
pub const FontConfig = cimgui.ImFontConfig();
199199

200200
pub const io = struct {
201+
pub const GetIO = cimgui.igGetIO_Nil;
202+
201203
pub fn addFontDefault(config: ?FontConfig) Font {
202-
const fonts = cimgui.igGetIO_Nil().*.Fonts;
204+
const fonts = GetIO().*.Fonts;
203205
return cimgui.ImFontAtlas_AddFontDefault(fonts, config);
204206
}
205207

@@ -219,40 +221,39 @@ pub const io = struct {
219221
}
220222

221223
pub fn addFontFromMemory(fontdata: []const u8, size_pixels: f32) Font {
222-
return zguiIoAddFontFromMemory(fontdata.ptr, @intCast(fontdata.len), size_pixels);
224+
const config = cimgui.ImFontConfig_ImFontConfig();
225+
config.*.FontDataOwnedByAtlas = false;
226+
227+
return cimgui.ImFontAtlas_AddFontFromMemoryTTF(
228+
GetIO().*.Fonts.*,
229+
fontdata.ptr, @intCast(fontdata.len),
230+
size_pixels,
231+
&config,
232+
null);
223233
}
224-
extern fn zguiIoAddFontFromMemory(font_data: *const anyopaque, font_size: c_int, size_pixels: f32) Font;
225234

226235
pub fn addFontFromMemoryWithConfig(
227236
fontdata: []const u8,
228237
size_pixels: f32,
229238
config: ?FontConfig,
230239
ranges: ?[*]const Wchar,
231240
) Font {
232-
return zguiIoAddFontFromMemoryWithConfig(
233-
fontdata.ptr,
234-
@intCast(fontdata.len),
241+
return cimgui.ImFontAtlas_AddFontFromMemoryTTF(
242+
GetIO().*.Fonts.*,
243+
fontdata.ptr, @intCast(fontdata.len),
235244
size_pixels,
236245
if (config) |c| &c else null,
237246
ranges,
238247
);
239248
}
240-
extern fn zguiIoAddFontFromMemoryWithConfig(
241-
font_data: *const anyopaque,
242-
font_size: c_int,
243-
size_pixels: f32,
244-
config: ?*const FontConfig,
245-
ranges: ?[*]const Wchar,
246-
) Font;
247249

248250
pub fn getFont(index: u32) Font {
249-
return zguiIoGetFont(index);
251+
return GetIO().*.Fonts.*.Fonts.Data[index];
250252
}
251-
extern fn zguiIoGetFont(index: c_uint) Font;
252253

253-
/// `pub fn setDefaultFont(font: Font) void`
254-
pub const setDefaultFont = zguiIoSetDefaultFont;
255-
extern fn zguiIoSetDefaultFont(font: Font) void;
254+
pub fn setDefaultFont(font: Font) void{
255+
GetIO().*.FontDefault = font;
256+
}
256257

257258

258259
//TODO <tonitch>: Function not in imgui since 1.92.0
@@ -272,145 +273,137 @@ pub const io = struct {
272273
// }
273274

274275

276+
// TODO <tonitch>: can't find equivalent to ImGui::GetIO().Fonts->TexID = id;
275277
/// `pub fn setFontsTexId(id:TextureIdent) set the backend Id for the fonts atlas
276-
pub const setFontsTexId = zguiIoSetFontsTexId;
277-
extern fn zguiIoSetFontsTexId(id: TextureIdent) void;
278-
279-
pub const getFontsTexId = zguiIoGetFontsTexId;
280-
extern fn zguiIoGetFontsTexId() TextureIdent;
281-
282-
pub const getGlyphRangesDefault = zguiIoGetGlyphRangesDefault;
283-
extern fn zguiIoGetGlyphRangesDefault() [*]const Wchar;
284-
285-
pub const getGlyphRangesGreek = zguiIoGetGlyphRangesGreek;
286-
extern fn zguiIoGetGlyphRangesGreek() [*]const Wchar;
287-
288-
pub const getGlyphRangesKorean = zguiIoGetGlyphRangesKorean;
289-
extern fn zguiIoGetGlyphRangesKorean() [*]const Wchar;
290-
291-
pub const getGlyphRangesJapanese = zguiIoGetGlyphRangesJapanese;
292-
extern fn zguiIoGetGlyphRangesJapanese() [*]const Wchar;
278+
// pub const setFontsTexId = zguiIoSetFontsTexId;
279+
//
280+
// pub const getFontsTexId = zguiIoGetFontsTexId;
293281

294-
pub const getGlyphRangesChineseFull = zguiIoGetGlyphRangesChineseFull;
295-
extern fn zguiIoGetGlyphRangesChineseFull() [*]const Wchar;
296-
297-
pub const getGlyphRangesChineseSimplifiedCommon = zguiIoGetGlyphRangesChineseSimplifiedCommon;
298-
extern fn zguiIoGetGlyphRangesChineseSimplifiedCommon() [*]const Wchar;
299-
300-
pub const getGlyphRangesCyrillic = zguiIoGetGlyphRangesCyrillic;
301-
extern fn zguiIoGetGlyphRangesCyrillic() [*]const Wchar;
302-
303-
pub const getGlyphRangesThai = zguiIoGetGlyphRangesThai;
304-
extern fn zguiIoGetGlyphRangesThai() [*]const Wchar;
305-
306-
pub const getGlyphRangesVietnamese = zguiIoGetGlyphRangesVietnamese;
307-
extern fn zguiIoGetGlyphRangesVietnamese() [*]const Wchar;
282+
pub fn getGlyphRangesDefault() [*]const Wchar{
283+
return cimgui.ImFontAtlas_GetGlyphRangesDefault(GetIO().*.Fonts.*);
284+
}
308285

309-
/// `pub fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool) void`
310-
pub const setConfigWindowsMoveFromTitleBarOnly = zguiIoSetConfigWindowsMoveFromTitleBarOnly;
311-
extern fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(enabled: bool) void;
286+
// those functions are Obsolete since 1.92
287+
// pub const getGlyphRangesGreek = zguiIoGetGlyphRangesGreek;
288+
// pub fn getGlyphRangesGreek() [*]const Wchar;
289+
//
290+
// pub const getGlyphRangesKorean = zguiIoGetGlyphRangesKorean;
291+
// extern fn zguiIoGetGlyphRangesKorean() [*]const Wchar;
292+
//
293+
// pub const getGlyphRangesJapanese = zguiIoGetGlyphRangesJapanese;
294+
// extern fn zguiIoGetGlyphRangesJapanese() [*]const Wchar;
295+
//
296+
// pub const getGlyphRangesChineseFull = zguiIoGetGlyphRangesChineseFull;
297+
// extern fn zguiIoGetGlyphRangesChineseFull() [*]const Wchar;
298+
//
299+
// pub const getGlyphRangesChineseSimplifiedCommon = zguiIoGetGlyphRangesChineseSimplifiedCommon;
300+
// extern fn zguiIoGetGlyphRangesChineseSimplifiedCommon() [*]const Wchar;
301+
//
302+
// pub const getGlyphRangesCyrillic = zguiIoGetGlyphRangesCyrillic;
303+
// extern fn zguiIoGetGlyphRangesCyrillic() [*]const Wchar;
304+
//
305+
// pub const getGlyphRangesThai = zguiIoGetGlyphRangesThai;
306+
// extern fn zguiIoGetGlyphRangesThai() [*]const Wchar;
307+
//
308+
// pub const getGlyphRangesVietnamese = zguiIoGetGlyphRangesVietnamese;
309+
// extern fn zguiIoGetGlyphRangesVietnamese() [*]const Wchar;
310+
311+
pub fn setConfigWindowsMoveFromTitleBarOnly(enabled: bool) void{
312+
var IO = GetIO().*;
313+
IO.ConfigWindowsMoveFromTitleBarOnly = enabled;
314+
}
312315

313-
/// `pub fn zguiIoGetWantCaptureMouse() bool`
314-
pub const getWantCaptureMouse = zguiIoGetWantCaptureMouse;
315-
extern fn zguiIoGetWantCaptureMouse() bool;
316+
pub fn getWantCaptureMouse() bool{
317+
return GetIO().*.WantCaptureMouse;
318+
}
316319

317-
/// `pub fn zguiIoGetWantCaptureKeyboard() bool`
318-
pub const getWantCaptureKeyboard = zguiIoGetWantCaptureKeyboard;
319-
extern fn zguiIoGetWantCaptureKeyboard() bool;
320+
pub fn getWantCaptureKeyboard() bool{
321+
return GetIO().*.WantCaptureKeyboard;
322+
}
320323

321-
/// `pub fn zguiIoGetWantTextInput() bool`
322-
pub const getWantTextInput = zguiIoGetWantTextInput;
323-
extern fn zguiIoGetWantTextInput() bool;
324+
pub fn getWantTextInput() bool{
325+
return GetIO().*.WantTextInput;
326+
}
324327

325-
pub const getFramerate = zguiIoFramerate;
326-
extern fn zguiIoFramerate() f32;
328+
pub fn getFramerate() bool{
329+
return GetIO().*.Framerate;
330+
}
327331

328332
pub fn setIniFilename(filename: ?[*:0]const u8) void {
329-
var IO = cimgui.igGetIO_Nil().*;
333+
var IO = GetIO().*;
330334
IO.IniFilename = filename;
331335
}
332-
extern fn zguiIoSetIniFilename(filename: ?[*:0]const u8) void;
333336

334-
/// `pub fn setDisplaySize(width: f32, height: f32) void`
335337
pub fn setDisplaySize(width: f32, height: f32) void{
336-
var IO = cimgui.igGetIO_Nil().*;
337-
IO.DisplaySize.x = width;
338-
IO.DisplaySize.y = height;
338+
var IO = GetIO().*;
339+
IO.DisplaySize = .{.x = width, .y = height};
339340
}
340341

341342
pub fn getDisplaySize() [2]f32 {
342-
var size: [2]f32 = undefined;
343-
zguiIoGetDisplaySize(&size);
344-
return size;
343+
return @bitCast(GetIO().*.DisplaySize);
345344
}
346-
extern fn zguiIoGetDisplaySize(size: *[2]f32) void;
347345

348346
pub fn setDisplayFramebufferScale(sx: f32, sy: f32) void{
349-
const IO = cimgui.igGetIO_Nil();
350-
IO.*.DisplayFramebufferScale = .{.x = sx, .y = sy};
347+
var IO = GetIO().*;
348+
IO.DisplayFramebufferScale = .{.x = sx, .y = sy};
351349
}
352350

353-
/// `pub fn setConfigFlags(flags: ConfigFlags) void`
354-
pub const setConfigFlags = zguiIoSetConfigFlags;
355-
extern fn zguiIoSetConfigFlags(flags: ConfigFlags) void;
351+
pub fn setConfigFlags(flags: ConfigFlags) void{
352+
var IO = GetIO().*;
353+
IO.ConfigFlags = flags;
354+
}
356355

357-
/// `pub fn setDeltaTime(delta_time: f32) void`
358-
pub const setDeltaTime = zguiIoSetDeltaTime;
359-
extern fn zguiIoSetDeltaTime(delta_time: f32) void;
356+
pub fn setDeltaTime(delta_time: f32) void{
357+
var IO = GetIO().*;
358+
IO.DeltaTime = delta_time;
359+
}
360360

361-
pub const addFocusEvent = zguiIoAddFocusEvent;
362-
extern fn zguiIoAddFocusEvent(focused: bool) void;
361+
pub fn addFocusEvent(focused: bool) void{
362+
cimgui.ImGuiIO_AddFocusEvent(GetIO(), focused);
363+
}
363364

364-
pub const addMousePositionEvent = zguiIoAddMousePositionEvent;
365-
extern fn zguiIoAddMousePositionEvent(x: f32, y: f32) void;
365+
pub fn addMousePositionEvent(x: f32, y: f32) void{
366+
cimgui.ImGuiIO_AddMousePosEvent(GetIO(), x, y);
367+
}
366368

367-
pub const addMouseButtonEvent = zguiIoAddMouseButtonEvent;
368-
extern fn zguiIoAddMouseButtonEvent(button: MouseButton, down: bool) void;
369+
pub fn addMouseButtonEvent(btn: MouseButton, down: bool) void{
370+
cimgui.ImGuiIO_AddMouseButtonEvent(GetIO(), btn, down);
371+
}
369372

370-
pub const addMouseWheelEvent = zguiIoAddMouseWheelEvent;
371-
extern fn zguiIoAddMouseWheelEvent(x: f32, y: f32) void;
373+
pub fn addMouseWheelEvent(x: f32, y: f32) void{
374+
cimgui.ImGuiIO_AddMouseWheelEvent(GetIO(), x, y);
375+
}
372376

373-
pub const addKeyEvent = zguiIoAddKeyEvent;
374-
extern fn zguiIoAddKeyEvent(key: Key, down: bool) void;
377+
pub fn addKeyEvent(key: Key, down: bool) void{
378+
cimgui.ImGuiIO_AddKeyEvent(GetIO(), key, down);
379+
}
375380

376-
pub const addInputCharactersUTF8 = zguiIoAddInputCharactersUTF8;
377-
extern fn zguiIoAddInputCharactersUTF8(utf8_chars: ?[*:0]const u8) void;
381+
pub fn addInputCharactersUTF8(utf8_chars: ?[*:0]const u8) void{
382+
cimgui.ImGuiIO_AddInputCharactersUTF8(GetIO(), utf8_chars);
383+
}
378384

379385
pub fn setKeyEventNativeData(key: Key, keycode: i32, scancode: i32) void {
380-
zguiIoSetKeyEventNativeData(key, keycode, scancode);
386+
cimgui.ImGuiIO_SetKeyEventNativeData(GetIO(), key, keycode, scancode);
381387
}
382-
extern fn zguiIoSetKeyEventNativeData(key: Key, keycode: c_int, scancode: c_int) void;
383388

384389
pub fn addCharacterEvent(char: i32) void {
385-
zguiIoAddCharacterEvent(char);
390+
cimgui.ImGuiIO_AddInputCharacter(GetIO(), char);
386391
}
387-
extern fn zguiIoAddCharacterEvent(char: c_int) void;
388392
};
389393

390394
pub fn setClipboardText(value: [:0]const u8) void {
391-
zguiSetClipboardText(value.ptr);
395+
cimgui.igSetClipboardText(value);
392396
}
393397
pub fn getClipboardText() [:0]const u8 {
394-
const value = zguiGetClipboardText();
398+
const value = cimgui.igGetClipboardText();
395399
return std.mem.span(value);
396400
}
397-
extern fn zguiSetClipboardText(text: [*:0]const u8) void;
398-
extern fn zguiGetClipboardText() [*:0]const u8;
399401
//--------------------------------------------------------------------------------------------------
400402
pub const Context = *opaque {};
401-
pub const DrawData = *extern struct {
402-
valid: bool,
403-
cmd_lists_count: c_int,
404-
total_idx_count: c_int,
405-
total_vtx_count: c_int,
406-
cmd_lists: Vector(DrawList),
407-
display_pos: [2]f32,
408-
display_size: [2]f32,
409-
framebuffer_scale: [2]f32,
410-
};
411-
pub const Font = *opaque {};
403+
pub const DrawData = *cimgui.ImDrawData;
404+
pub const Font = *cimgui.ImFont;
412405
pub const Ident = u32;
413-
pub const TextureIdent = *anyopaque;
406+
pub const TextureIdent = cimgui.ImTextureID; //TODO <tonitch>: not sure, was *anyopaque
414407
pub const Wchar = if (@import("zgui_options").use_wchar32) u32 else u16;
415408
pub const Key = enum(c_int) {
416409
none = 0,
@@ -709,61 +702,51 @@ pub fn setNextWindowPos(args: SetNextWindowPos) void {
709702
cimgui.igSetNextWindowPos(.{.x = args.x, .y = args.y}, args.cond, .{.x = args.pivot_x, .y = args.pivot_y});
710703
}
711704
//--------------------------------------------------------------------------------------------------
712-
const SetNextWindowSize = struct {
713-
w: f32,
714-
h: f32,
715-
cond: Condition = .none,
716-
};
717-
pub fn setNextWindowSize(args: SetNextWindowSize) void {
718-
zguiSetNextWindowSize(args.w, args.h, args.cond);
719-
}
720-
extern fn zguiSetNextWindowSize(w: f32, h: f32, cond: Condition) void;
705+
// fn igSetNextWindowSize(size: ImVec2, cond: ImGuiCond) void
706+
pub const setNextWindowSize = cimgui.igSetNextWindowSize;
721707
//--------------------------------------------------------------------------------------------------
722-
extern fn zguiSetNextWindowContentSize(w: f32, h: f32) void;
723-
pub const setNextWindowContentSize = zguiSetNextWindowContentSize;
708+
//
709+
// fn igSetNextWindowContentSize(size: ImVec2) void;
710+
pub const setNextWindowContentSize = cimgui.igSetNextWindowContentSize;
724711
//--------------------------------------------------------------------------------------------------
725712
const SetNextWindowCollapsed = struct {
726713
collapsed: bool,
727714
cond: Condition = .none,
728715
};
729-
pub fn setNextWindowCollapsed(args: SetNextWindowCollapsed) void {
730-
zguiSetNextWindowCollapsed(args.collapsed, args.cond);
731-
}
732-
extern fn zguiSetNextWindowCollapsed(collapsed: bool, cond: Condition) void;
716+
// fn igSetNextWindowCollapsed(collapsed: bool, cond: ImGuiCond) void;
717+
pub const setNextWindowCollapsed = cimgui.igSetNextWindowCollapsed;
718+
733719
//--------------------------------------------------------------------------------------------------
734-
/// `pub fn setNextWindowFocus() void`
735-
pub const setNextWindowFocus = zguiSetNextWindowFocus;
736-
extern fn zguiSetNextWindowFocus() void;
720+
// fn igSetNextWindowFocus() void;
721+
pub const setNextWindowFocus = cimgui.igSetNextWindowFocus;
737722
//--------------------------------------------------------------------------------------------------
738-
extern fn zguiSetNextWindowScroll(scroll_x: f32, scroll_y: f32) void;
739-
pub const setNextWindowScroll = zguiSetNextWindowScroll;
723+
// fn igSetNextWindowScroll(scroll: ImVec2) void;
724+
pub const setNextWindowScroll = cimgui.igSetNextWindowScroll;
740725
//--------------------------------------------------------------------------------------------------
741-
const SetNextWindowBgAlpha = struct {
742-
alpha: f32,
743-
};
744-
pub fn setNextWindowBgAlpha(args: SetNextWindowBgAlpha) void {
745-
zguiSetNextWindowBgAlpha(args.alpha);
746-
}
747-
extern fn zguiSetNextWindowBgAlpha(alpha: f32) void;
726+
// fn igSetNextWindowBgAlpha(alpha: f32) void;
727+
pub const setNextWindowBgAlpha = cimgui.igSetNextWindowBgAlpha;
748728
//--------------------------------------------------------------------------------------------------
749729
pub fn setWindowFocus(name: ?[:0]const u8) void {
750-
zguiSetWindowFocus(name orelse null);
730+
if(name) |n|{
731+
cimgui.igSetWindowFocus_Str(n);
732+
}else{
733+
cimgui.igSetWindowFocus_Nil();
734+
}
751735
}
752-
extern fn zguiSetWindowFocus(name: ?[*:0]const u8) void;
753736
//-------------------------------------------------------------------------------------------------
754-
extern fn zguiSetWindowFontScale(scale: f32) void;
755-
pub const setWindowFontScale = zguiSetWindowFontScale;
737+
// TODO <tonitch>: depreciated
738+
// extern fn zguiSetWindowFontScale(scale: f32) void;
739+
// pub const setWindowFontScale = zguiSetWindowFontScale;
756740
//-------------------------------------------------------------------------------------------------
757-
pub fn setKeyboardFocusHere(offset: i32) void {
758-
zguiSetKeyboardFocusHere(offset);
759-
}
760-
extern fn zguiSetKeyboardFocusHere(offset: c_int) void;
761741

762-
extern fn zguiSetNavCursorVisible(visible: bool) void;
763-
pub const setNavCursorVisible = zguiSetNavCursorVisible;
742+
// fn igSetKeyboardFocusHere(offset: c_int) void;
743+
pub const setKeyboardFocusHere = cimgui.igSetKeyboardFocusHere;
744+
745+
// fn igSetNavCursorVisible(visible: bool) void;
746+
pub const setNavCursorVisible = cimgui.igSetNavCursorVisible;
764747

765-
extern fn zguiSetNextItemAllowOverlap() void;
766-
pub const setNextItemAllowOverlap = zguiSetNextItemAllowOverlap;
748+
// fn igSetNextItemAllowOverlap() void;
749+
pub const setNextItemAllowOverlap = cimgui.igSetNextItemAllowOverlap;
767750
//--------------------------------------------------------------------------------------------------
768751
const Begin = struct {
769752
popen: ?*bool = null,

0 commit comments

Comments
 (0)