From a652514ab0f2865d36530d3d149145ce4482d44e Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Thu, 9 Apr 2026 03:42:45 +0900 Subject: [PATCH] always use monospace for listbox --- src/widget/listbox.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 855fa51..a4511b5 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -4,6 +4,8 @@ #define Padding 2 +#define Font MwFLBuildFont(MwFLFlagMonospace) + MwListBoxPacket* MwListBoxCreatePacket(void) { MwListBoxPacket* packet = malloc(sizeof(*packet)); memset(packet, 0, sizeof(*packet)); @@ -129,8 +131,8 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) { int h = MwGetInteger(handle, MwNheight); st = get_first_entry(handle->parent, lb); - for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, NULL, "M") + Padding) + 2; i++) { - if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, NULL, "M") + Padding)) { + for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, Font, "M") + Padding) + 2; i++) { + if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, Font, "M") + Padding)) { unsigned long t; int old = MwGetInteger(handle->parent, MwNvalue); @@ -143,7 +145,7 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) { lb->click_time = t; } - y += MwTextHeight(handle, NULL, "M") + Padding; + y += MwTextHeight(handle, Font, "M") + Padding; } MwForceRender(lb->frame); @@ -175,11 +177,11 @@ static void frame_mouse_move(MwWidget handle, void* user, void* call) { int h = MwGetInteger(handle, MwNheight); st = get_first_entry(handle->parent, lb); - for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, NULL, "M") + Padding) + 2; i++) { - if(y <= p->y && p->y <= (y + MwTextHeight(handle, NULL, "M") + Padding)) { + for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth(handle) * 2) / (MwTextHeight(handle, Font, "M") + Padding) + 2; i++) { + if(y <= p->y && p->y <= (y + MwTextHeight(handle, Font, "M") + Padding)) { MwSetInteger(handle->parent, MwNvalue, st + i); } - y += MwTextHeight(handle, NULL, "M") + Padding; + y += MwTextHeight(handle, Font, "M") + Padding; } MwForceRender(lb->frame); @@ -227,20 +229,20 @@ static void frame_draw(MwWidget handle) { r2.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding); r2.y = p.y; r2.width = r.width - r2.x; - r2.height = MwTextHeight(handle, NULL, "M") + Padding; + r2.height = MwTextHeight(handle, Font, "M") + Padding; MwDrawRect(handle, &r2, text2); handle->bgcolor = text2; } if(lb->list[i].pixmap != NULL) { MwRect r2; - int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, NULL, "M") + Padding)) ? (MwTextHeight(handle, NULL, "M") + Padding) : lb->list[i].pixmap->common.height; + int h = (lb->list[i].pixmap->common.height > (MwTextHeight(handle, Font, "M") + Padding)) ? (MwTextHeight(handle, Font, "M") + Padding) : lb->list[i].pixmap->common.height; r2.x = MwDefaultBorderWidth(handle); - r2.y = p.y + (MwTextHeight(handle, NULL, "M") + Padding - h) / 2; + r2.y = p.y + (MwTextHeight(handle, Font, "M") + Padding - h) / 2; r2.width = h * lb->list[i].pixmap->common.width / lb->list[i].pixmap->common.height; r2.height = h; MwLLDrawPixmap(handle->lowlevel, &r2, lb->list[i].pixmap); } - p.y += (MwTextHeight(handle, NULL, "M") + Padding) / 2; + p.y += (MwTextHeight(handle, Font, "M") + Padding) / 2; p.x = MwDefaultBorderWidth(handle) + MwGetInteger(handle->parent, MwNleftPadding); for(j = 0; j < arrlen(lb->list[i].name); j++) { char* t = lb->list[i].name[j]; @@ -250,8 +252,8 @@ static void frame_draw(MwWidget handle) { if(t == NULL) t = ""; str = MwStringDuplicate(t); - if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, NULL, "M")) { - int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, NULL, "M"); + if(MwUTF8Length(str) > (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M")) { + int ind = (get_col_width(lb, j) - l) / MwTextWidth(handle, Font, "M"); str[ind] = 0; if(ind > 3) memset(str + ind - 3, '.', 3); } @@ -259,26 +261,26 @@ static void frame_draw(MwWidget handle) { if(j == (arrlen(lb->list[i].name) - 1)) p.x -= MwDefaultBorderWidth(handle); if(arrlen(lb->alignment) <= j || lb->alignment[j] == MwALIGNMENT_BEGINNING) { p.x += 4; - MwDrawText(handle, NULL, &p, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2); + MwDrawText(handle, Font, &p, str, MwALIGNMENT_BEGINNING, selected ? base2 : text2); p.x -= 4; p.x += get_col_width(lb, j); } else if(lb->alignment[j] == MwALIGNMENT_CENTER) { p.x += (get_col_width(lb, j) - l) / 2; - MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, selected ? base2 : text2); + MwDrawText(handle, Font, &p, str, MwALIGNMENT_CENTER, selected ? base2 : text2); p.x += (get_col_width(lb, j) - l) / 2; p.x += l; } else if(lb->alignment[j] == MwALIGNMENT_END) { p.x += get_col_width(lb, j); p.x -= 4; - MwDrawText(handle, NULL, &p, str, MwALIGNMENT_END, selected ? base2 : text2); + MwDrawText(handle, Font, &p, str, MwALIGNMENT_END, selected ? base2 : text2); p.x += 4; } free(str); if(j == 0) p.x -= MwGetInteger(handle->parent, MwNleftPadding); } - p.y += (MwTextHeight(handle, NULL, "M") + Padding) / 2; + p.y += (MwTextHeight(handle, Font, "M") + Padding) / 2; handle->bgcolor = NULL; }