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)
- 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.
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
// 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
}
Config controls scrollbar rendering and geometry.
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 begins a drag at the given mouse position. It computes the grab offset (preserving relative position if clicking on the thumb, centering otherwise) and returns the viewport offset to scroll to.
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.