better property handling

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@226 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-08 15:42:57 +00:00
parent 84a4efa57e
commit 7450b17bcf
8 changed files with 64 additions and 22 deletions

View File

@@ -28,6 +28,16 @@
#define MwDispatch2(x, y) \
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
/*!
* %warning Used internally
* %brief Dispatches the handler of widget class
* %param x Widget
* %param y Handler name
* %param name Property name
*/
#define MwDispatch3(x, y, name) \
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x, name) : 0)
#define MwWaitMS 5
#ifdef __cplusplus

View File

@@ -25,7 +25,7 @@ typedef void* MwWidget;
#endif
typedef void (*MwHandler)(MwWidget handle);
typedef int (*MwHandler2)(MwWidget handle);
typedef int (*MwHandler3)(MwWidget handle, const char* key);
typedef void (*MwHandler3)(MwWidget handle, const char* key);
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
@@ -79,6 +79,7 @@ struct _MwWidget {
MwPoint mouse_point;
int close;
jmp_buf before_step;
int prop_event;
void* internal;

View File

@@ -83,6 +83,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->pressed = 0;
h->close = 0;
h->destroy_queue = NULL;
h->prop_event = 1;
h->lowlevel->user = h;
h->lowlevel->handler->draw = lldrawhandler;
@@ -171,7 +172,11 @@ void MwStep(MwWidget handle) {
int i, j;
if(setjmp(handle->before_step)) return;
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
handle->prop_event = 0;
MwLLNextEvent(handle->lowlevel);
handle->prop_event = 1;
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
MwWidget w = handle->destroy_queue[i];
@@ -222,6 +227,7 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
} else {
shput(handle->integer, key, n);
}
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
}
void MwSetText(MwWidget handle, const char* key, const char* value) {
@@ -235,6 +241,10 @@ void MwSetText(MwWidget handle, const char* key, const char* value) {
shput(handle->text, key, v);
}
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
if(strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0) {
MwForceRender(handle);
}
}
void MwSetVoid(MwWidget handle, const char* key, void* value) {
@@ -243,6 +253,7 @@ void MwSetVoid(MwWidget handle, const char* key, void* value) {
} else {
shput(handle->data, key, value);
}
if(handle->prop_event) MwDispatch3(handle, prop_change, key);
}
int MwGetInteger(MwWidget handle, const char* key) {

View File

@@ -61,13 +61,17 @@ static void click(MwWidget handle) {
MwDispatchUserHandler(handle, MwNactivateHandler, NULL);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNpixmap) == 0) MwForceRender(handle);
}
MwClassRec MwButtonClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
prop_change, /* prop_change */
NULL, /* mouse_move */
MwForceRender, /* mouse_up */
MwForceRender /* mouse_down */

View File

@@ -33,13 +33,17 @@ static void click(MwWidget handle) {
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNchecked) == 0) MwForceRender(handle);
}
MwClassRec MwCheckBoxClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
click, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
prop_change, /* prop_change */
NULL, /* mouse_move */
MwForceRender, /* mouse_up */
MwForceRender /* mouse_down */

View File

@@ -20,15 +20,19 @@ static void draw(MwWidget handle) {
}
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNpixmap) == 0) MwForceRender(handle);
}
MwClassRec MwImageClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL /* mouse_down */
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL /* mouse_down */
};
MwClass MwImageClass = &MwImageClassRec;

View File

@@ -40,15 +40,19 @@ static void draw(MwWidget handle) {
MwLLFreeColor(base);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle);
}
MwClassRec MwLabelClassRec = {
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL /* mouse_down */
create, /* create */
NULL, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
prop_change, /* prop_change */
NULL, /* mouse_move */
NULL, /* mouse_up */
NULL /* mouse_down */
};
MwClass MwLabelClass = &MwLabelClassRec;

View File

@@ -181,13 +181,17 @@ static void mouse_down(MwWidget handle) {
MwForceRender(handle);
}
static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNminValue) == 0 || strcmp(key, MwNvalue) == 0 || strcmp(key, MwNmaxValue) == 0 || strcmp(key, MwNareaShown) == 0) MwForceRender(handle);
}
MwClassRec MwScrollBarClassRec = {
create, /* create */
destroy, /* destroy */
draw, /* draw */
NULL, /* click */
NULL, /* parent_resize */
NULL, /* prop_change */
prop_change, /* prop_change */
mouse_move, /* mouse_move */
MwForceRender, /* mouse_up */
mouse_down /* mouse_down */