JSCScrollView container view with scrollers



A container view which allows the user to scroll across content which exceeds the view's visible bounds.


See also: JSCWindow GUI


N.B. JSCScrollView inherits most of it's important methods from it's superclass, JSCScrollTopView. Please see its helpfile for more information.


Setting the Internal Bounds


The size of the contained 'canvas' is determined by the bounds of the views which it encloses. Resize settings are thus ignored for contained views. To set it to a particular size, you can add a JSCCompositeView or other container view, but there is no direct setter. One should not use a decorator such as FlowLayout directly on a NSScrollView, only on a container view within it. 


Action Functions with Scrolling JSCViews


A JSCScrollTopView or JSCScrollView's action function is evaluated when a user scrolls the view or sets the visibleOrigin. See the example below.


Creation


*new(parent, bounds)

Returns a new JSCScrollView. (Inheritted from JSCView).

parent - A JSCWindow, or a container view such as JSCCompositeView.

bounds  - A Rect, which specifies the position of this view in its parent.



Instance Methods

hasBorder_(bool)

hasBorder

These methods get and set a Boolean indicating whether or not a black border is drawn around the view. This border is drawn within the bounds of the JSCScrollView. Thus the bounds do not change when a border is added, but the visible area is slightly reduced.



Examples


(

a = JSCWindow.new;

b = JSCScrollView( a, Rect( 0, 0, 150, 100 ));

c = JSC2DSlider( b, Rect( 0, 0, 100, 100 ));

d = JSC2DSlider( b, Rect( 100, 0, 100, 100 ));

a.front;

)


a.view.background = Color.white;

b.background = Color.grey;


d.bounds = Rect( 100, 0, 1000, 100 ); // the 'canvas' grows to accomodate it


b.resize = 5; // the ScrollView resizes, but not its contents


b.hasBorder_( true );

b.hasBorder_( false );


b.visibleOrigin;


b.visibleOrigin = Point( 2000, 0 ); // clips to the bounds of its contents


b.hasHorizontalScroller_( false );

b.autohidesScrollers_( false );

b.hasVerticalScroller_( false );


b.hasHorizontalScroller_( true );

b.hasVerticalScroller_( true );

b.autohidesScrollers_( true );


a.close;


/////////////////


// force a 'canvas' size


(

a = JSCWindow.new;

b = JSCScrollView( a, Rect( 0, 0, 300, 300 ));

c = JSCCompositeView( b, Rect( 0, 0, 500, 500 )); // 'canvas' is this big

a.front;

)


(

c.decorator = FlowLayout( c.bounds ); // now we can use a decorator

JSC2DSlider( c, Rect( 0, 0, 240, 240 ));

JSC2DSlider( c, Rect( 0, 0, 240, 240 ));

JSC2DSlider( c, Rect( 0, 0, 240, 240 ));

c.decorator.nextLine;

)


/////////////////


// "rulers", using an action function


(

var labelFunc;

w = JSCWindow.new;


a = JSCScrollView( w, Rect( 40, 40, 300, 300 ));

b = JSCScrollView( w, Rect( 0, 40, 40, 300 ))

.hasHorizontalScroller_( false )

.hasVerticalScroller_( false );

// .autoScrolls_( false );

c = JSCScrollView( w, Rect( 40, 0, 300, 40 ))

.hasHorizontalScroller_( false )

.hasVerticalScroller_( false );

// .autoScrolls_( false );

b.background = Color.grey;

c.background = Color.grey;


d = JSCUserView( a, Rect( 0, 0, 620, 620 )).canFocus_( false );

e = JSCUserView( b, Rect( 0, 0, 40, 630 )).canFocus_( false );

f = JSCUserView( c, Rect( 0, 0, 630, 40 )).canFocus_( false );


a.action = { var origin;

origin = a.visibleOrigin;

b.visibleOrigin = 0 @ (origin.y);

c.visibleOrigin = (origin.x) @ 0;

};


labelFunc = { (1..30).do({ arg i; JPen.stringAtPoint( i.asString, (i * 20) @ 0 )})};


d.drawFunc = { arg view; var b = view.bounds;

JPen.font = JFont( "Courier", 9 );

JPen.fillColor = Color.red;

JPen.use({

JPen.translate( 0, 5 );

labelFunc.value; 

});

JPen.translate( 15, 0 ).rotate( 0.5pi ); 

labelFunc.value;

};


e.drawFunc = { arg view; var b = view.bounds;

JPen.font = JFont( "Courier", 9 );

JPen.translate( 40, 0 ).rotate(0.5pi); 

labelFunc.value;

};


f.drawFunc = { arg view; var b = view.bounds;

JPen.font = JFont( "Courier", 9 );

JPen.translate( 0, 25 );

labelFunc.value; 

};


w.front;

)