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
Database class: ClientData
Acts as a data storage for a widgets. User can store any data and this will not have any effect on widget property.
-cursor
Database name: cursor
Database class: Cursor
Specifies the mouse cursor to be used for the widget. See Tk_GetCursor and cursors(n) in the Tk reference manual for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget.
-helpcommand
Database name: helpcommand
Database class: Command
Dynamic help which calls an assigned -helpcommand when the user moves the mouse on the widget. The text which is returned by the -helpcommand will be in turn be displayed on the tooltip.
-takefocus
Database name: takeFocus
Database class: TakeFocus
Determines whether the window accepts the focus during keyboard traversal. Either 0, 1, a command prefix (to which the widget path is appended, and which should return 0 or 1), or the empty string. See options(n) in the Tk reference manual for the full description.

Widget-Specific Options

-command
Database name: command
Database class: Command
A Tcl script prefix to evaluate to change the view in the widget associated with the scrollbar. Additional arguments are appended to the value of this option whenever the user requests a view change by manipulating the scrollbar. This option typically consists of a two-element list, containing the name of a scrollable widget followed by either xview (for horizontal scrollbars) or yview (for vertical scrollbars).
-orient
Database name: orient
Database class: Orient
Specifies the orientation whether the widget should be laid out horizontally or vertically. Must be either horizontal or vertical or an abbreviation of one of these. Default is horizontal.

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:
setchanges[pathNamestatespec]
pathNamestate$changes
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.
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

The following widget commands are used internally by the TScrollbar widget class bindings.
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