@@ -76,6 +76,11 @@ export class LayoutController implements ILayoutController {
7676 constructor ( public isLayoutEnabled : boolean ) { }
7777}
7878
79+ export class MultiplexLayoutController implements ILayoutController {
80+ get isLayoutEnabled ( ) : boolean { return this . layoutControllers . every ( l => l . isLayoutEnabled ) ; }
81+ constructor ( private layoutControllers : ILayoutController [ ] ) { }
82+ }
83+
7984export interface IGridViewOptions {
8085 readonly styles ?: IGridViewStyles ;
8186 readonly proportionalLayout ?: boolean ; // default true
@@ -170,6 +175,7 @@ class BranchNode implements ISplitView, IDisposable {
170175
171176 constructor (
172177 readonly orientation : Orientation ,
178+ readonly layoutController : ILayoutController ,
173179 styles : IGridViewStyles ,
174180 readonly proportionalLayout : boolean ,
175181 size : number = 0 ,
@@ -181,7 +187,7 @@ class BranchNode implements ISplitView, IDisposable {
181187
182188 this . element = $ ( '.monaco-grid-branch-node' ) ;
183189 this . splitview = new SplitView ( this . element , { orientation, styles, proportionalLayout } ) ;
184- this . splitview . layout ( size ) ;
190+ this . splitview . layout ( size , orthogonalSize ) ;
185191
186192 const onDidSashReset = Event . map ( this . splitview . onDidSashReset , i => [ i ] ) ;
187193 this . splitviewSashResetDisposable = onDidSashReset ( this . _onDidSashReset . fire , this . _onDidSashReset ) ;
@@ -198,12 +204,19 @@ class BranchNode implements ISplitView, IDisposable {
198204 }
199205 }
200206
201- layout ( size : number ) : void {
202- this . _orthogonalSize = size ;
207+ layout ( size : number , orthogonalSize : number | undefined ) : void {
208+ if ( ! this . layoutController . isLayoutEnabled ) {
209+ return ;
210+ }
203211
204- for ( const child of this . children ) {
205- child . orthogonalLayout ( size ) ;
212+ if ( typeof orthogonalSize !== 'number' ) {
213+ throw new Error ( 'Invalid state' ) ;
206214 }
215+
216+ this . _size = orthogonalSize ;
217+ this . _orthogonalSize = size ;
218+
219+ this . splitview . layout ( orthogonalSize , size ) ;
207220 }
208221
209222 setVisible ( visible : boolean ) : void {
@@ -212,11 +225,6 @@ class BranchNode implements ISplitView, IDisposable {
212225 }
213226 }
214227
215- orthogonalLayout ( size : number ) : void {
216- this . _size = size ;
217- this . splitview . layout ( size ) ;
218- }
219-
220228 addChild ( node : Node , size : number | Sizing , index : number ) : void {
221229 if ( index < 0 || index > this . children . length ) {
222230 throw new Error ( 'Invalid index' ) ;
@@ -539,12 +547,18 @@ class LeafNode implements ISplitView, IDisposable {
539547 // noop
540548 }
541549
542- layout ( size : number ) : void {
543- this . _size = size ;
550+ layout ( size : number , orthogonalSize : number | undefined ) : void {
551+ if ( ! this . layoutController . isLayoutEnabled ) {
552+ return ;
553+ }
544554
545- if ( this . layoutController . isLayoutEnabled ) {
546- this . view . layout ( this . width , this . height , orthogonal ( this . orientation ) ) ;
555+ if ( typeof orthogonalSize !== 'number' ) {
556+ throw new Error ( 'Invalid state' ) ;
547557 }
558+
559+ this . _size = size ;
560+ this . _orthogonalSize = orthogonalSize ;
561+ this . view . layout ( this . width , this . height , orthogonal ( this . orientation ) ) ;
548562 }
549563
550564 setVisible ( visible : boolean ) : void {
@@ -553,22 +567,14 @@ class LeafNode implements ISplitView, IDisposable {
553567 }
554568 }
555569
556- orthogonalLayout ( size : number ) : void {
557- this . _orthogonalSize = size ;
558-
559- if ( this . layoutController . isLayoutEnabled ) {
560- this . view . layout ( this . width , this . height , orthogonal ( this . orientation ) ) ;
561- }
562- }
563-
564570 dispose ( ) : void { }
565571}
566572
567573type Node = BranchNode | LeafNode ;
568574
569575function flipNode < T extends Node > ( node : T , size : number , orthogonalSize : number ) : T {
570576 if ( node instanceof BranchNode ) {
571- const result = new BranchNode ( orthogonal ( node . orientation ) , node . styles , node . proportionalLayout , size , orthogonalSize ) ;
577+ const result = new BranchNode ( orthogonal ( node . orientation ) , node . layoutController , node . styles , node . proportionalLayout , size , orthogonalSize ) ;
572578
573579 let totalSize = 0 ;
574580
@@ -589,7 +595,7 @@ function flipNode<T extends Node>(node: T, size: number, orthogonalSize: number)
589595
590596 return result as T ;
591597 } else {
592- return new LeafNode ( ( node as LeafNode ) . view , orthogonal ( node . orientation ) , ( node as LeafNode ) . layoutController , orthogonalSize ) as T ;
598+ return new LeafNode ( ( node as LeafNode ) . view , orthogonal ( node . orientation ) , node . layoutController , orthogonalSize ) as T ;
593599 }
594600}
595601
@@ -634,8 +640,9 @@ export class GridView implements IDisposable {
634640
635641 const { size, orthogonalSize } = this . _root ;
636642 this . root = flipNode ( this . _root , orthogonalSize , size ) ;
637- this . root . layout ( size ) ;
638- this . root . orthogonalLayout ( orthogonalSize ) ;
643+ this . root . layout ( size , orthogonalSize ) ;
644+ // this.root.layout(size);
645+ // this.root.orthogonalLayout(orthogonalSize);
639646 }
640647
641648 get width ( ) : number { return this . root . width ; }
@@ -649,14 +656,25 @@ export class GridView implements IDisposable {
649656 private _onDidChange = new Relay < IViewSize | undefined > ( ) ;
650657 readonly onDidChange = this . _onDidChange . event ;
651658
659+ /**
660+ * The first layout controller makes sure layout only propagates
661+ * to the views after the very first call to gridview.layout()
662+ */
663+ private firstLayoutController : LayoutController ;
652664 private layoutController : LayoutController ;
653665
654666 constructor ( options : IGridViewOptions = { } ) {
655667 this . element = $ ( '.monaco-grid-view' ) ;
656668 this . styles = options . styles || defaultStyles ;
657669 this . proportionalLayout = typeof options . proportionalLayout !== 'undefined' ? ! ! options . proportionalLayout : true ;
658- this . root = new BranchNode ( Orientation . VERTICAL , this . styles , this . proportionalLayout ) ;
659- this . layoutController = options . layoutController || new LayoutController ( true ) ;
670+
671+ this . firstLayoutController = new LayoutController ( false ) ;
672+ this . layoutController = new MultiplexLayoutController ( [
673+ this . firstLayoutController ,
674+ ...( options . layoutController ? [ options . layoutController ] : [ ] )
675+ ] ) ;
676+
677+ this . root = new BranchNode ( Orientation . VERTICAL , this . layoutController , this . styles , this . proportionalLayout ) ;
660678 }
661679
662680 style ( styles : IGridViewStyles ) : void {
@@ -665,9 +683,10 @@ export class GridView implements IDisposable {
665683 }
666684
667685 layout ( width : number , height : number ) : void {
686+ this . firstLayoutController . isLayoutEnabled = true ;
687+
668688 const [ size , orthogonalSize ] = this . root . orientation === Orientation . HORIZONTAL ? [ height , width ] : [ width , height ] ;
669- this . root . layout ( size ) ;
670- this . root . orthogonalLayout ( orthogonalSize ) ;
689+ this . root . layout ( size , orthogonalSize ) ;
671690 }
672691
673692 addView ( view : IView , size : number | Sizing , location : number [ ] ) : void {
@@ -694,9 +713,8 @@ export class GridView implements IDisposable {
694713
695714 grandParent . removeChild ( parentIndex ) ;
696715
697- const newParent = new BranchNode ( parent . orientation , this . styles , this . proportionalLayout , parent . size , parent . orthogonalSize ) ;
716+ const newParent = new BranchNode ( parent . orientation , parent . layoutController , this . styles , this . proportionalLayout , parent . size , parent . orthogonalSize ) ;
698717 grandParent . addChild ( newParent , parent . size , parentIndex ) ;
699- newParent . orthogonalLayout ( parent . orthogonalSize ) ;
700718
701719 const newSibling = new LeafNode ( parent . view , grandParent . orientation , this . layoutController , parent . size ) ;
702720 newParent . addChild ( newSibling , newSiblingSize , 0 ) ;
@@ -827,9 +845,6 @@ export class GridView implements IDisposable {
827845
828846 fromParent . addChild ( toNode , fromSize , fromIndex ) ;
829847 toParent . addChild ( fromNode , toSize , toIndex ) ;
830-
831- fromParent . layout ( fromParent . orthogonalSize ) ;
832- toParent . layout ( toParent . orthogonalSize ) ;
833848 }
834849 }
835850
0 commit comments