better selection

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@335 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-15 08:36:55 +00:00
parent 6aadadc268
commit d206493c12
2 changed files with 33 additions and 0 deletions

View File

@@ -126,6 +126,7 @@ struct _MwListBox {
char** list;
int selected;
unsigned long click_time;
int pressed;
};
struct _MwSizeHints {

View File

@@ -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,