@@ -23,14 +23,14 @@ const defaultStyles: ISplitViewStyles = {
2323 separatorBorder : Color . transparent
2424} ;
2525
26- export interface ISplitViewOptions {
26+ export interface ISplitViewOptions < TLayoutContext = undefined > {
2727 readonly orientation ?: Orientation ; // default Orientation.VERTICAL
2828 readonly styles ?: ISplitViewStyles ;
2929 readonly orthogonalStartSash ?: Sash ;
3030 readonly orthogonalEndSash ?: Sash ;
3131 readonly inverseAltBehavior ?: boolean ;
3232 readonly proportionalLayout ?: boolean ; // default true,
33- readonly descriptor ?: ISplitViewDescriptor ;
33+ readonly descriptor ?: ISplitViewDescriptor < TLayoutContext > ;
3434}
3535
3636/**
@@ -42,14 +42,14 @@ export const enum LayoutPriority {
4242 High
4343}
4444
45- export interface IView {
45+ export interface IView < TLayoutContext = undefined > {
4646 readonly element : HTMLElement ;
4747 readonly minimumSize : number ;
4848 readonly maximumSize : number ;
4949 readonly onDidChange : Event < number | undefined > ;
5050 readonly priority ?: LayoutPriority ;
5151 readonly snap ?: boolean ;
52- layout ( size : number , orthogonalSize : number | undefined ) : void ;
52+ layout ( size : number , offset : number , context : TLayoutContext | undefined ) : void ;
5353 setVisible ?( visible : boolean ) : void ;
5454}
5555
@@ -62,7 +62,7 @@ interface ISashEvent {
6262
6363type ViewItemSize = number | { cachedVisibleSize : number } ;
6464
65- abstract class ViewItem {
65+ abstract class ViewItem < TLayoutContext > {
6666
6767 private _size : number ;
6868 set size ( size : number ) {
@@ -115,7 +115,7 @@ abstract class ViewItem {
115115
116116 constructor (
117117 protected container : HTMLElement ,
118- private view : IView ,
118+ private view : IView < TLayoutContext > ,
119119 size : ViewItemSize ,
120120 private disposable : IDisposable
121121 ) {
@@ -129,31 +129,31 @@ abstract class ViewItem {
129129 }
130130 }
131131
132- layout ( position : number , orthogonalSize : number | undefined ) : void {
133- this . layoutContainer ( position ) ;
134- this . view . layout ( this . size , orthogonalSize ) ;
132+ layout ( offset : number , layoutContext : TLayoutContext | undefined ) : void {
133+ this . layoutContainer ( offset ) ;
134+ this . view . layout ( this . size , offset , layoutContext ) ;
135135 }
136136
137- abstract layoutContainer ( position : number ) : void ;
137+ abstract layoutContainer ( offset : number ) : void ;
138138
139- dispose ( ) : IView {
139+ dispose ( ) : IView < TLayoutContext > {
140140 this . disposable . dispose ( ) ;
141141 return this . view ;
142142 }
143143}
144144
145- class VerticalViewItem extends ViewItem {
145+ class VerticalViewItem < TLayoutContext > extends ViewItem < TLayoutContext > {
146146
147- layoutContainer ( position : number ) : void {
148- this . container . style . top = `${ position } px` ;
147+ layoutContainer ( offset : number ) : void {
148+ this . container . style . top = `${ offset } px` ;
149149 this . container . style . height = `${ this . size } px` ;
150150 }
151151}
152152
153- class HorizontalViewItem extends ViewItem {
153+ class HorizontalViewItem < TLayoutContext > extends ViewItem < TLayoutContext > {
154154
155- layoutContainer ( position : number ) : void {
156- this . container . style . left = `${ position } px` ;
155+ layoutContainer ( offset : number ) : void {
156+ this . container . style . left = `${ offset } px` ;
157157 this . container . style . width = `${ this . size } px` ;
158158 }
159159}
@@ -198,26 +198,26 @@ export namespace Sizing {
198198 export function Invisible ( cachedVisibleSize : number ) : InvisibleSizing { return { type : 'invisible' , cachedVisibleSize } ; }
199199}
200200
201- export interface ISplitViewDescriptor {
201+ export interface ISplitViewDescriptor < TLayoutContext > {
202202 size : number ;
203203 views : {
204204 visible ?: boolean ;
205205 size : number ;
206- view : IView ;
206+ view : IView < TLayoutContext > ;
207207 } [ ] ;
208208}
209209
210- export class SplitView extends Disposable {
210+ export class SplitView < TLayoutContext = undefined > extends Disposable {
211211
212212 readonly orientation : Orientation ;
213213 readonly el : HTMLElement ;
214214 private sashContainer : HTMLElement ;
215215 private viewContainer : HTMLElement ;
216216 private size = 0 ;
217- private orthogonalSize : number | undefined ;
217+ private layoutContext : TLayoutContext | undefined ;
218218 private contentSize = 0 ;
219219 private proportions : undefined | number [ ] = undefined ;
220- private viewItems : ViewItem [ ] = [ ] ;
220+ private viewItems : ViewItem < TLayoutContext > [ ] = [ ] ;
221221 private sashItems : ISashItem [ ] = [ ] ;
222222 private sashDragState : ISashDragState | undefined ;
223223 private state : State = State . Idle ;
@@ -280,7 +280,7 @@ export class SplitView extends Disposable {
280280 this . updateSashEnablement ( ) ;
281281 }
282282
283- constructor ( container : HTMLElement , options : ISplitViewOptions = { } ) {
283+ constructor ( container : HTMLElement , options : ISplitViewOptions < TLayoutContext > = { } ) {
284284 super ( ) ;
285285
286286 this . orientation = types . isUndefined ( options . orientation ) ? Orientation . VERTICAL : options . orientation ;
@@ -323,11 +323,11 @@ export class SplitView extends Disposable {
323323 }
324324 }
325325
326- addView ( view : IView , size : number | Sizing , index = this . viewItems . length ) : void {
326+ addView ( view : IView < TLayoutContext > , size : number | Sizing , index = this . viewItems . length ) : void {
327327 this . doAddView ( view , size , index , false ) ;
328328 }
329329
330- removeView ( index : number , sizing ?: Sizing ) : IView {
330+ removeView ( index : number , sizing ?: Sizing ) : IView < TLayoutContext > {
331331 if ( this . state !== State . Idle ) {
332332 throw new Error ( 'Cant modify splitview' ) ;
333333 }
@@ -419,10 +419,10 @@ export class SplitView extends Disposable {
419419 return viewItem . cachedVisibleSize ;
420420 }
421421
422- layout ( size : number , orthogonalSize ?: number ) : void {
422+ layout ( size : number , layoutContext ?: TLayoutContext ) : void {
423423 const previousSize = Math . max ( this . size , this . contentSize ) ;
424424 this . size = size ;
425- this . orthogonalSize = orthogonalSize ;
425+ this . layoutContext = layoutContext ;
426426
427427 if ( ! this . proportions ) {
428428 const indexes = range ( this . viewItems . length ) ;
@@ -563,7 +563,7 @@ export class SplitView extends Disposable {
563563 }
564564 }
565565
566- private onViewChange ( item : ViewItem , size : number | undefined ) : void {
566+ private onViewChange ( item : ViewItem < TLayoutContext > , size : number | undefined ) : void {
567567 const index = this . viewItems . indexOf ( item ) ;
568568
569569 if ( index < 0 || index >= this . viewItems . length ) {
@@ -610,7 +610,7 @@ export class SplitView extends Disposable {
610610 }
611611
612612 distributeViewSizes ( ) : void {
613- const flexibleViewItems : ViewItem [ ] = [ ] ;
613+ const flexibleViewItems : ViewItem < TLayoutContext > [ ] = [ ] ;
614614 let flexibleSize = 0 ;
615615
616616 for ( const item of this . viewItems ) {
@@ -641,7 +641,7 @@ export class SplitView extends Disposable {
641641 return this . viewItems [ index ] . size ;
642642 }
643643
644- private doAddView ( view : IView , size : number | Sizing , index = this . viewItems . length , skipLayout ?: boolean ) : void {
644+ private doAddView ( view : IView < TLayoutContext > , size : number | Sizing , index = this . viewItems . length , skipLayout ?: boolean ) : void {
645645 if ( this . state !== State . Idle ) {
646646 throw new Error ( 'Cant modify splitview' ) ;
647647 }
@@ -875,11 +875,11 @@ export class SplitView extends Disposable {
875875 this . contentSize = this . viewItems . reduce ( ( r , i ) => r + i . size , 0 ) ;
876876
877877 // Layout views
878- let position = 0 ;
878+ let offset = 0 ;
879879
880880 for ( const viewItem of this . viewItems ) {
881- viewItem . layout ( position , this . orthogonalSize ) ;
882- position += viewItem . size ;
881+ viewItem . layout ( offset , this . layoutContext ) ;
882+ offset += viewItem . size ;
883883 }
884884
885885 // Layout sashes
0 commit comments