From d206493c129d2eeed856dd8e70ded01684572fce Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 15 Oct 2025 08:36:55 +0000 Subject: [PATCH] better selection git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@335 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/TypeDefs.h | 1 + src/widget/listbox.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index 4f21006..59cd8c1 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -126,6 +126,7 @@ struct _MwListBox { char** list; int selected; unsigned long click_time; + int pressed; }; struct _MwSizeHints { diff --git a/src/widget/listbox.c b/src/widget/listbox.c index 5c63e09..357268b 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -39,6 +39,36 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) { y += MwTextHeight(handle, "M"); } + MwForceRender(lb->frame); + lb->pressed = 1; + } +} + +static void frame_mouse_up(MwWidget handle, void* user, void* call) { + MwListBox lb = handle->parent->internal; + MwLLMouse* m = call; + if(m->button == MwLLMouseLeft) { + lb->pressed = 0; + } +} + +static void frame_mouse_move(MwWidget handle, void* user, void* call) { + MwListBox lb = handle->parent->internal; + MwPoint* p = call; + if(lb->pressed) { + int st = 0; + int i; + int y = MwDefaultBorderWidth; + int h = MwGetInteger(handle, MwNheight); + + st = get_first_entry(lb); + for(i = 0; i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) { + if(y <= p->y && p->y <= (y + MwTextHeight(handle, "M"))) { + lb->selected = st + i; + } + y += MwTextHeight(handle, "M"); + } + MwForceRender(lb->frame); } } @@ -104,6 +134,8 @@ static void resize(MwWidget handle) { lb->frame = MwVaCreateWidget(MwFrameClass, "frame", handle, 0, 0, w - 16, h, NULL); lb->frame->draw_inject = frame_draw; MwAddUserHandler(lb->frame, MwNmouseDownHandler, frame_mouse_down, NULL); + MwAddUserHandler(lb->frame, MwNmouseUpHandler, frame_mouse_up, NULL); + MwAddUserHandler(lb->frame, MwNmouseMoveHandler, frame_mouse_move, NULL); } else { MwVaApply(lb->frame, MwNx, 0,