add props_change, closes #20
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-04-20 16:22:06 +09:00
commit 1fd86732f5
24 changed files with 114 additions and 52 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -109,7 +109,7 @@ MwClassRec MwButtonClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -54,7 +54,7 @@ MwClassRec MwCheckBoxClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -200,7 +200,7 @@ MwClassRec MwComboBoxClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -204,7 +204,7 @@ MwClassRec MwEntryClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
clipboard, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -62,7 +62,7 @@ MwClassRec MwFrameClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -58,7 +58,7 @@ MwClassRec MwImageClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -376,7 +376,7 @@ MwClassRec MwLabelClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

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

View file

@ -205,7 +205,7 @@ MwClassRec MwMenuClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -146,7 +146,7 @@ MwClassRec MwNumberEntryClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

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

View file

@ -62,7 +62,7 @@ MwClassRec MwProgressBarClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -63,7 +63,7 @@ MwClassRec MwRadioBoxClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -273,7 +273,7 @@ MwClassRec MwScrollBarClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -51,7 +51,7 @@ MwClassRec MwSeparatorClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

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

View file

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

View file

@ -192,7 +192,7 @@ MwClassRec MwViewportClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -594,7 +594,7 @@ MwClassRec MwVulkanClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};

View file

@ -60,7 +60,7 @@ MwClassRec MwWindowClassRec = {
NULL, /* children_update */
NULL, /* children_prop_change */
NULL, /* clipboard */
NULL,
NULL, /* props_change */
NULL,
NULL,
NULL};