1b877906bSopenharmony_ci//========================================================================
2b877906bSopenharmony_ci// Window properties test
3b877906bSopenharmony_ci// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
4b877906bSopenharmony_ci//
5b877906bSopenharmony_ci// This software is provided 'as-is', without any express or implied
6b877906bSopenharmony_ci// warranty. In no event will the authors be held liable for any damages
7b877906bSopenharmony_ci// arising from the use of this software.
8b877906bSopenharmony_ci//
9b877906bSopenharmony_ci// Permission is granted to anyone to use this software for any purpose,
10b877906bSopenharmony_ci// including commercial applications, and to alter it and redistribute it
11b877906bSopenharmony_ci// freely, subject to the following restrictions:
12b877906bSopenharmony_ci//
13b877906bSopenharmony_ci// 1. The origin of this software must not be misrepresented; you must not
14b877906bSopenharmony_ci//    claim that you wrote the original software. If you use this software
15b877906bSopenharmony_ci//    in a product, an acknowledgment in the product documentation would
16b877906bSopenharmony_ci//    be appreciated but is not required.
17b877906bSopenharmony_ci//
18b877906bSopenharmony_ci// 2. Altered source versions must be plainly marked as such, and must not
19b877906bSopenharmony_ci//    be misrepresented as being the original software.
20b877906bSopenharmony_ci//
21b877906bSopenharmony_ci// 3. This notice may not be removed or altered from any source
22b877906bSopenharmony_ci//    distribution.
23b877906bSopenharmony_ci//
24b877906bSopenharmony_ci//========================================================================
25b877906bSopenharmony_ci
26b877906bSopenharmony_ci#define GLAD_GL_IMPLEMENTATION
27b877906bSopenharmony_ci#include <glad/gl.h>
28b877906bSopenharmony_ci#define GLFW_INCLUDE_NONE
29b877906bSopenharmony_ci#include <GLFW/glfw3.h>
30b877906bSopenharmony_ci
31b877906bSopenharmony_ci#include <stdarg.h>
32b877906bSopenharmony_ci
33b877906bSopenharmony_ci#define NK_IMPLEMENTATION
34b877906bSopenharmony_ci#define NK_INCLUDE_FIXED_TYPES
35b877906bSopenharmony_ci#define NK_INCLUDE_FONT_BAKING
36b877906bSopenharmony_ci#define NK_INCLUDE_DEFAULT_FONT
37b877906bSopenharmony_ci#define NK_INCLUDE_DEFAULT_ALLOCATOR
38b877906bSopenharmony_ci#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
39b877906bSopenharmony_ci#define NK_INCLUDE_STANDARD_VARARGS
40b877906bSopenharmony_ci#define NK_BUTTON_TRIGGER_ON_RELEASE
41b877906bSopenharmony_ci#include <nuklear.h>
42b877906bSopenharmony_ci
43b877906bSopenharmony_ci#define NK_GLFW_GL2_IMPLEMENTATION
44b877906bSopenharmony_ci#include <nuklear_glfw_gl2.h>
45b877906bSopenharmony_ci
46b877906bSopenharmony_ci#include <stdbool.h>
47b877906bSopenharmony_ci#include <stdio.h>
48b877906bSopenharmony_ci#include <stdlib.h>
49b877906bSopenharmony_ci#include <limits.h>
50b877906bSopenharmony_ci
51b877906bSopenharmony_ciint main(int argc, char** argv)
52b877906bSopenharmony_ci{
53b877906bSopenharmony_ci    int windowed_x, windowed_y, windowed_width, windowed_height;
54b877906bSopenharmony_ci    int last_xpos = INT_MIN, last_ypos = INT_MIN;
55b877906bSopenharmony_ci    int last_width = INT_MIN, last_height = INT_MIN;
56b877906bSopenharmony_ci    int limit_aspect_ratio = false, aspect_numer = 1, aspect_denom = 1;
57b877906bSopenharmony_ci    int limit_min_size = false, min_width = 400, min_height = 400;
58b877906bSopenharmony_ci    int limit_max_size = false, max_width = 400, max_height = 400;
59b877906bSopenharmony_ci    char width_buffer[12] = "", height_buffer[12] = "";
60b877906bSopenharmony_ci    char xpos_buffer[12] = "", ypos_buffer[12] = "";
61b877906bSopenharmony_ci    char numer_buffer[12] = "", denom_buffer[12] = "";
62b877906bSopenharmony_ci    char min_width_buffer[12] = "", min_height_buffer[12] = "";
63b877906bSopenharmony_ci    char max_width_buffer[12] = "", max_height_buffer[12] = "";
64b877906bSopenharmony_ci    int may_close = true;
65b877906bSopenharmony_ci    char window_title[64] = "";
66b877906bSopenharmony_ci
67b877906bSopenharmony_ci    if (!glfwInit())
68b877906bSopenharmony_ci        exit(EXIT_FAILURE);
69b877906bSopenharmony_ci
70b877906bSopenharmony_ci    glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
71b877906bSopenharmony_ci    glfwWindowHint(GLFW_WIN32_KEYBOARD_MENU, GLFW_TRUE);
72b877906bSopenharmony_ci    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
73b877906bSopenharmony_ci    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
74b877906bSopenharmony_ci
75b877906bSopenharmony_ci    GLFWwindow* window = glfwCreateWindow(600, 660, "Window Features", NULL, NULL);
76b877906bSopenharmony_ci    if (!window)
77b877906bSopenharmony_ci    {
78b877906bSopenharmony_ci        glfwTerminate();
79b877906bSopenharmony_ci        exit(EXIT_FAILURE);
80b877906bSopenharmony_ci    }
81b877906bSopenharmony_ci    glfwSetInputMode(window, GLFW_UNLIMITED_MOUSE_BUTTONS, GLFW_TRUE);
82b877906bSopenharmony_ci
83b877906bSopenharmony_ci    glfwMakeContextCurrent(window);
84b877906bSopenharmony_ci    gladLoadGL(glfwGetProcAddress);
85b877906bSopenharmony_ci    glfwSwapInterval(0);
86b877906bSopenharmony_ci
87b877906bSopenharmony_ci    bool position_supported = true;
88b877906bSopenharmony_ci
89b877906bSopenharmony_ci    glfwGetError(NULL);
90b877906bSopenharmony_ci    glfwGetWindowPos(window, &last_xpos, &last_ypos);
91b877906bSopenharmony_ci    sprintf(xpos_buffer, "%i", last_xpos);
92b877906bSopenharmony_ci    sprintf(ypos_buffer, "%i", last_ypos);
93b877906bSopenharmony_ci    if (glfwGetError(NULL) == GLFW_FEATURE_UNAVAILABLE)
94b877906bSopenharmony_ci        position_supported = false;
95b877906bSopenharmony_ci
96b877906bSopenharmony_ci    glfwGetWindowSize(window, &last_width, &last_height);
97b877906bSopenharmony_ci    sprintf(width_buffer, "%i", last_width);
98b877906bSopenharmony_ci    sprintf(height_buffer, "%i", last_height);
99b877906bSopenharmony_ci
100b877906bSopenharmony_ci    sprintf(numer_buffer, "%i", aspect_numer);
101b877906bSopenharmony_ci    sprintf(denom_buffer, "%i", aspect_denom);
102b877906bSopenharmony_ci
103b877906bSopenharmony_ci    sprintf(min_width_buffer, "%i", min_width);
104b877906bSopenharmony_ci    sprintf(min_height_buffer, "%i", min_height);
105b877906bSopenharmony_ci    sprintf(max_width_buffer, "%i", max_width);
106b877906bSopenharmony_ci    sprintf(max_height_buffer, "%i", max_height);
107b877906bSopenharmony_ci
108b877906bSopenharmony_ci    struct nk_context* nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
109b877906bSopenharmony_ci
110b877906bSopenharmony_ci    struct nk_font_atlas* atlas;
111b877906bSopenharmony_ci    nk_glfw3_font_stash_begin(&atlas);
112b877906bSopenharmony_ci    nk_glfw3_font_stash_end();
113b877906bSopenharmony_ci
114b877906bSopenharmony_ci    strncpy(window_title, glfwGetWindowTitle(window), sizeof(window_title));
115b877906bSopenharmony_ci
116b877906bSopenharmony_ci    while (!(may_close && glfwWindowShouldClose(window)))
117b877906bSopenharmony_ci    {
118b877906bSopenharmony_ci        int width, height;
119b877906bSopenharmony_ci
120b877906bSopenharmony_ci        glfwGetWindowSize(window, &width, &height);
121b877906bSopenharmony_ci
122b877906bSopenharmony_ci        struct nk_rect area = nk_rect(0.f, 0.f, (float) width, (float) height);
123b877906bSopenharmony_ci        nk_window_set_bounds(nk, "main", area);
124b877906bSopenharmony_ci
125b877906bSopenharmony_ci        nk_glfw3_new_frame();
126b877906bSopenharmony_ci        if (nk_begin(nk, "main", area, 0))
127b877906bSopenharmony_ci        {
128b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, 4);
129b877906bSopenharmony_ci
130b877906bSopenharmony_ci            if (glfwGetWindowMonitor(window))
131b877906bSopenharmony_ci            {
132b877906bSopenharmony_ci                if (nk_button_label(nk, "Make Windowed"))
133b877906bSopenharmony_ci                {
134b877906bSopenharmony_ci                    glfwSetWindowMonitor(window, NULL,
135b877906bSopenharmony_ci                                         windowed_x, windowed_y,
136b877906bSopenharmony_ci                                         windowed_width, windowed_height, 0);
137b877906bSopenharmony_ci                }
138b877906bSopenharmony_ci            }
139b877906bSopenharmony_ci            else
140b877906bSopenharmony_ci            {
141b877906bSopenharmony_ci                if (nk_button_label(nk, "Make Fullscreen"))
142b877906bSopenharmony_ci                {
143b877906bSopenharmony_ci                    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
144b877906bSopenharmony_ci                    const GLFWvidmode* mode = glfwGetVideoMode(monitor);
145b877906bSopenharmony_ci                    glfwGetWindowPos(window, &windowed_x, &windowed_y);
146b877906bSopenharmony_ci                    glfwGetWindowSize(window, &windowed_width, &windowed_height);
147b877906bSopenharmony_ci                    glfwSetWindowMonitor(window, monitor,
148b877906bSopenharmony_ci                                         0, 0, mode->width, mode->height,
149b877906bSopenharmony_ci                                         mode->refreshRate);
150b877906bSopenharmony_ci                }
151b877906bSopenharmony_ci            }
152b877906bSopenharmony_ci
153b877906bSopenharmony_ci            if (nk_button_label(nk, "Maximize"))
154b877906bSopenharmony_ci                glfwMaximizeWindow(window);
155b877906bSopenharmony_ci            if (nk_button_label(nk, "Iconify"))
156b877906bSopenharmony_ci                glfwIconifyWindow(window);
157b877906bSopenharmony_ci            if (nk_button_label(nk, "Restore"))
158b877906bSopenharmony_ci                glfwRestoreWindow(window);
159b877906bSopenharmony_ci
160b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, 2);
161b877906bSopenharmony_ci
162b877906bSopenharmony_ci            if (nk_button_label(nk, "Hide (for 3s)"))
163b877906bSopenharmony_ci            {
164b877906bSopenharmony_ci                glfwHideWindow(window);
165b877906bSopenharmony_ci
166b877906bSopenharmony_ci                const double time = glfwGetTime() + 3.0;
167b877906bSopenharmony_ci                while (glfwGetTime() < time)
168b877906bSopenharmony_ci                    glfwWaitEventsTimeout(1.0);
169b877906bSopenharmony_ci
170b877906bSopenharmony_ci                glfwShowWindow(window);
171b877906bSopenharmony_ci            }
172b877906bSopenharmony_ci            if (nk_button_label(nk, "Request Attention (after 3s)"))
173b877906bSopenharmony_ci            {
174b877906bSopenharmony_ci                glfwIconifyWindow(window);
175b877906bSopenharmony_ci
176b877906bSopenharmony_ci                const double time = glfwGetTime() + 3.0;
177b877906bSopenharmony_ci                while (glfwGetTime() < time)
178b877906bSopenharmony_ci                    glfwWaitEventsTimeout(1.0);
179b877906bSopenharmony_ci
180b877906bSopenharmony_ci                glfwRequestWindowAttention(window);
181b877906bSopenharmony_ci            }
182b877906bSopenharmony_ci
183b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, 1);
184b877906bSopenharmony_ci
185b877906bSopenharmony_ci            if (glfwGetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH))
186b877906bSopenharmony_ci            {
187b877906bSopenharmony_ci                nk_label(nk, "Press H to disable mouse passthrough", NK_TEXT_CENTERED);
188b877906bSopenharmony_ci
189b877906bSopenharmony_ci                if (glfwGetKey(window, GLFW_KEY_H))
190b877906bSopenharmony_ci                    glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, false);
191b877906bSopenharmony_ci            }
192b877906bSopenharmony_ci
193b877906bSopenharmony_ci            nk_label(nk, "Press Enter in a text field to set value", NK_TEXT_CENTERED);
194b877906bSopenharmony_ci
195b877906bSopenharmony_ci            nk_flags events;
196b877906bSopenharmony_ci            const nk_flags flags = NK_EDIT_FIELD |
197b877906bSopenharmony_ci                                   NK_EDIT_SIG_ENTER |
198b877906bSopenharmony_ci                                   NK_EDIT_GOTO_END_ON_ACTIVATE;
199b877906bSopenharmony_ci
200b877906bSopenharmony_ci            nk_layout_row_begin(nk, NK_DYNAMIC, 30, 2);
201b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 3.f);
202b877906bSopenharmony_ci            nk_label(nk, "Title", NK_TEXT_LEFT);
203b877906bSopenharmony_ci            nk_layout_row_push(nk, 2.f / 3.f);
204b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, window_title,
205b877906bSopenharmony_ci                                                    sizeof(window_title), NULL);
206b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
207b877906bSopenharmony_ci                glfwSetWindowTitle(window, window_title);
208b877906bSopenharmony_ci            nk_layout_row_end(nk);
209b877906bSopenharmony_ci
210b877906bSopenharmony_ci            if (position_supported)
211b877906bSopenharmony_ci            {
212b877906bSopenharmony_ci                int xpos, ypos;
213b877906bSopenharmony_ci                glfwGetWindowPos(window, &xpos, &ypos);
214b877906bSopenharmony_ci
215b877906bSopenharmony_ci                nk_layout_row_dynamic(nk, 30, 3);
216b877906bSopenharmony_ci                nk_label(nk, "Position", NK_TEXT_LEFT);
217b877906bSopenharmony_ci
218b877906bSopenharmony_ci                events = nk_edit_string_zero_terminated(nk, flags, xpos_buffer,
219b877906bSopenharmony_ci                                                        sizeof(xpos_buffer),
220b877906bSopenharmony_ci                                                        nk_filter_decimal);
221b877906bSopenharmony_ci                if (events & NK_EDIT_COMMITED)
222b877906bSopenharmony_ci                {
223b877906bSopenharmony_ci                    xpos = atoi(xpos_buffer);
224b877906bSopenharmony_ci                    glfwSetWindowPos(window, xpos, ypos);
225b877906bSopenharmony_ci                }
226b877906bSopenharmony_ci                else if (xpos != last_xpos || (events & NK_EDIT_DEACTIVATED))
227b877906bSopenharmony_ci                    sprintf(xpos_buffer, "%i", xpos);
228b877906bSopenharmony_ci
229b877906bSopenharmony_ci                events = nk_edit_string_zero_terminated(nk, flags, ypos_buffer,
230b877906bSopenharmony_ci                                                        sizeof(ypos_buffer),
231b877906bSopenharmony_ci                                                        nk_filter_decimal);
232b877906bSopenharmony_ci                if (events & NK_EDIT_COMMITED)
233b877906bSopenharmony_ci                {
234b877906bSopenharmony_ci                    ypos = atoi(ypos_buffer);
235b877906bSopenharmony_ci                    glfwSetWindowPos(window, xpos, ypos);
236b877906bSopenharmony_ci                }
237b877906bSopenharmony_ci                else if (ypos != last_ypos || (events & NK_EDIT_DEACTIVATED))
238b877906bSopenharmony_ci                    sprintf(ypos_buffer, "%i", ypos);
239b877906bSopenharmony_ci
240b877906bSopenharmony_ci                last_xpos = xpos;
241b877906bSopenharmony_ci                last_ypos = ypos;
242b877906bSopenharmony_ci            }
243b877906bSopenharmony_ci            else
244b877906bSopenharmony_ci                nk_label(nk, "Platform does not support window position", NK_TEXT_LEFT);
245b877906bSopenharmony_ci
246b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, 3);
247b877906bSopenharmony_ci            nk_label(nk, "Size", NK_TEXT_LEFT);
248b877906bSopenharmony_ci
249b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, width_buffer,
250b877906bSopenharmony_ci                                                    sizeof(width_buffer),
251b877906bSopenharmony_ci                                                    nk_filter_decimal);
252b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
253b877906bSopenharmony_ci            {
254b877906bSopenharmony_ci                width = atoi(width_buffer);
255b877906bSopenharmony_ci                glfwSetWindowSize(window, width, height);
256b877906bSopenharmony_ci            }
257b877906bSopenharmony_ci            else if (width != last_width || (events & NK_EDIT_DEACTIVATED))
258b877906bSopenharmony_ci                sprintf(width_buffer, "%i", width);
259b877906bSopenharmony_ci
260b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, height_buffer,
261b877906bSopenharmony_ci                                                    sizeof(height_buffer),
262b877906bSopenharmony_ci                                                    nk_filter_decimal);
263b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
264b877906bSopenharmony_ci            {
265b877906bSopenharmony_ci                height = atoi(height_buffer);
266b877906bSopenharmony_ci                glfwSetWindowSize(window, width, height);
267b877906bSopenharmony_ci            }
268b877906bSopenharmony_ci            else if (height != last_height || (events & NK_EDIT_DEACTIVATED))
269b877906bSopenharmony_ci                sprintf(height_buffer, "%i", height);
270b877906bSopenharmony_ci
271b877906bSopenharmony_ci            last_width = width;
272b877906bSopenharmony_ci            last_height = height;
273b877906bSopenharmony_ci
274b877906bSopenharmony_ci            bool update_ratio_limit = false;
275b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Aspect Ratio", &limit_aspect_ratio))
276b877906bSopenharmony_ci                update_ratio_limit = true;
277b877906bSopenharmony_ci
278b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, numer_buffer,
279b877906bSopenharmony_ci                                                    sizeof(numer_buffer),
280b877906bSopenharmony_ci                                                    nk_filter_decimal);
281b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
282b877906bSopenharmony_ci            {
283b877906bSopenharmony_ci                aspect_numer = abs(atoi(numer_buffer));
284b877906bSopenharmony_ci                update_ratio_limit = true;
285b877906bSopenharmony_ci            }
286b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
287b877906bSopenharmony_ci                sprintf(numer_buffer, "%i", aspect_numer);
288b877906bSopenharmony_ci
289b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, denom_buffer,
290b877906bSopenharmony_ci                                                    sizeof(denom_buffer),
291b877906bSopenharmony_ci                                                    nk_filter_decimal);
292b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
293b877906bSopenharmony_ci            {
294b877906bSopenharmony_ci                aspect_denom = abs(atoi(denom_buffer));
295b877906bSopenharmony_ci                update_ratio_limit = true;
296b877906bSopenharmony_ci            }
297b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
298b877906bSopenharmony_ci                sprintf(denom_buffer, "%i", aspect_denom);
299b877906bSopenharmony_ci
300b877906bSopenharmony_ci            if (update_ratio_limit)
301b877906bSopenharmony_ci            {
302b877906bSopenharmony_ci                if (limit_aspect_ratio)
303b877906bSopenharmony_ci                    glfwSetWindowAspectRatio(window, aspect_numer, aspect_denom);
304b877906bSopenharmony_ci                else
305b877906bSopenharmony_ci                    glfwSetWindowAspectRatio(window, GLFW_DONT_CARE, GLFW_DONT_CARE);
306b877906bSopenharmony_ci            }
307b877906bSopenharmony_ci
308b877906bSopenharmony_ci            bool update_size_limit = false;
309b877906bSopenharmony_ci
310b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Minimum Size", &limit_min_size))
311b877906bSopenharmony_ci                update_size_limit = true;
312b877906bSopenharmony_ci
313b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, min_width_buffer,
314b877906bSopenharmony_ci                                                    sizeof(min_width_buffer),
315b877906bSopenharmony_ci                                                    nk_filter_decimal);
316b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
317b877906bSopenharmony_ci            {
318b877906bSopenharmony_ci                min_width = abs(atoi(min_width_buffer));
319b877906bSopenharmony_ci                update_size_limit = true;
320b877906bSopenharmony_ci            }
321b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
322b877906bSopenharmony_ci                sprintf(min_width_buffer, "%i", min_width);
323b877906bSopenharmony_ci
324b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, min_height_buffer,
325b877906bSopenharmony_ci                                                    sizeof(min_height_buffer),
326b877906bSopenharmony_ci                                                    nk_filter_decimal);
327b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
328b877906bSopenharmony_ci            {
329b877906bSopenharmony_ci                min_height = abs(atoi(min_height_buffer));
330b877906bSopenharmony_ci                update_size_limit = true;
331b877906bSopenharmony_ci            }
332b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
333b877906bSopenharmony_ci                sprintf(min_height_buffer, "%i", min_height);
334b877906bSopenharmony_ci
335b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Maximum Size", &limit_max_size))
336b877906bSopenharmony_ci                update_size_limit = true;
337b877906bSopenharmony_ci
338b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, max_width_buffer,
339b877906bSopenharmony_ci                                                    sizeof(max_width_buffer),
340b877906bSopenharmony_ci                                                    nk_filter_decimal);
341b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
342b877906bSopenharmony_ci            {
343b877906bSopenharmony_ci                max_width = abs(atoi(max_width_buffer));
344b877906bSopenharmony_ci                update_size_limit = true;
345b877906bSopenharmony_ci            }
346b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
347b877906bSopenharmony_ci                sprintf(max_width_buffer, "%i", max_width);
348b877906bSopenharmony_ci
349b877906bSopenharmony_ci            events = nk_edit_string_zero_terminated(nk, flags, max_height_buffer,
350b877906bSopenharmony_ci                                                    sizeof(max_height_buffer),
351b877906bSopenharmony_ci                                                    nk_filter_decimal);
352b877906bSopenharmony_ci            if (events & NK_EDIT_COMMITED)
353b877906bSopenharmony_ci            {
354b877906bSopenharmony_ci                max_height = abs(atoi(max_height_buffer));
355b877906bSopenharmony_ci                update_size_limit = true;
356b877906bSopenharmony_ci            }
357b877906bSopenharmony_ci            else if (events & NK_EDIT_DEACTIVATED)
358b877906bSopenharmony_ci                sprintf(max_height_buffer, "%i", max_height);
359b877906bSopenharmony_ci
360b877906bSopenharmony_ci            if (update_size_limit)
361b877906bSopenharmony_ci            {
362b877906bSopenharmony_ci                glfwSetWindowSizeLimits(window,
363b877906bSopenharmony_ci                                        limit_min_size ? min_width : GLFW_DONT_CARE,
364b877906bSopenharmony_ci                                        limit_min_size ? min_height : GLFW_DONT_CARE,
365b877906bSopenharmony_ci                                        limit_max_size ? max_width : GLFW_DONT_CARE,
366b877906bSopenharmony_ci                                        limit_max_size ? max_height : GLFW_DONT_CARE);
367b877906bSopenharmony_ci            }
368b877906bSopenharmony_ci
369b877906bSopenharmony_ci            int fb_width, fb_height;
370b877906bSopenharmony_ci            glfwGetFramebufferSize(window, &fb_width, &fb_height);
371b877906bSopenharmony_ci            nk_label(nk, "Framebuffer Size", NK_TEXT_LEFT);
372b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", fb_width);
373b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", fb_height);
374b877906bSopenharmony_ci
375b877906bSopenharmony_ci            float xscale, yscale;
376b877906bSopenharmony_ci            glfwGetWindowContentScale(window, &xscale, &yscale);
377b877906bSopenharmony_ci            nk_label(nk, "Content Scale", NK_TEXT_LEFT);
378b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%f", xscale);
379b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%f", yscale);
380b877906bSopenharmony_ci
381b877906bSopenharmony_ci            nk_layout_row_begin(nk, NK_DYNAMIC, 30, 5);
382b877906bSopenharmony_ci            int frame_left, frame_top, frame_right, frame_bottom;
383b877906bSopenharmony_ci            glfwGetWindowFrameSize(window, &frame_left, &frame_top, &frame_right, &frame_bottom);
384b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 3.f);
385b877906bSopenharmony_ci            nk_label(nk, "Frame Size:", NK_TEXT_LEFT);
386b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 6.f);
387b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", frame_left);
388b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 6.f);
389b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", frame_top);
390b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 6.f);
391b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", frame_right);
392b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 6.f);
393b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "%i", frame_bottom);
394b877906bSopenharmony_ci            nk_layout_row_end(nk);
395b877906bSopenharmony_ci
396b877906bSopenharmony_ci            nk_layout_row_begin(nk, NK_DYNAMIC, 30, 2);
397b877906bSopenharmony_ci            float opacity = glfwGetWindowOpacity(window);
398b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 3.f);
399b877906bSopenharmony_ci            nk_labelf(nk, NK_TEXT_LEFT, "Opacity: %0.3f", opacity);
400b877906bSopenharmony_ci            nk_layout_row_push(nk, 2.f / 3.f);
401b877906bSopenharmony_ci            if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f))
402b877906bSopenharmony_ci                glfwSetWindowOpacity(window, opacity);
403b877906bSopenharmony_ci            nk_layout_row_end(nk);
404b877906bSopenharmony_ci
405b877906bSopenharmony_ci            nk_layout_row_begin(nk, NK_DYNAMIC, 30, 2);
406b877906bSopenharmony_ci            int should_close = glfwWindowShouldClose(window);
407b877906bSopenharmony_ci            nk_layout_row_push(nk, 1.f / 3.f);
408b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Should Close", &should_close))
409b877906bSopenharmony_ci                glfwSetWindowShouldClose(window, should_close);
410b877906bSopenharmony_ci            nk_layout_row_push(nk, 2.f / 3.f);
411b877906bSopenharmony_ci            nk_checkbox_label(nk, "May Close", &may_close);
412b877906bSopenharmony_ci            nk_layout_row_end(nk);
413b877906bSopenharmony_ci
414b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, 1);
415b877906bSopenharmony_ci            nk_label(nk, "Attributes", NK_TEXT_CENTERED);
416b877906bSopenharmony_ci
417b877906bSopenharmony_ci            nk_layout_row_dynamic(nk, 30, width > 200 ? width / 200 : 1);
418b877906bSopenharmony_ci
419b877906bSopenharmony_ci            int decorated = glfwGetWindowAttrib(window, GLFW_DECORATED);
420b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Decorated", &decorated))
421b877906bSopenharmony_ci                glfwSetWindowAttrib(window, GLFW_DECORATED, decorated);
422b877906bSopenharmony_ci
423b877906bSopenharmony_ci            int resizable = glfwGetWindowAttrib(window, GLFW_RESIZABLE);
424b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Resizable", &resizable))
425b877906bSopenharmony_ci                glfwSetWindowAttrib(window, GLFW_RESIZABLE, resizable);
426b877906bSopenharmony_ci
427b877906bSopenharmony_ci            int floating = glfwGetWindowAttrib(window, GLFW_FLOATING);
428b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Floating", &floating))
429b877906bSopenharmony_ci                glfwSetWindowAttrib(window, GLFW_FLOATING, floating);
430b877906bSopenharmony_ci
431b877906bSopenharmony_ci            int passthrough = glfwGetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH);
432b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Mouse Passthrough", &passthrough))
433b877906bSopenharmony_ci                glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, passthrough);
434b877906bSopenharmony_ci
435b877906bSopenharmony_ci            int auto_iconify = glfwGetWindowAttrib(window, GLFW_AUTO_ICONIFY);
436b877906bSopenharmony_ci            if (nk_checkbox_label(nk, "Auto Iconify", &auto_iconify))
437b877906bSopenharmony_ci                glfwSetWindowAttrib(window, GLFW_AUTO_ICONIFY, auto_iconify);
438b877906bSopenharmony_ci
439b877906bSopenharmony_ci            nk_value_bool(nk, "Focused", glfwGetWindowAttrib(window, GLFW_FOCUSED));
440b877906bSopenharmony_ci            nk_value_bool(nk, "Hovered", glfwGetWindowAttrib(window, GLFW_HOVERED));
441b877906bSopenharmony_ci            nk_value_bool(nk, "Visible", glfwGetWindowAttrib(window, GLFW_VISIBLE));
442b877906bSopenharmony_ci            nk_value_bool(nk, "Iconified", glfwGetWindowAttrib(window, GLFW_ICONIFIED));
443b877906bSopenharmony_ci            nk_value_bool(nk, "Maximized", glfwGetWindowAttrib(window, GLFW_MAXIMIZED));
444b877906bSopenharmony_ci        }
445b877906bSopenharmony_ci        nk_end(nk);
446b877906bSopenharmony_ci
447b877906bSopenharmony_ci        glClear(GL_COLOR_BUFFER_BIT);
448b877906bSopenharmony_ci        nk_glfw3_render(NK_ANTI_ALIASING_ON);
449b877906bSopenharmony_ci        glfwSwapBuffers(window);
450b877906bSopenharmony_ci
451b877906bSopenharmony_ci        glfwWaitEvents();
452b877906bSopenharmony_ci    }
453b877906bSopenharmony_ci
454b877906bSopenharmony_ci    nk_glfw3_shutdown();
455b877906bSopenharmony_ci    glfwTerminate();
456b877906bSopenharmony_ci    exit(EXIT_SUCCESS);
457b877906bSopenharmony_ci}
458b877906bSopenharmony_ci
459