Skip to content

Commit 52cd839

Browse files
committed
grid: boundary sashes
1 parent 60dea40 commit 52cd839

3 files changed

Lines changed: 64 additions & 9 deletions

File tree

src/vs/base/browser/ui/grid/grid.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'vs/css!./gridview';
77
import { Orientation } from 'vs/base/browser/ui/sash/sash';
88
import { Disposable } from 'vs/base/common/lifecycle';
99
import { tail2 as tail, equals } from 'vs/base/common/arrays';
10-
import { orthogonal, IView as IGridViewView, GridView, Sizing as GridViewSizing, Box, IGridViewStyles, IViewSize, IGridViewOptions } from './gridview';
10+
import { orthogonal, IView as IGridViewView, GridView, Sizing as GridViewSizing, Box, IGridViewStyles, IViewSize, IGridViewOptions, IBoundarySashes } from './gridview';
1111
import { Event } from 'vs/base/common/event';
1212

1313
export { Orientation, Sizing as GridViewSizing, IViewSize, orthogonal, LayoutPriority } from './gridview';
@@ -212,6 +212,9 @@ export class Grid<T extends IView = IView> extends Disposable {
212212
get maximumHeight(): number { return this.gridview.maximumHeight; }
213213
get onDidChange(): Event<{ width: number; height: number; } | undefined> { return this.gridview.onDidChange; }
214214

215+
get boundarySashes(): IBoundarySashes { return this.gridview.boundarySashes; }
216+
set boundarySashes(boundarySashes: IBoundarySashes) { this.gridview.boundarySashes = boundarySashes; }
217+
215218
get element(): HTMLElement { return this.gridview.element; }
216219

217220
private didLayout = false;

src/vs/base/browser/ui/grid/gridview.ts

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ export interface IViewSize {
2121
readonly height: number;
2222
}
2323

24-
interface IBoundarySashes {
24+
interface IRelativeBoundarySashes {
2525
readonly start?: Sash;
2626
readonly end?: Sash;
2727
readonly orthogonalStart?: Sash;
2828
readonly orthogonalEnd?: Sash;
2929
}
3030

31+
export interface IBoundarySashes {
32+
readonly top?: Sash;
33+
readonly right?: Sash;
34+
readonly bottom?: Sash;
35+
readonly left?: Sash;
36+
}
37+
3138
export interface IView {
3239
readonly element: HTMLElement;
3340
readonly minimumWidth: number;
@@ -39,6 +46,7 @@ export interface IView {
3946
readonly snap?: boolean;
4047
layout(width: number, height: number, top: number, left: number): void;
4148
setVisible?(visible: boolean): void;
49+
setBoundarySashes?(sashes: IBoundarySashes): void;
4250
}
4351

4452
export interface ISerializableView extends IView {
@@ -132,6 +140,22 @@ interface ILayoutContext {
132140
readonly absoluteOrthogonalSize: number;
133141
}
134142

143+
function toAbsoluteBoundarySashes(sashes: IRelativeBoundarySashes, orientation: Orientation): IBoundarySashes {
144+
if (orientation === Orientation.HORIZONTAL) {
145+
return { left: sashes.start, right: sashes.end, top: sashes.orthogonalStart, bottom: sashes.orthogonalEnd };
146+
} else {
147+
return { top: sashes.start, bottom: sashes.end, left: sashes.orthogonalStart, right: sashes.orthogonalEnd };
148+
}
149+
}
150+
151+
function fromAbsoluteBoundarySashes(sashes: IBoundarySashes, orientation: Orientation): IRelativeBoundarySashes {
152+
if (orientation === Orientation.HORIZONTAL) {
153+
return { start: sashes.left, end: sashes.right, orthogonalStart: sashes.top, orthogonalEnd: sashes.bottom };
154+
} else {
155+
return { start: sashes.top, end: sashes.bottom, orthogonalStart: sashes.left, orthogonalEnd: sashes.right };
156+
}
157+
}
158+
135159
class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
136160

137161
readonly element: HTMLElement;
@@ -224,13 +248,26 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
224248
private splitviewSashResetDisposable: IDisposable = Disposable.None;
225249
private childrenSashResetDisposable: IDisposable = Disposable.None;
226250

227-
private _boundarySashes: IBoundarySashes = {};
228-
get boundarySashes(): IBoundarySashes { return this._boundarySashes; }
229-
set boundarySashes(boundarySashes: IBoundarySashes) {
251+
private _boundarySashes: IRelativeBoundarySashes = {};
252+
get boundarySashes(): IRelativeBoundarySashes { return this._boundarySashes; }
253+
set boundarySashes(boundarySashes: IRelativeBoundarySashes) {
230254
this._boundarySashes = boundarySashes;
231255

232256
this.splitview.orthogonalStartSash = boundarySashes.orthogonalStart;
233257
this.splitview.orthogonalEndSash = boundarySashes.orthogonalEnd;
258+
259+
for (let index = 0; index < this.children.length; index++) {
260+
const child = this.children[index];
261+
const first = index === 0;
262+
const last = index === this.children.length - 1;
263+
264+
child.boundarySashes = {
265+
start: boundarySashes.orthogonalStart,
266+
end: boundarySashes.orthogonalEnd,
267+
orthogonalStart: first ? boundarySashes.start : child.boundarySashes.orthogonalStart,
268+
orthogonalEnd: last ? boundarySashes.end : child.boundarySashes.orthogonalEnd,
269+
};
270+
}
234271
}
235272

236273
constructor(
@@ -694,9 +731,15 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
694731
return this.orientation === Orientation.HORIZONTAL ? this.maximumWidth : this.maximumHeight;
695732
}
696733

697-
private _boundarySashes: IBoundarySashes = {};
698-
get boundarySashes(): IBoundarySashes { return this._boundarySashes; }
699-
set boundarySashes(boundarySashes: IBoundarySashes) { this._boundarySashes = boundarySashes; }
734+
private _boundarySashes: IRelativeBoundarySashes = {};
735+
get boundarySashes(): IRelativeBoundarySashes { return this._boundarySashes; }
736+
set boundarySashes(boundarySashes: IRelativeBoundarySashes) {
737+
this._boundarySashes = boundarySashes;
738+
739+
if (this.view.setBoundarySashes) {
740+
this.view.setBoundarySashes(toAbsoluteBoundarySashes(boundarySashes, this.orientation));
741+
}
742+
}
700743

701744
layout(size: number, offset: number, ctx: ILayoutContext | undefined): void {
702745
if (!this.layoutController.isLayoutEnabled) {
@@ -799,6 +842,7 @@ export class GridView implements IDisposable {
799842
const { size, orthogonalSize } = this._root;
800843
this.root = flipNode(this._root, orthogonalSize, size);
801844
this.root.layout(size, 0, { orthogonalSize, absoluteOffset: 0, absoluteOrthogonalOffset: 0, absoluteSize: size, absoluteOrthogonalSize: orthogonalSize });
845+
this.boundarySashes = this.boundarySashes;
802846
}
803847

804848
get width(): number { return this.root.width; }
@@ -812,6 +856,13 @@ export class GridView implements IDisposable {
812856
private _onDidChange = new Relay<IViewSize | undefined>();
813857
readonly onDidChange = this._onDidChange.event;
814858

859+
private _boundarySashes: IBoundarySashes = {};
860+
get boundarySashes(): IBoundarySashes { return this._boundarySashes; }
861+
set boundarySashes(boundarySashes: IBoundarySashes) {
862+
this._boundarySashes = boundarySashes;
863+
this.root.boundarySashes = fromAbsoluteBoundarySashes(boundarySashes, this.orientation);
864+
}
865+
815866
/**
816867
* The first layout controller makes sure layout only propagates
817868
* to the views after the very first call to gridview.layout()
@@ -933,6 +984,7 @@ export class GridView implements IDisposable {
933984
// we must promote sibling to be the new root
934985
parent.removeChild(0);
935986
this.root = sibling;
987+
this.boundarySashes = this.boundarySashes;
936988
return node.view;
937989
}
938990

src/vs/base/browser/ui/sash/sash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Event, Emitter } from 'vs/base/common/event';
1414
import { getElementsByTagName, EventHelper, createStyleSheet, addDisposableListener, append, $, addClass, removeClass, toggleClass } from 'vs/base/browser/dom';
1515
import { domEvent } from 'vs/base/browser/event';
1616

17-
const DEBUG = true;
17+
const DEBUG = false;
1818

1919
export interface ISashLayoutProvider { }
2020

0 commit comments

Comments
 (0)