Fixed non displayed windows.

WARNING: Drawing is not done correctly
This commit is contained in:
Ludwig Füchsl 2022-02-28 15:53:54 +01:00
parent 169470d2e3
commit 33395aabdb
2 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -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