From 187956133718adcaa75f9fafe46772bd9c7bcc64 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 24 Oct 2018 17:43:18 -0700 Subject: [PATCH] grid: pass priority, snapSize and proportionalLayout down to splitview related to #50853 --- src/vs/base/browser/ui/grid/gridview.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/vs/base/browser/ui/grid/gridview.ts b/src/vs/base/browser/ui/grid/gridview.ts index 2892dde50a9f8..2a066cbb2bf8a 100644 --- a/src/vs/base/browser/ui/grid/gridview.ts +++ b/src/vs/base/browser/ui/grid/gridview.ts @@ -6,13 +6,13 @@ import 'vs/css!./gridview'; import { Event, anyEvent, Emitter, mapEvent, Relay } from 'vs/base/common/event'; import { Orientation, Sash } from 'vs/base/browser/ui/sash/sash'; -import { SplitView, IView as ISplitView, Sizing, ISplitViewStyles } from 'vs/base/browser/ui/splitview/splitview'; +import { SplitView, IView as ISplitView, Sizing, LayoutPriority, ISplitViewStyles } from 'vs/base/browser/ui/splitview/splitview'; import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { $ } from 'vs/base/browser/dom'; import { tail2 as tail } from 'vs/base/common/arrays'; import { Color } from 'vs/base/common/color'; -export { Sizing } from 'vs/base/browser/ui/splitview/splitview'; +export { Sizing, LayoutPriority } from 'vs/base/browser/ui/splitview/splitview'; export { Orientation } from 'vs/base/browser/ui/sash/sash'; export interface IView { @@ -22,6 +22,8 @@ export interface IView { readonly minimumHeight: number; readonly maximumHeight: number; readonly onDidChange: Event<{ width: number; height: number; }>; + readonly priority?: LayoutPriority; + readonly snapSize?: number; layout(width: number, height: number): void; } @@ -60,6 +62,7 @@ const defaultStyles: IGridViewStyles = { export interface IGridViewOptions { styles?: IGridViewStyles; + proportionalLayout?: boolean; // default true } class BranchNode implements ISplitView, IDisposable { @@ -135,6 +138,7 @@ class BranchNode implements ISplitView, IDisposable { constructor( readonly orientation: Orientation, styles: IGridViewStyles, + readonly proportionalLayout: boolean, size: number = 0, orthogonalSize: number = 0 ) { @@ -450,6 +454,14 @@ class LeafNode implements ISplitView, IDisposable { return this.orientation === Orientation.HORIZONTAL ? this.maximumHeight : this.maximumWidth; } + get priority(): LayoutPriority { + return this.view.priority; + } + + get snapSize(): number | undefined { + return this.view.snapSize; + } + get minimumOrthogonalSize(): number { return this.orientation === Orientation.HORIZONTAL ? this.minimumWidth : this.minimumHeight; } @@ -483,7 +495,7 @@ type Node = BranchNode | LeafNode; function flipNode(node: T, size: number, orthogonalSize: number): T { if (node instanceof BranchNode) { - const result = new BranchNode(orthogonal(node.orientation), node.styles, size, orthogonalSize); + const result = new BranchNode(orthogonal(node.orientation), node.styles, node.proportionalLayout, size, orthogonalSize); let totalSize = 0; @@ -512,6 +524,7 @@ export class GridView implements IDisposable { readonly element: HTMLElement; private styles: IGridViewStyles; + private proportionalLayout: boolean; private _root: BranchNode; private onDidSashResetRelay = new Relay(); @@ -566,7 +579,8 @@ export class GridView implements IDisposable { constructor(options: IGridViewOptions = {}) { this.element = $('.monaco-grid-view'); this.styles = options.styles || defaultStyles; - this.root = new BranchNode(Orientation.VERTICAL, this.styles); + this.proportionalLayout = typeof options.proportionalLayout !== 'undefined' ? !!options.proportionalLayout : true; + this.root = new BranchNode(Orientation.VERTICAL, this.styles, this.proportionalLayout); } style(styles: IGridViewStyles): void { @@ -596,7 +610,7 @@ export class GridView implements IDisposable { const [, parentIndex] = tail(rest); grandParent.removeChild(parentIndex); - const newParent = new BranchNode(parent.orientation, this.styles, parent.size, parent.orthogonalSize); + const newParent = new BranchNode(parent.orientation, this.styles, this.proportionalLayout, parent.size, parent.orthogonalSize); grandParent.addChild(newParent, parent.size, parentIndex); newParent.orthogonalLayout(parent.orthogonalSize);