seems to work

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@276 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-11 15:55:42 +00:00
parent 8532ac96ec
commit 1574d9af33
2 changed files with 27 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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);
}