From f6abf024862f082d6fff2cde825d357c3cb12425 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Fri, 27 Mar 2026 16:31:28 +0900 Subject: [PATCH] wip --- examples/basic/periodic.c | 27 +++++++++++++++++++++-- src/draw.c | 11 +++++----- src/widget/entry.c | 46 ++++++++++++++++++++------------------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/examples/basic/periodic.c b/examples/basic/periodic.c index 8b7e7fd..646e113 100644 --- a/examples/basic/periodic.c +++ b/examples/basic/periodic.c @@ -140,8 +140,10 @@ static MwWidget child(MwWidget w) { } int main() { - int i; - MwWidget f, w; + int i; + MwWidget f, w; + MwListBoxPacket* pkt; + int index; MwLibraryInit(); @@ -173,6 +175,27 @@ int main() { MwComboBoxAdd(w, -1, "Hello!"); add(f); + f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL); + add(f); + + f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass, + MwNtext, "Epic text", + NULL); + add(f); + + f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass, + MwNhasHeading, 1, + NULL); + w = child(f); + pkt = MwListBoxCreatePacket(); + index = MwListBoxPacketInsert(pkt, -1); + MwListBoxPacketSet(pkt, index, 0, "Epic title..."); + index = MwListBoxPacketInsert(pkt, -1); + MwListBoxPacketSet(pkt, index, 0, "Hello"); + MwListBoxInsert(w, -1, pkt); + MwListBoxDestroyPacket(pkt); + add(f); + f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL); add(f); diff --git a/src/draw.c b/src/draw.c index 8414c72..b6e3705 100644 --- a/src/draw.c +++ b/src/draw.c @@ -117,6 +117,7 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color, int rounde MwRect r = *rect; int roundness = MwGetInteger(handle, MwNroundness); double div; + if(rect->width < 0 || rect->height < 0) return; if(roundness == MwDEFAULT) roundness = DEFAULT_ROUNDNESS; if(roundness >= MAX_ROUNDNESS) roundness = MAX_ROUNDNESS; div = (roundness <= 10) ? 7. : 10.; @@ -190,6 +191,8 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert MwLLColor col; MwBool rounded = MwGetInteger(handle, MwNroundness) != MwDEFAULT && MwGetInteger(handle, MwNisRounded) != 0; + if(rect->width < 0 || rect->height < 0) return; + if(border) { if(!handle->lowlevel->common.supports_transparency) { MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground)); @@ -287,9 +290,7 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, if(roundness == MwDEFAULT) roundness = DEFAULT_ROUNDNESS; if(roundness >= MAX_ROUNDNESS) roundness = MAX_ROUNDNESS; - if(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0) { - - } else { + if(!(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0)) { p[0].x = rect->x; p[0].y = rect->y; @@ -309,9 +310,7 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color, } MwLLPolygon(handle->lowlevel, p, 6, invert ? darker : lighter); - if(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0) { - - } else { + if(!(rounded && rect->height >= (roundness * 2) && rect->width >= (roundness * 2) && roundness > 0)) { p[0].x = rect->x + rect->width; p[0].y = rect->y; diff --git a/src/widget/entry.c b/src/widget/entry.c index b14a3a6..42b7000 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -53,30 +53,32 @@ static void draw(MwWidget handle) { len = (r.width - p.x * 2) / w; - show = malloc(len * 4 + 1); - memset(show, 0, len * 4 + 1); + if(len >= 0) { + show = malloc(len * 4 + 1); + memset(show, 0, len * 4 + 1); - start = (t->cursor - 1) / len; - start *= len; - if((attr = MwGetInteger(handle, MwNhideInput)) == MwDEFAULT || !attr) { - MwUTF8Copy(str, start, show, 0, len); - } else { - for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*'; + start = (t->cursor - 1) / len; + start *= len; + if((attr = MwGetInteger(handle, MwNhideInput)) == MwDEFAULT || !attr) { + MwUTF8Copy(str, start, show, 0, len); + } else { + for(i = 0; i < MwUTF8Length(str) - start; i++) show[i] = '*'; + } + + MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text); + + textlen = (t->cursor - 1) % len + 1; + for(i = 0; i < textlen; i++) show[i] = 'M'; + show[i] = 0; + + currc.x = p.x + MwTextWidth(handle, show); + currc.y = (r.height - h) / 2; + currc.width = 1; + currc.height = h; + MwDrawRect(handle, &currc, text); + + free(show); } - - MwDrawText(handle, &p, show, 0, MwALIGNMENT_BEGINNING, text); - - textlen = (t->cursor - 1) % len + 1; - for(i = 0; i < textlen; i++) show[i] = 'M'; - show[i] = 0; - - currc.x = p.x + MwTextWidth(handle, show); - currc.y = (r.height - h) / 2; - currc.width = 1; - currc.height = h; - MwDrawRect(handle, &currc, text); - - free(show); } MwLLFreeColor(text);