module Webglimpse { export interface Insets { top : number ; right : number ; bottom : number ; left : number ; } export function newInsets ( ... insets ) { switch ( insets . length ) { case 1 : return { top : insets [ 0 ] , right : insets [ 0 ] , bottom : insets [ 0 ] , left : insets [ 0 ] } ; case 2 : return { top : insets [ 0 ] , right : insets [ 1 ] , bottom : insets [ 0 ] , left : insets [ 1 ] } ; case 3 : return { top : insets [ 0 ] , right : insets [ 1 ] , bottom : insets [ 2 ] , left : insets [ 1 ] } ; case 4 : return { top : insets [ 0 ] , right : insets [ 1 ] , bottom : insets [ 2 ] , left : insets [ 3 ] } ; default : throw new Error ( 'Expected 1, 2, 3, or 4 args, but found ' + insets . length ) ; } } export function newInsetLayout ( insets ) { return { updatePrefSize : function ( parentPrefSize , children ) { if ( children . length === 0 ) { parentPrefSize . w = insets . left + insets . right ; parentPrefSize . h = insets . top + insets . bottom ; } else if ( children . length === 1 ) { var childPrefSize = children [ 0 ] . prefSize ; parentPrefSize . w = ( hasval ( childPrefSize . w ) ? childPrefSize . w + insets . left + insets . right : null ) ; parentPrefSize . h = ( hasval ( childPrefSize . h ) ? childPrefSize . h + insets . top + insets . bottom : null ) ; } else if ( children . length > 1 ) { throw new Error ( 'Inset layout works with at most 1 child, but pane has ' + this . children . length + ' children' ) ; } } , updateChildViewports : function ( children , parentViewport ) { if ( children . length === 1 ) { var childViewport = children [ 0 ] . viewport ; childViewport . setEdges ( parentViewport . iStart + insets . left , parentViewport . iEnd - insets . right , parentViewport . jStart + insets . bottom , parentViewport . jEnd - insets . top ) ; } else if ( children . length > 1 ) { throw new Error ( 'Inset layout works with at most 1 child, but pane has ' + this . children . length + ' children' ) ; } } } ; } export function newInsetPane ( pane , insets , bgColor = null , consumeInputEvents = true ) { var insetPane = new Pane ( newInsetLayout ( insets ) , consumeInputEvents ) ; if ( hasval ( bgColor ) ) { insetPane . addPainter ( newBackgroundPainter ( bgColor ) ) ; } insetPane . addPane ( pane ) ; return insetPane ; } }