class
SAPO.Component.CanvasScrollable
Version:
0.1
requires SAPO.Dom.Event
The function of this component is to mimic the behavior of a scrollable view using just canvas elements.
This is an abstraction for large canvas (especially useful for managed draws).
TODOs:
- test/give example of applyRendererDeltas = false
- test/correct when renderer's dimensions change during view lifetime
- support an option for drags not to redraw on every mousemove (timer-based)
Since:
Defined in
Component/CanvasScrollable/0.1/lib.js
February 2012
Constructor Summary
Function Summary
- increments the scroll. fixes parameters out of bounds.
Number[2]
getDimensions()
- returns the container's dimensions.
Number[2]
getMaxScroll()
- returns the max scroll.
Number[2]
getScroll()
- returns the current scroll.
redraw()
redraws the view. internally asks the renderer to update itself.
- updates the scroll. fixes parameters out of bounds.
Constructor Details
constructor _init
_init(String|DomElement
container, Object
options)
Parameters:
container
- the container where the view is to be created (that is, a canvas element).
options
-
Number[2] dims
- dimensions of the scrollable view, in pixels. -
Object renderer
- an object with a defined API. getDimensions(), getCanvas and redraw(delta, visibleWindow). see samples for usage. -
[ String scrollbarsVisible ]
- one of ['none', 'horizontal', 'vertical', 'both', 'auto']. defaults to 'auto' -
[ Number scrollbarLength ]
- length of the visible scrolls, in pixels. defaults to 12. -
[ String scrollbarFill ]
- the canvas style to apply to the scrollbars. defaults to rgba(0, 0, 0, 0.5). -
[ Number wheelDelta ]
- the scroll to apply when the mouse wheel is pressed, in pixels. defaults to 10. -
[ Boolean applyRendererDeltas ]
- if true (default), the component applies the scroll, otherwise it's up to the renderer to simulate it.
Function Details
function deltaScroll
deltaScroll(Number
dx, Number
dy)
- increments the scroll. fixes parameters out of bounds.
Parameters:
dx
- scroll delta to apply to the X coordinate, in pixels
dy
- scroll delta to apply to the Y coordinate, in pixels function getDimensions
Number[2]
getDimensions()
- returns the container's dimensions.
function getMaxScroll
Number[2]
getMaxScroll()
- returns the max scroll.
function getScroll
Number[2]
getScroll()
- returns the current scroll.
function redraw
redraw()
redraws the view. internally asks the renderer to update itself.
function scroll
scroll(Number
x, Number
y)
- updates the scroll. fixes parameters out of bounds.
Parameters:
x
- scroll position to apply in the X coordinate, in pixels
y
- scroll position to apply in the Y coordinate, in pixels