Repository navigation
tkScrollBar
Home › All Categories › tkControls › tkScrollBar
Runs the one scrollbar engine behind tkVScrollBar and tkHScrollBar.
tkScrollBar is the shared implementation of the two scrollbar controls. A vertical and a horizontal bar are the same control with the axes swapped, so both are built here and tkVScrollBar and tkHScrollBar are thin modules over it. Import one of those for a bar; this page describes the behaviour they share.
A bar is a flat track with a flat thumb, and no arrow buttons. It knows nothing about your content: you give it a total, a page (how many units are visible) and a position, and it calls you back when the user moves it. It never takes focus, handles no keys, and does not size, place or hide itself.
#import "vendor/tkControls/tkVScrollBar" ' or tkHScrollBar, or both
using tkVScrollBar
using tkScrollBar
using tkHostEach of the two bar modules imports tkScrollBar, tkHost and tkTheme publicly. Open
tkScrollBar with using only to call an engine name such as tkScrollBar_GetThumbRect on a
bar of either kind; every bar handle is accepted by the tkScrollBar_* procedures.
- Positions are whole units, clamped to
0 .. total - page. When everything fits (page >= total) there is no thumb:tkScrollBar_NeedsThumbis false andtkScrollBar_GetThumbRectis empty. - Dragging the thumb moves the position. A click on the track pages by exactly
pagetoward the click, then repeats while the button is held (TKSCROLL_REPEAT_DELAY, then everyTKSCROLL_REPEAT_MSmilliseconds) until the thumb reaches the cursor or the end. - The thumb never gets shorter than
TKSCROLL_MIN_THUMB(scaled), so it stays grabbable. - The wheel steps by the wheel step (
tkScrollBar_SetWheelStep), or byTKSCROLL_SYSTEM_WHEEL_LINESunits per notch when the step is 0. Partial notches from a touchpad accumulate in 120ths until they add up to a unit. - A vertical bar takes only the vertical wheel and a horizontal bar only the horizontal one; the other axis passes on to the parent.
-
HandleWheelDeltatakes 120ths of a notch. A positive delta moves a vertical bar up but a horizontal bar right. Call it from your content widget so the wheel works over the content, not only over the bar. -
SetRangeandSetPosare silent. Only the user's drag, track click and wheel call the scroll callback, andtkScrollBar_StepBy(a step that behaves as the user's) does too. - Colours follow the current theme until
SetColorspins them;UnpinColorshands them back. A paint callback replaces the built-in painter, and receives the thumb rectangle and the hot and dragging states inTKSCROLLBAR_PAINTINFO.
PsVScrollBar and PsHScrollBar remain the behaviour reference for everything not listed here.
- Names:
PsVScrollBar_*→tkVScrollBar_*,PsHScrollBar_*→tkHScrollBar_*;CVSCROLL_*→TKVSCROLL_*,CHSCROLL_*→TKHSCROLL_*. The callback type names (VScrollCallbackSub,VScrollPaintCallbackSub,HScrollCallbackSub,HScrollPaintCallbackSub) are unchanged. The handle isTK_WIDGET ptr. -
Create( hParent, CtrlID )takes aTK_WIDGET ptrparent (tkHost_Root( h )for a top-level window). Place and size the bar withtkWidget_SetPos; the usual thickness isTKVSCROLL_DEFAULT_WIDTH/TKHSCROLL_DEFAULT_HEIGHT, scaled withtkHost_Scale. -
IsDraggingandGetThumbRectexist on both bars. - The system lines-per-notch has no query here, so it is fixed at
TKSCROLL_SYSTEM_WHEEL_LINES(3). - DPI changes are handled by the bar itself.
- Gone: the hover-poll timer and its
*_HOTTRACK*constants, and PsRegistry.
Every public name the module declares, as the source declares it. Signatures are exact; type bodies keep their field comments and drop the rest.
const TKSCROLL_REPEAT_DELAY = 400
const TKSCROLL_REPEAT_MS = 80
const TKSCROLL_MIN_THUMB = 20
const TKSCROLL_DEFAULT_THICKNESS = 12
const TKSCROLL_SYSTEM_WHEEL_LINES = 3type TKSCROLLBAR_PAINTINFO
b as TK_PAINT ptr
rcClient as TKRECT
rcThumb as TKRECT ' empty when no thumb is needed
isHot as boolean ' the mouse is over the thumb
isDragging as boolean
end type
type TKSCROLLBAR_STATE ' per-instance state; reach it through the procedures
type tkScrollPaintSub as sub( byval p as TKSCROLLBAR_PAINTINFO ptr )
type tkScrollNotifySub as sub( byval hSB as TK_WIDGET ptr, byval newPos as integer )function tkScrollBar_StepBy( byval pSB as TKSCROLLBAR_STATE ptr, byval nUnits as integer ) as boolean
function tkScrollBar_HandleWheelDelta( byval hSB as TK_WIDGET ptr, byval nDelta as integer ) as boolean
function tkScrollBar_Create( byval hParent as TK_WIDGET ptr, byval ctrlId as integer, byval bVertical as boolean ) as TK_WIDGET ptr
function tkScrollBar_State( byval hSB as TK_WIDGET ptr ) as TKSCROLLBAR_STATE ptr
sub tkScrollBar_SetRange( byval hSB as TK_WIDGET ptr, byval nTotal as integer, byval nPage as integer, byval nPosition as integer )
function tkScrollBar_GetPos( byval hSB as TK_WIDGET ptr ) as integer
sub tkScrollBar_SetPos( byval hSB as TK_WIDGET ptr, byval nPosition as integer )
function tkScrollBar_NeedsThumb( byval hSB as TK_WIDGET ptr ) as boolean
function tkScrollBar_IsDragging( byval hSB as TK_WIDGET ptr ) as boolean
function tkScrollBar_GetThumbRect( byval hSB as TK_WIDGET ptr ) as TKRECT
sub tkScrollBar_SetColors( byval hSB as TK_WIDGET ptr, byval backclr as ulong, byval foreclr as ulong, byval foreclrhot as ulong )
sub tkScrollBar_SetDividerColor( byval hSB as TK_WIDGET ptr, byval clr as ulong, byval bShow as boolean = true )
sub tkScrollBar_ApplyTheme( byval hSB as TK_WIDGET ptr, byref t as TKTHEME_COLORS )
sub tkScrollBar_UnpinColors( byval hSB as TK_WIDGET ptr )
sub tkScrollBar_SetPaintCallback( byval hSB as TK_WIDGET ptr, byval usersub as tkScrollPaintSub )
sub tkScrollBar_SetScrollCallback( byval hSB as TK_WIDGET ptr, byval usersub as tkScrollNotifySub )
sub tkScrollBar_SetWheelStep( byval hSB as TK_WIDGET ptr, byval nUnitsPerNotch as integer )
function tkScrollBar_GetWheelStep( byval hSB as TK_WIDGET ptr ) as integertiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing