From 541499f43c71b3429353dd2611ce0edfc54d0ba0 Mon Sep 17 00:00:00 2001 From: Nishi Date: Sun, 5 Jul 2026 05:23:46 +0900 Subject: [PATCH] add RESIZE_ON_TICK and fix CMake --- CMakeLists.txt | 2 +- include/Mw/TypeDefs.h | 1 + src/core.c | 59 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7663578..eeb15e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,7 +417,7 @@ endif() target_compile_definitions( Mw PRIVATE - _MILSKO + _MILSKO _MILSKO_BUILD ) install( diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index fd72922..d31aeac 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -115,6 +115,7 @@ struct _MwWidget { int top_step; MwWidget* draw_queue; + MwWidget* resize_queue; int berserk; long last_tick; diff --git a/src/core.c b/src/core.c index 59984a5..f649a62 100644 --- a/src/core.c +++ b/src/core.c @@ -6,6 +6,8 @@ #define PERIODIC #endif +#define RESIZE_ON_TICK + #define DRAW(handle) \ { \ MwLLBeginDraw(handle->lowlevel); \ @@ -18,6 +20,16 @@ MwLLEndDraw(handle->lowlevel); \ } +#define RESIZE(handle) \ + { \ + int RESIZE_i; \ + MwDispatchUserHandler(handle, MwNresizeHandler, NULL); \ + for(RESIZE_i = 0; RESIZE_i < arrlen(handle->children); RESIZE_i++) { \ + MwDispatch(handle->children[RESIZE_i], parent_resize); \ + } \ + MwDispatch(handle, resize); \ + } + static void MWAPI MwVaListApply_Internal(MwWidget handle, va_list va, int only_early); static MwWidget MWAPI MwCreateWidget_Internal(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, int do_prop, va_list prop); @@ -83,16 +95,35 @@ static void lldownhandler(MwLL handle, void* data) { static void llresizehandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; - int i; +#ifdef RESIZE_ON_TICK + MwWidget top; +#endif (void)data; - MwDispatchUserHandler(h, MwNresizeHandler, NULL); - for(i = 0; i < arrlen(h->children); i++) { - MwDispatch(h->children[i], parent_resize); - MwDispatch(h->children[i], draw); +#ifdef RESIZE_ON_TICK + top = h; + while(top != NULL) { + if(top->top_step) { + break; + } + + top = top->parent; } - MwDispatch(h, resize); + + if(top == NULL) { + RESIZE(h); /* fallback */ + } else { + int i; + + for(i = 0; i < arrlen(top->resize_queue); i++) { + if(top->resize_queue[i] == h) break; + } + if(i == arrlen(top->resize_queue)) arrput(top->resize_queue, h); + } +#else + RESIZE(h); +#endif } static void llclosehandler(MwLL handle, void* data) { @@ -226,8 +257,9 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, h->opaque = NULL; h->user = NULL; - h->top_step = 0; - h->draw_queue = NULL; + h->top_step = 0; + h->draw_queue = NULL; + h->resize_queue = NULL; if(parent == NULL) arrput(h->tick_list, h); @@ -393,6 +425,7 @@ void MwFreeWidget(MwWidget handle) { arrfree(handle->tick_list); arrfree(handle->draw_queue); + arrfree(handle->resize_queue); if(handle->root_font != NULL) MwFontFree(handle->root_font); if(handle->root_boldfont != NULL) MwFontFree(handle->root_boldfont); @@ -472,6 +505,16 @@ static void MwAfterStep(MwWidget handle) { } #endif +#ifdef RESIZE_ON_TICK + if(handle->top_step) { + for(i = 0; i < arrlen(handle->resize_queue); i++) { + RESIZE(handle->resize_queue[i]); + } + + arrfree(handle->resize_queue); + } +#endif + if(arrlen(handle->tick_list) > 0 && (MwTimeGetTick() - handle->last_tick) >= MwWaitMS) { for(i = 0; i < arrlen(handle->tick_list); i++) { MwDispatch(handle->tick_list[i], tick);