Skip to content

Commit b155a8a

Browse files
committed
updatemenu: fix computation of scrollbox size
* Ensure scrollbox size is recomputed every time, drawButtons is called.
1 parent 3b17d1d commit b155a8a

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

src/components/updatemenus/draw.js

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {
314314
index: 0,
315315
};
316316

317+
var scrollBoxPosition = {
318+
l: posOpts.x + menuOpts.borderwidth,
319+
t: posOpts.y + menuOpts.borderwidth
320+
};
321+
317322
buttons.each(function(buttonOpts, buttonIndex) {
318323
var button = d3.select(this);
319324

@@ -344,49 +349,29 @@ function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {
344349

345350
buttons.call(styleButtons, menuOpts);
346351

352+
if(isVertical) {
353+
scrollBoxPosition.w = Math.max(menuOpts.openWidth, menuOpts.headerWidth);
354+
scrollBoxPosition.h = posOpts.y - scrollBoxPosition.t;
355+
}
356+
else {
357+
scrollBoxPosition.w = posOpts.x - scrollBoxPosition.l;
358+
scrollBoxPosition.h = Math.max(menuOpts.openHeight, menuOpts.headerHeight);
359+
}
360+
347361
if(scrollBox) {
348362
if(buttons.size()) {
349-
drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts);
363+
drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, scrollBoxPosition);
350364
}
351365
else {
352366
hideScrollBox(scrollBox);
353367
}
354368
}
355369
}
356370

357-
function drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts) {
371+
function drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, position) {
358372
// enable the scrollbox
359373
var direction = menuOpts.direction,
360-
isUp = (direction === 'up'),
361-
isDown = (direction === 'down'),
362-
isLeft = (direction === 'left'),
363-
isRight = (direction === 'right'),
364-
isVertical = (isUp || isDown);
365-
366-
var x0, y0;
367-
if(isDown) {
368-
x0 = 0;
369-
y0 = menuOpts.headerHeight + constants.gapButtonHeader;
370-
}
371-
else if(isUp) {
372-
x0 = 0;
373-
y0 = menuOpts.headerHeight + constants.gapButton - menuOpts.openHeight;
374-
}
375-
else if(isRight) {
376-
x0 = menuOpts.headerWidth + constants.gapButtonHeader;
377-
y0 = 0;
378-
}
379-
else if(isLeft) {
380-
x0 = menuOpts.headerWidth + constants.gapButton - menuOpts.openWidth;
381-
y0 = 0;
382-
}
383-
384-
var position = {
385-
l: menuOpts.lx + menuOpts.borderwidth + x0 + menuOpts.pad.l,
386-
t: menuOpts.ly + menuOpts.borderwidth + y0 + menuOpts.pad.t,
387-
w: Math.max(menuOpts.openWidth, menuOpts.headerWidth),
388-
h: menuOpts.openHeight
389-
};
374+
isVertical = (direction === 'up' || direction === 'down');
390375

391376
var active = menuOpts.active,
392377
translateX, translateY,

0 commit comments

Comments
 (0)