From 29773729021654bf1e7df697fb969b3165dae482 Mon Sep 17 00:00:00 2001 From: Idle <651462+reonZ@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:41:49 +0200 Subject: [PATCH] improve? columns algorithm --- src/hud/sidebar/base.ts | 53 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/hud/sidebar/base.ts b/src/hud/sidebar/base.ts index 2c29772..df9dcd5 100644 --- a/src/hud/sidebar/base.ts +++ b/src/hud/sidebar/base.ts @@ -110,32 +110,6 @@ abstract class PF2eHudSidebar extends foundry.applications.api return htmlQuery(this.innerElement, ".item-list"); } - /** - * total height if there was overflow allowed - */ - get virtualHeight() { - const scrollElement = this.scrollElement; - const elementStyle = getComputedStyle(this.element); - const innerStyle = getComputedStyle(this.innerElement); - return ( - (scrollElement?.scrollHeight ?? 0) + - parseFloat(elementStyle.paddingTop) + - parseFloat(elementStyle.paddingBottom) + - parseInt(innerStyle.borderTopWidth) + - parseInt(innerStyle.borderBottomWidth) + - 4 - ); - } - - /** - * max height limited by the parent hud allotted bounds - */ - get maxHeight() { - const { limits } = this.parentHUD.anchor; - const allottedHeight = (limits?.bottom ?? window.innerHeight) - (limits?.top ?? 0); - return allottedHeight * (this.getSetting("sidebarHeight") / 100); - } - abstract _activateListeners(html: HTMLElement): void; async _preFirstRender( @@ -244,8 +218,8 @@ abstract class PF2eHudSidebar extends foundry.applications.api const multiColumns = this.getSetting("multiColumns"); if (multiColumns > 1) { - const maxHeight = this.maxHeight; - const virtualHeight = this.virtualHeight; + const maxHeight = this.getMaxHeight(true); + const virtualHeight = (this.scrollElement?.scrollHeight ?? 0) + 8; const columns = Math.clamp(Math.ceil(virtualHeight / maxHeight), 1, multiColumns); if (columns > 1) { @@ -263,7 +237,7 @@ abstract class PF2eHudSidebar extends foundry.applications.api if (!element) return position; const anchor = this.parentHUD.anchor; - const maxHeight = this.maxHeight; + const maxHeight = this.getMaxHeight(); const bounds = element.getBoundingClientRect(); const center: Point = { x: anchor.x, y: anchor.y }; const limits = { @@ -299,6 +273,27 @@ abstract class PF2eHudSidebar extends foundry.applications.api return super.close(options); } + getMaxHeight(inner?: boolean) { + const { limits } = this.parentHUD.anchor; + const allottedHeight = (limits?.bottom ?? window.innerHeight) - (limits?.top ?? 0); + const maxHeight = allottedHeight * (this.getSetting("sidebarHeight") / 100); + + if (inner) { + const elementStyle = getComputedStyle(this.element); + const innerStyle = getComputedStyle(this.innerElement); + + return ( + maxHeight - + parseFloat(elementStyle.paddingTop) - + parseFloat(elementStyle.paddingBottom) - + parseInt(innerStyle.borderTopWidth) - + parseInt(innerStyle.borderBottomWidth) + ); + } + + return maxHeight; + } + getSetting(key: K): SidebarSettings[K]; getSetting(key: K): GlobalSettings[K]; getSetting(key: K) {