hwtk::scrollbar
Control the viewport of a scrollable widget.
Format
hwtk::scrollbar - pathName ?option value? …
Description
Scrollbar widgets are typically linked to an associated window that displays a document of some sort, such as a file being edited or a drawing. A scrollbar displays a "thumb" in the middle portion of the scrollbar, whose position and size provides information about the portion of the document visible in the associated window. The thumb may be dragged by the user to control the visible region. Depending on the theme, two or more arrow buttons may also be present; these are used to scroll the visible region in discrete units.
Standard Options
- -clientdata
- Database name: clientData
- -cursor
- Database name: cursor
- -helpcommand
- Database name: helpcommand
- -takefocus
- Database name: takeFocus
Widget-Specific Options
- -command
- Database name: command
- -orient
- Database name: orient
Widget Command
- pathName configure ?option? ?value option value …?
- Query or modify the configuration options of the widget. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. If option is specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If no option is specified, returns a list describing all of the available options for pathName.
- pathName cget option
- Returns the current value of the configuration option given by option.
- pathName identify element x y
- Returns the name of the element under the point given by x and y, or an empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget. Some widgets accept other identify subcommands.
- pathName instate statespec ?script?
- Test the widget’s state. If script is not specified, returns 1 if the
widget state matches statespec and 0 otherwise. If script is specified,
equivalent to
if{[pathNameinstatestateSpec]}script
- pathName state ?stateSpec?
- Modify or inquire widget state. If stateSpec is
present, sets the widget state: for each flag in
stateSpec, sets the corresponding flag or clears it
if prefixed by an exclamation point. Returns a new state spec indicating
which flags were changed:
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.setchanges[pathNamestatespec]
pathNamestate$changes
- pathName get
- Returns the scrollbar settings in the form of a list whose elements are the arguments to the most recent set widget command.
- pathName set first last
- This command is normally invoked by the scrollbars associated widget from an -xscrollcommand or -yscrollcommand callback. Specifies the visible range to be displayed. first and last are real fractions between 0 and 1.
Internal Commands
- pathName delta deltaX deltaY
- Returns a real number indicating the fractional change in the scrollbar setting that corresponds to a given change in thumb position. For example, if the scrollbar is horizontal, the result indicates how much the scrollbar setting must change to move the thumb deltaX pixels to the right (deltaY is ignored in this case). If the scrollbar is vertical, the result indicates how much the scrollbar setting must change to move the thumb deltaY pixels down. The arguments and the result may be zero or negative.
- pathName fraction x y
- Returns a real number between 0 and 1 indicating where the point given by x and y lies in the trough area of the scrollbar, where 0.0 corresponds to the top or left of the trough and 1.0 corresponds to the bottom or right. x and y are pixel coordinates relative to the scrollbar widget. If x and y refer to a point outside the trough, the closest point in the trough is used.
- pathName identify x y
- Returns the name of the element under the point given by x and y, or an empty string if the point does not lie in any element of the scrollbar. x and y are pixel coordinates relative to the scrollbar widget.
Example
hwtk::dialog .dlg -title "::hwtk::scrollbar"
set recess [.dlg recess]
set sv [hwtk::scrollbar $recess.sv -command "$recess.text yview"]
set sh [hwtk::scrollbar $recess.sh -command "$recess.text xview" -orient horizontal]
set text [text $recess.text -yscrollcommand "$sv set" -xscrollcommand "$sh set" -wrap none]
grid $sv -row 0 -col 1 -sticky ns
grid $sh -sticky ew
grid $text -row 0 -sticky news
grid columnfigure $recess 0 -weight 1
grid rowfigure $recess 0 -weight 1
.dlg post