Jamba Views / Scrollbar

Scrollbar

Scrollbar

Generic scrollbar which handles scrolling and (optional) zooming via handles. The scrollbar is driven by 2 parameters which can be tied to Vst or Jmb parameters:

  • offsetPercent which represents the position of the scrollbar as a percent (0 means completely left, 1 means completely right)
  • zoomPercent which represents the size of the scrollbar as a percent (0 means completely zoomed out (hence the scrollbar is full), 1 means completely zoomed in (hence the scrollbar is at its minimum size)).

In addition to the attributes exposed by CustomView, this class exposes the following attributes:

Attribute Description
offset-percent-tag id for the parameter tied to offset percent
zoom-percent-tag id for the parameter tied to zoom percent
margin Amount of space (in pixels) to draw around the full scrollbar (includes handles)
scrollbar-color the color of the scrollbar itself (the rectangle)
scrollbar-min-size Minimum size for the scrollbar (in pixels). If -1 it will be auto-computed.
scrollbar-gutter-spacing Spacing (in pixels) between the scrollbar and zoom handles (only drawn when zoom handles)
zoom-handles-color Zoom handles color
zoom-handles-size Zoom handles size. If -1 it will be auto-computed. Set to 0 to disable handles entirely.
shift-drag-factor Defines how much to slow down (if less than 1) or accelerate (if more than 1) when shift is held when dragging.
enable-zoom-double-click true to allow zooming on double click on the scrollbar
Note

At the moment, it handles only horizontal scrollbar.

The image above shows an example of a scrollbar tied to 2 vst parameters which control the offset and zoom level of the display.

Example

The XML defining the scrollbar, tied to 2 parameters (Param_LCDHistoryOffset and Param_LCDZoomFactorX) (Source)

<view back-color="~ BlackCColor" class="VAC6V::LCDScrollbar" custom-view-tag="CV_LCDScrollbar" enable-zoom-double-click="true" margin="3,2.5,3,2.5" offset-percent-tag="Param_LCDHistoryOffset" origin="72, 235" scrollbar-color="LevelStateOk" scrollbar-gutter-spacing="1" scrollbar-min-size="-1" shift-drag-factor="1" size="256, 16" zoom-handles-color="LevelStateOk" zoom-handles-size="-1" zoom-percent-tag="Param_LCDZoomFactorX"/>

The 2 vst params are defined this way (Percent is just an alias to a float) (Source)

VstParam<Percent> fZoomFactorXParam;
// ... #34
VstParam<Percent> fLCDHistoryOffsetParam;

The vst params are initialized this way (Source)

fZoomFactorXParam =
  vst<LCDZoomFactorXParamConverter>(EVAC6ParamID::kLCDZoomFactorX, STR16 ("Zoom Level"))
    .defaultValue(DEFAULT_ZOOM_FACTOR_X)
    .shortTitle(STR16 ("Zoom Lvl"))
    .precision(1)
    .add();
// ... #120
fLCDHistoryOffsetParam =
  vst<LCDHistoryOffsetParamConverter>(EVAC6ParamID::kLCDHistoryOffset, STR16 ("Graph Scroll"))
    .defaultValue(MAX_HISTORY_OFFSET) // all the way to the right
    .flags(0) // state is not saved
    .precision(0)
    .transient()
    .add();