Next | Prev | Up | Top | Contents | Index

xmScrollBar

The xmScrollBar widget is made to allow moving the current view of a widget that is too large to be displayed all at once. Usually, scroll bars are part of an xmScrolledWidget, an xmScrolledText, or an xmScrolledList widget.

An xmScrollBar may be horizontal or vertical (depending its -orientation resource). An xmScrollBar is composed of two arrows, a long rectangle called the scroll region, and a smaller rectangle called the slider. The data is scrolled by clicking either arrow, clicking inside the scroll region, or by dragging the slider. When the mouse is held down in the scroll region or in either arrow, the data continues to move at a constant speed.

The following example uses two scrollbars to move a target button:

#! /usr/sgitcl/bin/moat 
xtAppInitialize
xmBulletinBoard .top managed
xmScrollBar .top.h managed \
    -orientation horizontal -width 150 \
    -y 160 -minimum 10 -maximum 140
xmScrollBar .top.v managed \
    -orientation vertical -height 150 \
    -x 160 -minimum 10 -maximum 140
xmPushButton .top.target managed -labelString "X"
proc track_it {} {
    .top.h getValues -value x
    .top.v getValues -value y
    .top.target setValues -x [expr 8+$x] -y [expr 8+$y]
}
.top.h dragCallback track_it
.top.v dragCallback track_it
.top.h valueChangedCallback track_it
.top.v valueChangedCallback track_it
track_it
. realizeWidget
. mainLoop
The xmScrollBar widget class defines the new resources listed in Table 4-36.

xmScrollBar Resources
Resource NameDefault ValueType or Legal Values
-increment1Integer
-initialDelay250 msInteger
-maximum100Integer
-minimum0Integer
-orientationverticalhorizontal
vertical
-pageIncrement10Integer
-processingDirectioncomputedmax_on_bottom
max_on_left
max_on_right
max_on_top
-repeatDelay50 msInteger
-showArrowsTrueBoolean
-sliderSizecomputedInteger
-troughColorcomputedColor
-value0Integer

The -value resource specifies the current position of the scrollbar slider, between the minimum and maximum -sliderSize. The slider moves between -minimum and -maximum by -increment steps (clipped at the ends). Clicking either scrollbar arrow moves the slider by -pageIncrement. The -sliderSize reflects the portion of the widget currently in view.

The -troughColor specifies the scrollbar slider fill color. Constant speed movement can be parameterized with -repeatDelay and -initialDelay. If -showArrows is set to False, the scroll bar will not have arrows at either end.

xmScrollBar Methods
Method Name Why
decrementCallback Value was decremented.
dragCallback The slider is being dragged.
incrementCallback Value was incremented.
pageDecrementCallback Value was decremented by pageIncrement.
pageIncrementCallback Value was incremented by pageIncrement.
toTopCallback Value was reset to minimum.
toBottomCallback Value was reset to maximum.
valueChangedCallback The value had changed.

In the callbacks above, the %value substitution returns the current scroll bar position.


Next | Prev | Up | Top | Contents | Index