From 149f99622a4bd62c7c1cc38f01b2d8bc8df97c5c Mon Sep 17 00:00:00 2001 From: IoIxD Date: Fri, 22 May 2026 11:41:08 -0700 Subject: [PATCH] add disabled widgets --- examples/basic/example.c | 23 ++++++++++++++++------- examples/basic/periodic.c | 15 +++++++++++---- include/Mw/StringDefs.h | 1 + src/backend/wayland/wayland.c | 5 ++++- src/core.c | 8 ++++++++ src/draw.c | 31 +++++++++++++++++++++++++++++-- src/text/text.c | 28 ++++++++++++++++++++++------ 7 files changed, 91 insertions(+), 20 deletions(-) diff --git a/examples/basic/example.c b/examples/basic/example.c index 9facecb..8fe38da 100644 --- a/examples/basic/example.c +++ b/examples/basic/example.c @@ -1,6 +1,6 @@ #include -MwWidget window, menu, button, button2, button3, button4, button5, button6; +MwWidget window, menu, button, button2, button3, button4, button5, button6, button7; void MWAPI handler(MwWidget handle, void* user_data, void* call_data) { (void)handle; @@ -51,24 +51,29 @@ void MWAPI resize(MwWidget handle, void* user_data, void* call_data) { MwVaApply(button, MwNy, 50 + mh, - MwNwidth, (w - 50 * 2) / 3, + MwNwidth, (w - 50 * 2) / 4, MwNheight, h - 125 - 50 * 3, NULL); MwVaApply(button2, - MwNx, 50 + (w - 50 * 2) / 3, + MwNx, 50 + (w - 50 * 2) / 4, MwNy, 50 + mh, - MwNwidth, (w - 50 * 2) / 3, + MwNwidth, (w - 50 * 2) / 4, MwNheight, h - 125 - 50 * 3, NULL); MwVaApply(button3, - MwNx, 50 + (w - 50 * 2) / 3 * 2, + MwNx, 50 + (w - 50 * 2) / 4 * 2, MwNy, 50 + mh, - MwNwidth, (w - 50 * 2) / 3, + MwNwidth, (w - 50 * 2) / 4, + MwNheight, h - 125 - 50 * 3, + NULL); + MwVaApply(button7, + MwNx, 50 + (w - 50 * 2) / 4 * 3, + MwNy, 50 + mh, + MwNwidth, (w - 50 * 2) / 4, MwNheight, h - 125 - 50 * 3, NULL); - MwVaApply(button4, MwNx, 50 + (w - 50 * 2) / 3 * 0, MwNy, h - 50 - 125 + mh, @@ -121,6 +126,10 @@ int main() { MwNbackground, "#66f", MwNforeground, "#000", NULL); + button7 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125, + MwNtext, "disabled", + MwNdisabled, 1, + NULL); MwAddUserHandler(window, MwNresizeHandler, resize, NULL); MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL); diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c index 069395f..92dab70 100644 --- a/examples/basic/periodic.c +++ b/examples/basic/periodic.c @@ -202,9 +202,16 @@ int main() { MwNcolumns, 5, NULL); - f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass, - MwNtext, "Press me", + f = frame("Button", -PaddingContent, -PaddingContent, MwBoxClass, + MwNorientation, MwVERTICAL, NULL); + b = MwVaCreateWidget(MwButtonClass, "btn", child(f), 0, 0, 0, 0, + MwNtext, "Press me", + NULL); + b = MwVaCreateWidget(MwButtonClass, "btn_disabled", child(f), 0, 0, 0, 0, + MwNtext, "Cannot press me", + MwNdisabled, 1, + NULL); MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0, MwNbold, 1, @@ -221,11 +228,11 @@ int main() { MwNorientation, MwVERTICAL, MwNfixedSize, 16, NULL); - for(j = 0; j < 5; j++) MwCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0); + for(j = 0; j < 6; j++) MwVaCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0, MwNdisabled, (j == 5) ? 1 : 0, NULL); b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0, MwNorientation, MwVERTICAL, NULL); - for(j = 0; j < 5; j++) { + for(j = 0; j < 6; j++) { char buf[32]; sprintf(buf, "%sBox %d", i == 0 ? "Check" : "Radio", j + 1); MwVaCreateWidget(MwLabelClass, "label", b, 0, 0, 0, 0, diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 3a019e0..b95fe93 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -52,6 +52,7 @@ #define MwNcolumns "Icolumns" #define MwNcolumnSpan "IcolumnSpan" #define MwNrowSpan "IrowSpan" +#define MwNdisabled "Idisabled" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/src/backend/wayland/wayland.c b/src/backend/wayland/wayland.c index 73a51cf..89f00f1 100644 --- a/src/backend/wayland/wayland.c +++ b/src/backend/wayland/wayland.c @@ -1652,8 +1652,11 @@ static void MwLLEndStateChangeImpl(MwLL handle) { } static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) { - (void)handle; (void)toggle; + + /* Not Really what's supposed to happen with this function, but take this opprutunity to do the handlers that will force everything to redraw. */ + MwLLDispatch(handle, resize, NULL); + MwLLDispatch(handle, draw, NULL); } static MwBool MwLLDoModernImpl(MwLL handle) { diff --git a/src/core.c b/src/core.c index c081950..99b8d8b 100644 --- a/src/core.c +++ b/src/core.c @@ -57,6 +57,7 @@ static void lldrawhandler(MwLL handle, void* data) { static void lluphandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; MwMouse* p = data; + if(MwGetInteger(h, MwNdisabled) == 1) return; if(p->button == MwMOUSE_LEFT) h->pressed = 0; h->mouse_point.x = p->point.x; @@ -70,6 +71,7 @@ static void lluphandler(MwLL handle, void* data) { static void lldownhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; MwMouse* p = data; + if(MwGetInteger(h, MwNdisabled) == 1) return; if(p->button == MwMOUSE_LEFT) h->pressed = 1; h->mouse_point.x = p->point.x; @@ -124,6 +126,7 @@ static void llmovehandler(MwLL handle, void* data) { static void llkeyhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; int key = *(int*)data; + if(MwGetInteger(h, MwNdisabled) == 1) return; MwDispatch3(h, key, key); MwDispatchUserHandler(h, MwNkeyHandler, data); @@ -131,24 +134,28 @@ static void llkeyhandler(MwLL handle, void* data) { static void llkeyrelhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; + if(MwGetInteger(h, MwNdisabled) == 1) return; MwDispatchUserHandler(h, MwNkeyReleaseHandler, data); } static void llfocusinhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; + if(MwGetInteger(h, MwNdisabled) == 1) return; MwDispatchUserHandler(h, MwNfocusInHandler, data); } static void llfocusouthandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; + if(MwGetInteger(h, MwNdisabled) == 1) return; MwDispatchUserHandler(h, MwNfocusOutHandler, data); } static void llclipboardhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; + if(MwGetInteger(h, MwNdisabled) == 1) return; MwDispatch3(h, clipboard, data); MwDispatchUserHandler(h, MwNclipboardHandler, data); @@ -691,6 +698,7 @@ int MwGetInteger(MwWidget handle, const char* key) { #endif if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0); if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0); + if(strcmp(key, MwNdisabled) == 0) return inherit_integer(handle, key, 0); } return shget(handle->integer, key); } diff --git a/src/draw.c b/src/draw.c index 4d419bc..4f872cc 100644 --- a/src/draw.c +++ b/src/draw.c @@ -38,6 +38,18 @@ static int hex(const char* txt, int len) { return r; } +static void color_set_disabled_if_disabled(MwWidget handle, MwLLColor rgb) { + if(MwGetInteger(handle, MwNdisabled) == 1) { + MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground)); + + if(c != NULL) { + rgb->common.red = rgb->common.red + (c->common.red - rgb->common.red) * 0.5; + rgb->common.green = rgb->common.green + (c->common.green - rgb->common.green) * 0.5; + rgb->common.blue = rgb->common.blue + (c->common.blue - rgb->common.blue) * 0.5; + } + } +}; + void MwParseColorNoAllocate(const char* text, MwRGB* rgb) { if(text[0] == '#' && strlen(text) == 4) { rgb->red = hex(text + 1, 1); @@ -125,6 +137,7 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) { for(y = 0; y < rect->height; y++) { MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken); int idx = y * 4; + color_set_disabled_if_disabled(handle, col); data[idx] = col->common.red; data[idx + 1] = col->common.green; data[idx + 2] = col->common.blue; @@ -204,6 +217,8 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert if(rect->width <= 0 || rect->height <= 0) return; col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color; + color_set_disabled_if_disabled(handle, col); + if(MwGetInteger(handle, MwNmodernLook)) { MwDrawRectFading(handle, rect, col); } else { @@ -219,6 +234,9 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) { MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color; + color_set_disabled_if_disabled(handle, col); + color_set_disabled_if_disabled(handle, darker); + color_set_disabled_if_disabled(handle, lighter); p[0].x = rect->x; p[0].y = rect->y + rect->height / 2; @@ -284,8 +302,11 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, int ColorDiff = get_color_diff(handle); MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff); MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, ColorDiff - diff, ColorDiff - diff, ColorDiff - diff); - p[0].x = rect->x; - p[0].y = rect->y; + color_set_disabled_if_disabled(handle, darker); + color_set_disabled_if_disabled(handle, lighter); + + p[0].x = rect->x; + p[0].y = rect->y; p[1].x = rect->x + rect->width; p[1].y = rect->y; @@ -380,6 +401,9 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff); MwRect r = *rect; + color_set_disabled_if_disabled(handle, darker); + color_set_disabled_if_disabled(handle, lighter); + frame_border_complex(handle, rect, lighter, darker, invert, border == 1 ? 1 : (border / 2), diff, same); if(border > 1) { @@ -416,6 +440,9 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff); MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff); MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color; + color_set_disabled_if_disabled(handle, col); + color_set_disabled_if_disabled(handle, darker); + color_set_disabled_if_disabled(handle, lighter); double deg = 30 * ((direction == MwEAST || direction == MwWEST) ? 2 : 1); double c = cos(deg / 180 * M_PI); diff --git a/src/text/text.c b/src/text/text.c index f2d83a2..b6297e3 100644 --- a/src/text/text.c +++ b/src/text/text.c @@ -76,10 +76,22 @@ static MwFLFont assume_ttf(MwWidget handle, MwFLFont ttf) { #endif void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color) { - MwPoint p = *point; - char* input = (char*)text; - char* last = input; - int cp; + MwPoint p = *point; + char* input = (char*)text; + char* last = input; + int cp; + MwLLColor fadedColor = NULL; + + if(MwGetInteger(handle, MwNdisabled) == 1) { + MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground)); + + if(c != NULL) { + fadedColor = MwLLAllocColor(handle->lowlevel, color->common.red, color->common.blue, color->common.green); + fadedColor->common.red = fadedColor->common.red + (c->common.red - fadedColor->common.red) * 0.5; + fadedColor->common.green = fadedColor->common.green + (c->common.green - fadedColor->common.green) * 0.5; + fadedColor->common.blue = fadedColor->common.blue + (c->common.blue - fadedColor->common.blue) * 0.5; + } + } #ifdef TTF if(ttf <= MwFLBuildFont(0xff) && !is_bitmap(handle, ttf)) ttf = assume_ttf(handle, ttf); @@ -122,9 +134,9 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, #ifdef TTF if(MwFLDrawText) - if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, color)) + if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, fadedColor ? fadedColor : color)) #endif - bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), color); + bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), fadedColor ? fadedColor : color); p.y += MwTextHeight(handle, ttf, line); @@ -133,6 +145,10 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, last = input; } } + + if(fadedColor) { + MwLLFreeColor(fadedColor); + } } int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {