From 1574d9af33846158b9d99df0a734fe40a02876e8 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 11 Oct 2025 15:55:42 +0000 Subject: [PATCH] seems to work git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@276 b9cfdab3-6d41-4d17-bbe4-086880011989 --- src/widget/scrollbar.c | 2 +- src/widget/viewport.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index c377eb9..eca867d 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -32,7 +32,7 @@ static int calc_length(MwWidget handle) { int max = MwScrollBarGetVisibleLength(handle); int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue); int area = MwGetInteger(handle, MwNareaShown); - if(area > MwGetInteger(handle, MwNmaxValue)) area = MwGetInteger(handle, MwNmaxValue); + if(area > len) area = len; return max * (double)area / len; } diff --git a/src/widget/viewport.c b/src/widget/viewport.c index dff85dc..e667869 100644 --- a/src/widget/viewport.c +++ b/src/widget/viewport.c @@ -11,6 +11,10 @@ typedef struct viewport { static void vscroll_changed(MwWidget handle, void* user, void* call) { viewport_t* vp = user; int v = MwGetInteger(handle, MwNvalue); + int mv = MwGetInteger(handle, MwNmaxValue); + int l = MwGetInteger(vp->frame, MwNheight); + v = (mv - l) * (double)v / mv; + if(v < 0) v = 0; MwVaApply(vp->inframe, MwNy, -v, NULL); @@ -19,6 +23,10 @@ static void vscroll_changed(MwWidget handle, void* user, void* call) { static void hscroll_changed(MwWidget handle, void* user, void* call) { viewport_t* vp = user; int v = MwGetInteger(handle, MwNvalue); + int mv = MwGetInteger(handle, MwNmaxValue); + int l = MwGetInteger(vp->frame, MwNwidth); + v = (mv - l) * (double)v / mv; + if(v < 0) v = 0; MwVaApply(vp->inframe, MwNx, -v, NULL); @@ -28,6 +36,8 @@ static void resize(MwWidget handle) { viewport_t* vp = handle->internal; int w = MwGetInteger(handle, MwNwidth); int h = MwGetInteger(handle, MwNheight); + int iw, ix; + int ih, iy; if(vp->vscroll == NULL) { vp->vscroll = MwVaCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h - 16, NULL); MwAddUserHandler(vp->vscroll, MwNchangedHandler, vscroll_changed, vp); @@ -64,13 +74,27 @@ static void resize(MwWidget handle) { vp->inframe = MwCreateWidget(MwFrameClass, "inframe", vp->frame, 0, 0, w - 16, h - 16); } + iw = MwGetInteger(vp->inframe, MwNwidth); + ih = MwGetInteger(vp->inframe, MwNheight); + + iy = MwGetInteger(vp->vscroll, MwNvalue); + if(iy > ih) iy = ih; MwVaApply(vp->vscroll, MwNareaShown, h - 16, + MwNmaxValue, ih, + MwNvalue, iy, NULL); + ix = MwGetInteger(vp->hscroll, MwNvalue); + if(ix > iw) ix = iw; MwVaApply(vp->hscroll, MwNareaShown, w - 16, + MwNmaxValue, iw, + MwNvalue, ix, NULL); + + vscroll_changed(vp->vscroll, vp, NULL); + hscroll_changed(vp->hscroll, vp, NULL); } static int create(MwWidget handle) { @@ -131,16 +155,10 @@ MwWidget MwViewportGetViewport(MwWidget handle) { void MwViewportSetSize(MwWidget handle, int w, int h) { viewport_t* vp = handle->internal; - MwVaApply(vp->vscroll, - MwNmaxValue, h, - NULL); - - MwVaApply(vp->hscroll, - MwNmaxValue, w, - NULL); - MwVaApply(vp->inframe, MwNwidth, w, MwNheight, h, NULL); + + resize(handle); }