diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index d3e4ba3..561c53b 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -35,7 +35,7 @@ typedef void* MwWidget; #endif typedef void (*MwHandler)(MwWidget handle); typedef int (*MwHandlerWithStatus)(MwWidget handle); -typedef void (*MwHandlerProps)(MwWidget handle, const char** key); +typedef void (*MwHandlerProps)(MwWidget handle, char** key); typedef void (*MwHandlerProp)(MwWidget handle, const char* key); typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const char* key); typedef void (*MwHandlerKey)(MwWidget handle, int key); diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 24b7014..159b25e 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -1748,8 +1748,8 @@ static void clip(MwLL handle) { y += ws[i]->wayland.y; cx += MAX(-ws[i]->wayland.x, 0); cy += MAX(-ws[i]->wayland.y, 0); - w = MIN(ws[i]->wayland.ww - MAX(-x, 0), w); - h = MIN(ws[i]->wayland.wh - MAX(-y, 0), h); + w = MIN(ws[i]->wayland.ww - MAX(-x, 0), w); + h = MIN(ws[i]->wayland.wh - MAX(-y, 0), h); } arrfree(ws); @@ -1761,7 +1761,7 @@ static void clip(MwLL handle) { region_setup(handle); cairo_reset_clip(handle->wayland.front_cairo); - if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL){ + if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL) { cairo_rectangle(handle->wayland.front_cairo, cx, cy, w, h); cairo_clip(handle->wayland.front_cairo); } @@ -1994,7 +1994,7 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) { } region_setup(handle); - recursive_render(handle); + if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL) recursive_render(handle); MwLLDispatch(handle, draw, NULL); } @@ -2028,7 +2028,7 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) { } region_setup(handle); - recursive_render(handle); + if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL) recursive_render(handle); framebuffer_destroy(&handle->wayland); framebuffer_setup(&handle->wayland); diff --git a/src/core.c b/src/core.c index d5a6903..4c8e512 100644 --- a/src/core.c +++ b/src/core.c @@ -209,8 +209,8 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, h->bgcolor = NULL; h->berserk = 0; - h->internal = NULL; - h->opaque = NULL; + h->internal = NULL; + h->opaque = NULL; h->top_step = 0; h->draw_queue = NULL; @@ -303,19 +303,19 @@ MwWidget MwVaCreateWidget(MwClass widget_class, const char* name, MwWidget paren MwWidget MwVaListCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, va_list va) { MwWidget h; - va_list va2; + va_list va2; #ifdef va_copy - va_copy(va2, va); + va_copy(va2, va); #else - va2 = va; + va2 = va; #endif h = MwCreateWidget_Internal(widget_class, name, parent, x, y, width, height, 1, va); - MwVaListApply(h, va2); + MwVaListApply(h, va2); + + va_end(va2); - va_end(va2); - return h; } @@ -550,6 +550,13 @@ void MwSetInteger(MwWidget handle, const char* key, int n) { shput(handle->integer, key, n); } if(handle->prop_event) { + char** keys = NULL; + + arrput(keys, (char*)key); + arrput(keys, NULL); + MwDispatch3(handle, props_change, keys); + arrfree(keys); + MwDispatch3(handle, prop_change, key); if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key); } @@ -584,6 +591,13 @@ void MwSetText(MwWidget handle, const char* key, const char* value) { } } if(handle->prop_event) { + char** keys = NULL; + + arrput(keys, (char*)key); + arrput(keys, NULL); + MwDispatch3(handle, props_change, keys); + arrfree(keys); + MwDispatch3(handle, prop_change, key); if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key); } @@ -605,6 +619,13 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) { shput(handle->data, key, value); } if(handle->prop_event) { + char** keys = NULL; + + arrput(keys, (char*)key); + arrput(keys, NULL); + MwDispatch3(handle, props_change, keys); + arrfree(keys); + MwDispatch3(handle, prop_change, key); if(handle->parent != NULL) MwDispatch4(handle->parent, children_prop_change, handle, key); } @@ -729,10 +750,18 @@ void MwVaApply(MwWidget handle, ...) { } static void MwVaListApply_Internal(MwWidget handle, va_list va, int only_early) { - char* key; - int x = MwDEFAULT, y = MwDEFAULT, w = MwDEFAULT, h = MwDEFAULT; + char* key; + int x = MwDEFAULT, y = MwDEFAULT, w = MwDEFAULT, h = MwDEFAULT; + char** keys = NULL; + int old = handle->prop_event; + int i; + handle->prop_event = 0; while((key = va_arg(va, char*)) != NULL) { + if(!only_early || key[1] == 'E') { + arrput(keys, key); + } + if(key[0] == 'I') { int n = va_arg(va, int); if(only_early && key[1] != 'E') continue; @@ -790,6 +819,18 @@ static void MwVaListApply_Internal(MwWidget handle, va_list va, int only_early) MwSetInteger(handle, MwNheight, h); } } + handle->prop_event = old; + + arrput(keys, NULL); + + if(handle->prop_event) { + for(i = 0; keys[i] != NULL; i++) { + MwDispatch3(handle, prop_change, keys[i]); + } + MwDispatch3(handle, props_change, keys); + } + + arrfree(keys); } void MwVaListApply(MwWidget handle, va_list va) { diff --git a/src/widget/box.c b/src/widget/box.c index 6fb8935..626ebad 100644 --- a/src/widget/box.c +++ b/src/widget/box.c @@ -78,7 +78,6 @@ static void layout(MwWidget handle) { static void draw(MwWidget handle) { MwRect r; MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); - MwBox b = handle->internal; r.x = 0; r.y = 0; @@ -92,12 +91,6 @@ static void draw(MwWidget handle) { MwDrawRect(handle, &r, base); MwLLFreeColor(base); - - if(b->layout) { - layout(handle); - - b->layout = 0; - } } static void prop_change(MwWidget handle, const char* key) { @@ -120,6 +113,16 @@ static void children_prop_change(MwWidget handle, MwWidget child, const char* ke } } +static void tick(MwWidget handle) { + MwBox b = handle->internal; + + if(b->layout) { + layout(handle); + + b->layout = 0; + } +} + static void resize(MwWidget handle) { MwBox b = handle->internal; b->layout = 1; @@ -146,12 +149,12 @@ MwClassRec MwBoxClassRec = { NULL, /* mouse_down */ NULL, /* key */ NULL, /* execute */ - NULL, /* tick */ + tick, /* tick */ resize, /* resize */ children_update, /* children_update */ children_prop_change, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/button.c b/src/widget/button.c index 7287f2a..edee8c1 100644 --- a/src/widget/button.c +++ b/src/widget/button.c @@ -109,7 +109,7 @@ MwClassRec MwButtonClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c index 2301aa0..72e0da3 100644 --- a/src/widget/checkbox.c +++ b/src/widget/checkbox.c @@ -54,7 +54,7 @@ MwClassRec MwCheckBoxClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/combobox.c b/src/widget/combobox.c index 823185d..2803cbe 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -200,7 +200,7 @@ MwClassRec MwComboBoxClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/entry.c b/src/widget/entry.c index d38e6d5..2d4f12f 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -204,7 +204,7 @@ MwClassRec MwEntryClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ clipboard, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/frame.c b/src/widget/frame.c index 0cc0c41..f2af108 100644 --- a/src/widget/frame.c +++ b/src/widget/frame.c @@ -62,7 +62,7 @@ MwClassRec MwFrameClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/image.c b/src/widget/image.c index 791570e..c8e0680 100644 --- a/src/widget/image.c +++ b/src/widget/image.c @@ -58,7 +58,7 @@ MwClassRec MwImageClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/label.c b/src/widget/label.c index 98a0d5f..29e63e9 100644 --- a/src/widget/label.c +++ b/src/widget/label.c @@ -376,7 +376,7 @@ MwClassRec MwLabelClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/listbox.c b/src/widget/listbox.c index b2acad7..90d5126 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -377,7 +377,6 @@ static void draw(MwWidget handle) { } static void prop_change(MwWidget handle, const char* prop) { - if(strcmp(prop, MwNwidth) == 0 || strcmp(prop, MwNheight) == 0 || strcmp(prop, MwNhasHeading) == 0) resize(handle); if(strcmp(prop, MwNleftPadding) == 0) { MwListBox lb = handle->internal; MwForceRender(lb->frame); @@ -564,6 +563,17 @@ static void tick(MwWidget handle) { } } +static void props_change(MwWidget handle, char** props) { + int i; + int rsz = 0; + + for(i = 0; props[i] != NULL; i++) { + if(strcmp(props[i], MwNwidth) == 0 || strcmp(props[i], MwNheight) == 0 || strcmp(props[i], MwNhasHeading) == 0) rsz = 1; + } + + if(rsz) resize(handle); +} + MwClassRec MwListBoxClassRec = { wcreate, /* create */ destroy, /* destroy */ @@ -581,7 +591,7 @@ MwClassRec MwListBoxClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + props_change, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/menu.c b/src/widget/menu.c index 1517591..3d39e7d 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -205,7 +205,7 @@ MwClassRec MwMenuClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/numberentry.c b/src/widget/numberentry.c index f1d7bde..969d544 100644 --- a/src/widget/numberentry.c +++ b/src/widget/numberentry.c @@ -146,7 +146,7 @@ MwClassRec MwNumberEntryClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/opengl.c b/src/widget/opengl.c index b936920..d8f8f7c 100644 --- a/src/widget/opengl.c +++ b/src/widget/opengl.c @@ -521,7 +521,8 @@ MwClassRec MwOpenGLClassRec = {wcreate, /* create */ NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, NULL, NULL, NULL}; + NULL, /* props_change */ + NULL, NULL, NULL}; MwClass MwOpenGLClass = &MwOpenGLClassRec; #else MWDECL MwClass MwOpenGLClass; diff --git a/src/widget/progressbar.c b/src/widget/progressbar.c index dedd7a9..ec80a3e 100644 --- a/src/widget/progressbar.c +++ b/src/widget/progressbar.c @@ -62,7 +62,7 @@ MwClassRec MwProgressBarClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/radiobox.c b/src/widget/radiobox.c index 1342232..82fff29 100644 --- a/src/widget/radiobox.c +++ b/src/widget/radiobox.c @@ -63,7 +63,7 @@ MwClassRec MwRadioBoxClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index 58ed578..98a050d 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -273,7 +273,7 @@ MwClassRec MwScrollBarClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/separator.c b/src/widget/separator.c index 15919d0..4e70ccc 100644 --- a/src/widget/separator.c +++ b/src/widget/separator.c @@ -51,7 +51,7 @@ MwClassRec MwSeparatorClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/submenu.c b/src/widget/submenu.c index 7a2afca..addd999 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -101,7 +101,7 @@ static void draw(MwWidget handle) { } static void click(MwWidget handle) { - MwWidget w = handle; + MwWidget w = handle; MwMenu menu = handle->internal; if(arrlen(menu->sub) > 0) { @@ -257,7 +257,7 @@ MwClassRec MwSubMenuClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/treeview.c b/src/widget/treeview.c index 99f12e2..580ecd6 100644 --- a/src/widget/treeview.c +++ b/src/widget/treeview.c @@ -331,10 +331,6 @@ static void draw(MwWidget handle) { MwLLFreeColor(c); } -static void prop_change(MwWidget handle, const char* prop) { - if(strcmp(prop, MwNwidth) == 0 || strcmp(prop, MwNheight) == 0) resize(handle); -} - static void* mwTreeViewAddImpl(MwWidget handle, void* parent, MwLLPixmap pixmap, const char* item) { MwTreeView tv = handle->internal; MwTreeViewEntry* t = malloc(sizeof(*t)); @@ -480,13 +476,24 @@ static void tick(MwWidget handle) { } } +static void props_change(MwWidget handle, char** props) { + int i; + int rsz = 0; + + for(i = 0; props[i] != NULL; i++) { + if(strcmp(props[i], MwNwidth) == 0 || strcmp(props[i], MwNheight) == 0) rsz = 1; + } + + if(rsz) resize(handle); +} + MwClassRec MwTreeViewClassRec = { wcreate, /* create */ destroy, /* destroy */ draw, /* draw */ NULL, /* click */ NULL, /* parent_resize */ - prop_change, /* prop_change */ + NULL, /* prop_change */ NULL, /* mouse_move */ NULL, /* mouse_up */ NULL, /* mouse_down */ @@ -497,7 +504,7 @@ MwClassRec MwTreeViewClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + props_change, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/viewport.c b/src/widget/viewport.c index f05b18d..ceaab5e 100644 --- a/src/widget/viewport.c +++ b/src/widget/viewport.c @@ -192,7 +192,7 @@ MwClassRec MwViewportClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/vulkan.c b/src/widget/vulkan.c index 55387d2..8da8ef1 100644 --- a/src/widget/vulkan.c +++ b/src/widget/vulkan.c @@ -594,7 +594,7 @@ MwClassRec MwVulkanClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL}; diff --git a/src/widget/window.c b/src/widget/window.c index 2b596b5..7178d3f 100644 --- a/src/widget/window.c +++ b/src/widget/window.c @@ -60,7 +60,7 @@ MwClassRec MwWindowClassRec = { NULL, /* children_update */ NULL, /* children_prop_change */ NULL, /* clipboard */ - NULL, + NULL, /* props_change */ NULL, NULL, NULL};