From ba4010eb52691770ba92076088f7c3e431aa3bcb Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Thu, 16 Oct 2025 10:38:37 +0000 Subject: [PATCH] icon git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@360 b9cfdab3-6d41-4d17-bbe4-086880011989 --- examples/basic/listbox.c | 2 +- include/Mw/Widget/ListBox.h | 6 ++++-- src/widget/listbox.c | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/basic/listbox.c b/examples/basic/listbox.c index 4197e0a..789f50a 100644 --- a/examples/basic/listbox.c +++ b/examples/basic/listbox.c @@ -26,7 +26,7 @@ int main() { lb = MwCreateWidget(MwListBoxClass, "listbox", wmain, 5, 5, 630, 470); MwAddUserHandler(lb, MwNactivateHandler, activate, NULL); - MwListBoxInsertMultiple(lb, -1, (char**)harvard, sizeof(harvard) / sizeof(harvard[0]) - 1); + MwListBoxInsertMultiple(lb, -1, (char**)harvard, NULL, sizeof(harvard) / sizeof(harvard[0]) - 1); MwLoop(wmain); } diff --git a/include/Mw/Widget/ListBox.h b/include/Mw/Widget/ListBox.h index 5ac6182..838d9c6 100644 --- a/include/Mw/Widget/ListBox.h +++ b/include/Mw/Widget/ListBox.h @@ -24,17 +24,19 @@ MWDECL MwClass MwListBoxClass; * %param handle Widget * %param index Index * %param text Text + * %param pixmap Pixmap */ -MWDECL void MwListBoxInsert(MwWidget handle, int index, const char* text); +MWDECL void MwListBoxInsert(MwWidget handle, int index, const char* text, MwLLPixmap pixmap); /*! * %brief Inserts multiple items on the listbox * %param handle Widget * %param index Index * %param text Text + * %param pixmap Pixmap * %param count Count */ -MWDECL void MwListBoxInsertMultiple(MwWidget handle, int index, char** text, int count); +MWDECL void MwListBoxInsertMultiple(MwWidget handle, int index, char** text, MwLLPixmap* pixmap, int count); /*! * %brief Deletes item from the listbox diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 3437178..77a8a41 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -105,10 +105,11 @@ static void frame_draw(MwWidget handle) { } if(lb->pixmap_list[i] != NULL) { MwRect r2; + int h = (lb->pixmap_list[i]->height > MwTextHeight(handle, "M")) ? MwTextHeight(handle, "M") : lb->pixmap_list[i]->height; r2.x = MwDefaultBorderWidth; - r2.y = p.y + (MwTextHeight(handle, "M") - lb->pixmap_list[i]->height) / 2; - r2.width = lb->pixmap_list[i]->width; - r2.height = lb->pixmap_list[i]->height; + r2.y = p.y + (MwTextHeight(handle, "M") - h) / 2; + r2.width = h * lb->pixmap_list[i]->width / lb->pixmap_list[i]->height; + r2.height = h; MwLLDrawPixmap(handle->lowlevel, &r2, lb->pixmap_list[i]); } p.y += MwTextHeight(handle, lb->list[i]) / 2; @@ -228,7 +229,7 @@ MwClassRec MwListBoxClassRec = { NULL}; MwClass MwListBoxClass = &MwListBoxClassRec; -void MwListBoxInsert(MwWidget handle, int index, const char* text) { +void MwListBoxInsert(MwWidget handle, int index, const char* text, MwLLPixmap pixmap) { char* str = malloc(strlen(text) + 1); MwListBox lb = handle->internal; @@ -236,7 +237,7 @@ void MwListBoxInsert(MwWidget handle, int index, const char* text) { if(index == -1) index = arrlen(lb->list); arrins(lb->list, index, str); - arrins(lb->pixmap_list, index, NULL); + arrins(lb->pixmap_list, index, pixmap); resize(handle); if(index < (MwGetInteger(lb->vscroll, MwNvalue) + MwGetInteger(lb->vscroll, MwNareaShown))) { @@ -244,7 +245,7 @@ void MwListBoxInsert(MwWidget handle, int index, const char* text) { } } -void MwListBoxInsertMultiple(MwWidget handle, int index, char** text, int count) { +void MwListBoxInsertMultiple(MwWidget handle, int index, char** text, MwLLPixmap* pixmap, int count) { int i; MwListBox lb = handle->internal; int old; @@ -256,7 +257,11 @@ void MwListBoxInsertMultiple(MwWidget handle, int index, char** text, int count) strcpy(str, text[i]); arrins(lb->list, index, str); - arrins(lb->pixmap_list, index, NULL); + if(pixmap == NULL) { + arrins(lb->pixmap_list, index, NULL); + } else { + arrins(lb->pixmap_list, index, pixmap[i]); + } index++; }