MCPcopy
hub / github.com/mathuo/dockview / layoutViews

Method layoutViews

packages/dockview-core/src/splitview/splitview.ts:800–890  ·  view source on GitHub ↗

* Margin explain: * * For `n` views in a splitview there will be `n-1` margins `m`. * * To fit the margins each view must reduce in size by `(m * (n - 1)) / n`. * * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.

()

Source from the content-addressed store, hash-verified

798 * For each view `i` the offet must be adjusted by `m * i/(n - 1)`.
799 */
800 private layoutViews(): void {
801 this._contentSize = this.viewItems.reduce((r, i) => r + i.size, 0);
802
803 this.updateSashEnablement();
804
805 if (this.viewItems.length === 0) {
806 return;
807 }
808
809 const visibleViewItems = this.viewItems.filter((i) => i.visible);
810
811 const sashCount = Math.max(0, visibleViewItems.length - 1);
812 const marginReducedSize =
813 (this.margin * sashCount) / Math.max(1, visibleViewItems.length);
814
815 let totalLeftOffset = 0;
816 const viewLeftOffsets: number[] = [];
817
818 const sashWidth = 4; // hardcoded in css
819
820 const runningVisiblePanelCount = this.viewItems.reduce(
821 (arr, viewItem, i) => {
822 const flag = viewItem.visible ? 1 : 0;
823 if (i === 0) {
824 arr.push(flag);
825 } else {
826 arr.push(arr[i - 1] + flag);
827 }
828
829 return arr;
830 },
831 [] as number[]
832 );
833
834 // calculate both view and cash positions
835 this.viewItems.forEach((view, i) => {
836 totalLeftOffset += this.viewItems[i].size;
837 viewLeftOffsets.push(totalLeftOffset);
838
839 const size = view.visible ? view.size - marginReducedSize : 0;
840
841 const visiblePanelsBeforeThisView = Math.max(
842 0,
843 runningVisiblePanelCount[i] - 1
844 );
845
846 const offset =
847 i === 0 || visiblePanelsBeforeThisView === 0
848 ? 0
849 : viewLeftOffsets[i - 1] +
850 (visiblePanelsBeforeThisView / sashCount) *
851 marginReducedSize;
852
853 if (i < this.viewItems.length - 1) {
854 // calculate sash position
855 const newSize = view.visible
856 ? offset + size - sashWidth / 2 + this.margin / 2
857 : offset;

Callers 4

setViewVisibleMethod · 0.95
onPointerMoveMethod · 0.95
layoutMethod · 0.95
relayoutMethod · 0.95

Calls 3

updateSashEnablementMethod · 0.95
pushMethod · 0.80
layoutMethod · 0.65

Tested by

no test coverage detected