Documentation
¶
Index ¶
- func Percent(offset, total, viewport int) int
- func Position(start, end, total int) string
- func ThumbMetrics(height, totalLines int, percent float64) (int, int)
- func ThumbMetricsWithConfig(height, totalLines int, percent float64, cfg Config) (int, int)
- func ThumbRange(height, totalLines int, percent float64, cfg Config) (int, int)
- func ViewportThumbMetrics(trackHeight, totalLines, viewportLines, offset int) (int, int)
- func ViewportThumbMetricsWithConfig(trackHeight, totalLines, viewportLines, offset int, cfg Config) (int, int)
- type Config
- type Drag
- type Hitbox
- type Model
- type Styles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Percent ¶
Percent returns the scroll position as a percentage in the style of less(1): the percentage of content above and including the bottom of the viewport. This means the value never reaches 0% when there is content, and reaches 100% exactly at the end.
func Position ¶
Position returns a formatted scroll position string like "1-10/42 (24%)". The start parameter is 0-indexed; it is displayed as 1-indexed in the output.
func ThumbMetrics ¶
ThumbMetrics returns the thumb position and size for a proportional scrollbar.
func ThumbMetricsWithConfig ¶
ThumbMetricsWithConfig returns the thumb position and size for a proportional scrollbar using the supplied config.
func ThumbRange ¶
ThumbRange returns the start row, inclusive, and end row, exclusive, of the rendered thumb within a track of the given height.
func ViewportThumbMetrics ¶ added in v0.2.4
ViewportThumbMetrics returns the thumb position and size for an explicit viewport and scroll offset. The track height is independent of the number of content lines visible in the viewport.
func ViewportThumbMetricsWithConfig ¶ added in v0.2.4
func ViewportThumbMetricsWithConfig( trackHeight, totalLines, viewportLines, offset int, cfg Config, ) (int, int)
ViewportThumbMetricsWithConfig returns the thumb position and size for an explicit viewport and scroll offset using the supplied config.
Types ¶
type Config ¶
type Config struct {
// ThumbSymbol is the cell rendered for the scrollbar thumb.
ThumbSymbol string
// TrackSymbol is the cell rendered for the scrollbar track.
TrackSymbol string
// HideTrack renders blank cells outside the thumb while preserving the
// scrollbar's width.
HideTrack bool
// PageTrackClicks makes presses outside the thumb move one viewport instead
// of jumping to the pressed position and beginning a drag.
PageTrackClicks bool
// MaxThumbDivisor caps the thumb height to Height/MaxThumbDivisor.
// The default is 2. Set to 1 for a fully proportional thumb capped only
// by the track height.
MaxThumbDivisor int
// MinThumbSize sets the minimum thumb height. The default is 1. Values
// larger than the configured maximum are clamped to that maximum.
MinThumbSize int
}
Config controls scrollbar rendering, geometry, and interaction.
Zero-valued fields preserve the package defaults.
type Drag ¶
type Drag struct {
Active bool
// contains filtered or unexported fields
}
Drag tracks the state of a scrollbar drag interaction.
Typical usage in a Bubble Tea Update loop:
case tea.MouseClickMsg:
offset := drag.Press(hitbox, msg.Y, vp.ScrollPercent())
vp.SetYOffset(offset)
case tea.MouseMotionMsg:
if offset, ok := drag.Motion(hitbox, msg.Y); ok {
vp.SetYOffset(offset)
}
case tea.MouseReleaseMsg:
drag.Release()
func (*Drag) Motion ¶
Motion updates the drag position and returns the new viewport offset. Returns ok=false if no drag is active.
func (*Drag) Press ¶
Press handles a press at the given mouse position and returns the viewport offset to scroll to. By default it begins a drag, preserving the grab offset on the thumb and centering it otherwise. When PageTrackClicks is enabled, a press outside the thumb moves one viewport without beginning a drag.
The scrollPercent parameter is the viewport's current scroll position (0.0 to 1.0), used to determine the thumb's current position.
type Hitbox ¶
type Hitbox struct {
X int // column position
Y int // top row
Height int // visible track height
TotalLines int // total content lines
Config Config
}
Hitbox describes the screen region occupied by a vertical scrollbar.