Overview
TheScroller class provides a visual scrollbar component that displays scroll position and allows users to navigate through editor content. It handles mouse interactions for clicking arrows, dragging the thumb, and page up/down operations.
Class Definition
Constructor
editor- Reference to the parentZepEditorinstanceparent- Reference to the parentRegionthat contains this scroller
Public Members
vScrollVisiblePercent
The percentage of content visible in the viewport.1.0means all content is visible (no scrolling needed)0.5means 50% of content is visible- Smaller values indicate more content to scroll through
vScrollPosition
The current scroll position as a percentage of total scrollable area.0.0means scrolled to the top1.0means scrolled to the bottom0.5means scrolled to the middle
vScrollLinePercent
The percentage of the viewport that one line represents.0.05 means each line is 5% of the viewport height.
Example:
vScrollPagePercent
The percentage of the viewport that one page represents.vScrollVisiblePercent.
Example:
vertical
Whether this is a vertical or horizontal scrollbar.true- Vertical scrollbar (default)false- Horizontal scrollbar
Methods
Display
Renders the scrollbar using the provided theme.theme- Theme to use for rendering the scrollbar
- Up/down arrow buttons
- Scrollbar track
- Draggable thumb indicator
Notify
Handles messages from the editor system, particularly mouse events.message- Message containing event information
- Clicking up/down arrows
- Clicking track for page up/down
- Dragging the thumb
- Releasing mouse button
Usage Example
Basic Setup
Horizontal Scrollbar
Responding to Scroll Changes
Scroll Calculations
Thumb Size
The visible thumb size represents how much content is visible:Thumb Position
The thumb position shows where you are in the document:Converting Position to Line
To convert scroll position to a line number:Internal Details
The scroller maintains several private regions and state:Private Members
Private Methods
CheckState()- Updates scroll state based on timers and mouse positionClickUp()- Handles clicking the up arrowClickDown()- Handles clicking the down arrowPageUp()- Scrolls up one pagePageDown()- Scrolls down one pageDoMove(NVec2f pos)- Handles thumb draggingThumbSize()- Calculates thumb size in pixelsThumbExtra()- Extra space available for scrollingThumbRect()- Returns the thumb’s bounding rectangle
Integration with ZepComponent
TheScroller inherits from ZepComponent, giving it access to:
- Message handling through
Notify() - Parent-child region hierarchy
- Editor reference
- Theme-based rendering
include/zep/scroller.h:12 for the complete definition.
See Also
- ZepWindow - Editor window that uses scrollers
- ZepTheme - Theme system for rendering
- ZepDisplay - Display abstraction
