-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.zig
108 lines (97 loc) · 3.58 KB
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const ig = @import ("imgui.zig");
const fonts = @import("fonts.zig");
const app = @import("appImGui.zig");
//-----------
// gui_main()
//-----------
pub fn gui_main (window: *app.Window) void {
fonts.setupFonts(); // Setup CJK fonts and Icon fonts
//---------------
// main loop GUI
//---------------
while (ig.glfwWindowShouldClose (window.handle) == 0) {
ig.glfwPollEvents ();
// Start the Dear ImGui frame
window.frame();
//------------------
// Show demo window
//------------------
ig.igShowDemoWindow (null);
window.showInfoWindow();
// ImGui-Toggle demo
{
const green = ig.ImVec4{.x = 0.16, .y= 0.66, .z = 0.45, .w = 1.0};
const green_hover = ig.ImVec4{.x = 0.0, .y= 1.0, .z =0.57, .w = 1.0};
const green_shadow = ig.ImVec4{.x = 0.0, .y= 1.0, .z =0.0, .w = 0.4};
var value_index: usize = 0;
const sz = ig.ImVec2{.x = 0.0, .y = 0.0};
const sThemeClassic = "Theme: Classic";
const sThemeLight = "Theme: Light";
const st = struct {
var values = [8]bool{true, true, true, true, true, true, true, true };
var sTheme: []const u8 = sThemeClassic[0..];
};
_ = ig.igBegin("Zig: ImGui-Toggle demo 2025/02", null, 0);
defer ig.igEnd ();
//
if (ig.Toggle("##toggle1", &st.values[value_index], sz)){
if (st.values[value_index]) {
st.sTheme = sThemeClassic[0..];
ig.igStyleColorsClassic(null);
}else{
st.sTheme = sThemeLight[0..];
ig.igStyleColorsLight(null);
}
}
ig.igSameLine(0.0, -1.0); ig.igText("%s", st.sTheme.ptr);
ig.igSeparator();
value_index += 1;
//
_ = ig.Toggle("Default Toggle", &st.values[value_index], sz); ig.igSameLine(0.0, -1.0);
value_index += 1;
//
_ = ig.ToggleAnim("Animated Toggle", &st.values[value_index], ig.ImGuiToggleFlags_Animated, 1.0, sz);
value_index += 1;
// This toggle draws a simple border around it's frame and knob
_ = ig.ToggleAnim("Bordered Knob", &st.values[value_index], ig.ImGuiToggleFlags_Bordered, 1.0, sz); ig.igSameLine(0.0, -1.0);
value_index += 1;
//
{
ig.igPushStyleColor_Vec4(ig.ImGuiCol_BorderShadow, green_shadow);
_ = ig.ToggleAnim("Shadowed Knob", &st.values[value_index], ig.ImGuiToggleFlags_Shadowed, 1.0, sz);
value_index += 1;
//
_ = ig.ToggleAnim("Bordered + Shadowed Knob", &st.values[value_index], ig.ImGuiToggleFlags_Bordered | ig.ImGuiToggleFlags_Shadowed, 1.0, sz);
value_index += 1;
ig.igPopStyleColor(1);
}
// This toggle uses stack-pushed style colors to change the way it displays
ig.igPushStyleColor_Vec4(ig.ImGuiCol_Button, green);
ig.igPushStyleColor_Vec4(ig.ImGuiCol_ButtonHovered, green_hover);
_ = ig.Toggle("Green Toggle", &st.values[value_index], sz); ig.igSameLine(0.0, -1.0);
ig.igPopStyleColor(2);
value_index += 1;
//
_ = ig.ToggleFlag("Toggle with A11y Labels", &st.values[value_index], ig.ImGuiToggleFlags_A11y, sz);
value_index += 1;
}
//--------
// render
//--------
window.render();
} // end while loop
}
//--------
// main()
//--------
const MainWinWidth :i32 = 1024;
const MainWinHeight:i32 = 900;
pub fn main () !void {
var window = try app.Window.createImGui(MainWinWidth, MainWinHeight, "ImGui window in Zig lang.");
defer window.destroyImGui();
_ = app.setTheme(app.Theme.classic); // Theme: dark, classic, light, microsoft
//---------------
// GUI main proc
//---------------
gui_main(&window);
}