API Reference 0.7.1rikulo_gestureScrollbarControl

ScrollbarControl class

The controller of a virtual scroll bar which appears when scrolling.

class ScrollbarControl {
 /* bar inner size: 4px
  * bar border: 1px
  * bar margin: 2px
  */
 static const _mgs = 2, _bds = 1, _ins = 4;

 Element _hbar, _vbar;

 ScrollbarControl(this.scroller, this.owner);

 ///The scrollbar
 final Scroller scroller;
 ///The owner
 final Element owner;
 
 /** Initialization of scroll bar.
  */
 void init(bool vertical) {
   if (vertical) {
     _vbar = new Element.tag("div");
     _vbar.classes = ["v-scrollbar-ver"];
     _vbar.style.width = CssUtil.px(_ins); // do here to have better sync
     _vbar.style.display = "none";
     owner.parent.insertBefore(_vbar, owner.nextElementSibling);
   } else {
     _hbar = new Element.tag("div");
     _hbar.classes = ["v-scrollbar-hor"];
     _hbar.style.height = CssUtil.px(_ins); // do here to have better sync
     _hbar.style.display = "none";
     owner.parent.insertBefore(_hbar, owner.nextElementSibling);
   }
 }
 
 /** Destory the scroll bar.
  */
 void destroy(bool vertical) {
   if (vertical) {
     _vbar.remove();
     _vbar == null;
   } else {
     _hbar.remove();
     _hbar == null;
   }
 }
 
 /** Called when scrolling starts.
  */
 void start(bool vertical, ScrollerState state) {
   _updateBarSize(vertical, state);
   _updateBarPosition(vertical, state);
   final Element bar = vertical ? _vbar : _hbar;
   bar.style.display = "block"; // TODO: animation + leave hook to cancel
 }
 
 /** Called at each scrolling iteraion.
  */
 void move(bool vertical, ScrollerState state) {
   _updateBarPosition(vertical, state);
 }
 
 /** Called when scrolling stops.
  */
 void end(bool vertical, ScrollerState state) {
   final Element bar = vertical ? _vbar : _hbar;
   bar.style.display = "none"; // TODO: animation + leave hook to skip
 }
 
 void _updateBarSize(bool ver, ScrollerState state) {
   final Size csize = state.contentSize;
   final Size vsize = state.viewPortSize;
   final num csize0 = ver ? csize.height : csize.width;
   final num vsize0 = ver ? vsize.height : vsize.width;
   final num s = ((vsize0 - _mgs * 2) * (csize0 > vsize0 ? vsize0 / csize0 : 1)).toInt() - _bds * 2;
   final num off = (ver ? vsize.width : vsize.height) - _mgs - _ins - _bds * 2;
   if (ver) {
     _vbar.style.height = CssUtil.px(s);
     _vbar.style.left = CssUtil.px(off);
   } else {
     _hbar.style.width = CssUtil.px(s);
     _hbar.style.top = CssUtil.px(off);
   }
 }
 
 void _updateBarPosition(bool ver, ScrollerState state) {
   final Size csize = state.contentSize;
   final Size vsize = state.viewPortSize;
   final num csize0 = ver ? csize.height : csize.width;
   final num vsize0 = ver ? vsize.height : vsize.width;
   final num pos = ver ? state.position.y : state.position.x;
   final num x = _mgs + (csize0 > vsize0 ? ((vsize0 - _mgs * 2) * pos / csize0) : 0);
   if (ver)
     _vbar.style.top = CssUtil.px(x);
   else
     _hbar.style.left = CssUtil.px(x);
 }
 
}

Constructors

new ScrollbarControl(Scroller scroller, Element owner) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
ScrollbarControl(this.scroller, this.owner);

Properties

final Element owner #

The owner

final Element owner

final Scroller scroller #

The scrollbar

final Scroller scroller

Methods

void destroy(bool vertical) #

Destory the scroll bar.

void destroy(bool vertical) {
 if (vertical) {
   _vbar.remove();
   _vbar == null;
 } else {
   _hbar.remove();
   _hbar == null;
 }
}

void end(bool vertical, ScrollerState state) #

Called when scrolling stops.

void end(bool vertical, ScrollerState state) {
 final Element bar = vertical ? _vbar : _hbar;
 bar.style.display = "none"; // TODO: animation + leave hook to skip
}

void init(bool vertical) #

Initialization of scroll bar.

void init(bool vertical) {
 if (vertical) {
   _vbar = new Element.tag("div");
   _vbar.classes = ["v-scrollbar-ver"];
   _vbar.style.width = CssUtil.px(_ins); // do here to have better sync
   _vbar.style.display = "none";
   owner.parent.insertBefore(_vbar, owner.nextElementSibling);
 } else {
   _hbar = new Element.tag("div");
   _hbar.classes = ["v-scrollbar-hor"];
   _hbar.style.height = CssUtil.px(_ins); // do here to have better sync
   _hbar.style.display = "none";
   owner.parent.insertBefore(_hbar, owner.nextElementSibling);
 }
}

void move(bool vertical, ScrollerState state) #

Called at each scrolling iteraion.

void move(bool vertical, ScrollerState state) {
 _updateBarPosition(vertical, state);
}

void start(bool vertical, ScrollerState state) #

Called when scrolling starts.

void start(bool vertical, ScrollerState state) {
 _updateBarSize(vertical, state);
 _updateBarPosition(vertical, state);
 final Element bar = vertical ? _vbar : _hbar;
 bar.style.display = "block"; // TODO: animation + leave hook to cancel
}