empty track (no knob) when board fits, add fit tolerance (v1.5.1)

This commit is contained in:
2026-07-08 09:48:49 -03:00
parent f0d9974a31
commit 89292492db
3 changed files with 23 additions and 7 deletions

View File

@@ -26,6 +26,10 @@
// Keep the thumb wide enough to grab, even on a very wide board. // Keep the thumb wide enough to grab, even on a very wide board.
var MIN_THUMB = 24; var MIN_THUMB = 24;
// Ignore a few px of residual overflow (padding / sub-pixel rounding) so a board that visually
// fits is treated as "no horizontal scroll" instead of showing an immovable near-full thumb.
var FIT_TOLERANCE = 4;
function getContainer() { function getContainer() {
return document.getElementById("board-container"); return document.getElementById("board-container");
} }
@@ -74,17 +78,29 @@
thumb.style.transform = "translateX(" + Math.round(left) + "px)"; thumb.style.transform = "translateX(" + Math.round(left) + "px)";
} }
// Recompute thumb width/position; hide the whole bar when nothing to scroll. // The board needs scrolling only if its content exceeds the viewport by more than the
// tolerance (absorbs a residual px or two so a fitting board reads as "no scroll").
function needsScroll(m) {
return m && m.content - m.viewport > FIT_TOLERANCE;
}
// Recompute the thumb. The (light) track stays visible for a STABLE height; when the board
// fits, just drop the knob (thumb width 0) so it reads as "nothing to scroll" without the
// layout jump that hiding the whole bar would cause.
function layout() { function layout() {
var m = metrics(); var m = metrics();
if (!m || m.content <= m.viewport || m.trackW <= 0) { if (!m || m.trackW <= 0) {
track.style.display = "none";
return; return;
} }
track.style.display = ""; track.style.display = "";
if (!needsScroll(m)) {
thumb.style.width = "0px";
return;
}
var thumbW = Math.round(m.trackW * m.viewport / m.content); var thumbW = Math.round(m.trackW * m.viewport / m.content);
if (thumbW < MIN_THUMB) { thumbW = MIN_THUMB; } if (thumbW < MIN_THUMB) { thumbW = MIN_THUMB; }
if (thumbW > m.trackW) { thumbW = m.trackW; } if (thumbW > m.trackW) { thumbW = m.trackW; }
@@ -107,7 +123,7 @@
if (dragging) { return; } if (dragging) { return; }
if (e.target !== getContainer()) { return; } if (e.target !== getContainer()) { return; }
var m = metrics(); var m = metrics();
if (!m || m.content <= m.viewport) { return; } if (!needsScroll(m)) { return; }
positionThumb(m, thumb.offsetWidth); positionThumb(m, thumb.offsetWidth);
}, true); }, true);
@@ -153,7 +169,7 @@
track.addEventListener("pointerdown", function (e) { track.addEventListener("pointerdown", function (e) {
if (e.target === thumb || dragging) { return; } if (e.target === thumb || dragging) { return; }
var m = metrics(); var m = metrics();
if (!m || m.content <= m.viewport) { return; } if (!needsScroll(m)) { return; }
var thumbW = thumb.offsetWidth; var thumbW = thumb.offsetWidth;
var maxThumb = m.trackW - thumbW; var maxThumb = m.trackW - thumbW;

View File

@@ -51,7 +51,7 @@ class Plugin extends Base
public function getPluginVersion() public function getPluginVersion()
{ {
return '1.5.0'; return '1.5.1';
} }
public function getPluginHomepage() public function getPluginHomepage()

View File

@@ -1 +1 @@
ShrinkVertically v1.5 ShrinkVertically v1.5.1