From 33395aabdb439ac41998f5c57982d2dfc8fc09a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20F=C3=BCchsl?= Date: Mon, 28 Feb 2022 15:53:54 +0100 Subject: [PATCH] Fixed non displayed windows. WARNING: Drawing is not done correctly --- demo/gdi_native_nuklear/main.c | 16 ++++++++++++++++ demo/gdi_native_nuklear/window.h | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/demo/gdi_native_nuklear/main.c b/demo/gdi_native_nuklear/main.c index 70ba268..05ed83b 100644 --- a/demo/gdi_native_nuklear/main.c +++ b/demo/gdi_native_nuklear/main.c @@ -16,23 +16,39 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #define NKGDI_IMPLEMENT_WINDOW #include "window.h" +int drawCallback(struct nk_context* ctx) +{ + nk_label(ctx, "Label", NK_TEXT_ALIGN_CENTERED); + nk_button_label(ctx, "Test 1234"); + return 1; +} + INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, PWSTR _In_ cmdArgs, INT _In_ cmdShow) { + nkgdi_window_init(); struct nkgdi_window w1, w2; + memset(&w1, 0x0, sizeof(struct nkgdi_window)); + memset(&w2, 0x0, sizeof(struct nkgdi_window)); w1.allow_sizing = 0; w1.allow_maximize = 0; w1.allow_move = 0; w1.has_titlebar = 0; + w1.cb_on_draw = &drawCallback; nkgdi_window_create(&w1, 500, 500, "F1", 10, 10); w2.allow_sizing = 1; w2.allow_maximize = 1; w2.allow_move = 1; w2.has_titlebar = 1; + w2.cb_on_draw = &drawCallback; nkgdi_window_create(&w2, 500, 500, "F2", 520, 10); while (nkgdi_window_update(&w1) && nkgdi_window_update(&w2)) Sleep(20); + nkgdi_window_destroy(&w1); + nkgdi_window_destroy(&w2); + + nkgdi_window_shutdown(); return 0; } diff --git a/demo/gdi_native_nuklear/window.h b/demo/gdi_native_nuklear/window.h index ce60475..ee1b5de 100644 --- a/demo/gdi_native_nuklear/window.h +++ b/demo/gdi_native_nuklear/window.h @@ -130,8 +130,8 @@ void nkgdi_window_create(struct nkgdi_window* wnd, unsigned int width, unsigned wnd->_internal.is_maximized = 0; wnd->_internal.drag_offset.x = 0; wnd->_internal.drag_offset.y = 0; - wnd->_internal.width = 0; - wnd->_internal.height = 0; + wnd->_internal.width = width; + wnd->_internal.height = height; } void nkgdi_window_destroy(struct nkgdi_window* wnd) @@ -193,7 +193,7 @@ int nkgdi_window_update(struct nkgdi_window* wnd) nk_window_set_bounds(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height)); if (nk_begin(wnd->_internal.nk_ctx, title, nk_rect(0, 0, wnd->_internal.width, wnd->_internal.height), window_flags)) { - if(!wnd->cb_on_draw(wnd->_internal.nk_ctx)) + if(wnd->cb_on_draw && !wnd->cb_on_draw(wnd->_internal.nk_ctx)) wnd->_internal.is_open = 0; // Update window size