class TUI::Scroller

Defined in:

tui/widget/scroller.cr

Constant Summary

WHEEL_STEP = 3

Rows moved per mouse wheel tick — one shared default so widgets don't each redeclare an identical constant.

Constructors

Instance Method Summary

Constructor Detail

def self.new(offset : Int32 = 0) #

[View source]

Instance Method Detail

def clamp(total : Int32, visible : Int32) : Nil #

Recompute a valid offset against current content/viewport sizes. Call every render — self-heals when content shrinks (filter, toggle) or the widget resizes, without every mutation site needing to remember to reset/clamp separately.


[View source]
def down(by : Int32 = 1, total : Int32 = Int32::MAX, visible : Int32 = 0) : Nil #

[View source]
def fraction(total : Int32, visible : Int32) : Float64 | Nil #

0.0..1.0 position of the viewport within the content, or nil if the content fits entirely (no scrollbar needed).


[View source]
def offset : Int32 #

First visible content row, 0-based. Kept in range by #clamp — call that every render rather than trusting this to stay valid on its own after content or viewport size changes.


[View source]
def reset : Nil #

[View source]
def reveal(index : Int32, visible : Int32) : Nil #

Ensure index is within the visible window — scrolls minimally.


[View source]
def up(by : Int32 = 1) : Nil #

[View source]
def wheel_down(by : Int32 = WHEEL_STEP, total : Int32 = Int32::MAX, visible : Int32 = 0) : Nil #

[View source]
def wheel_up(by : Int32 = WHEEL_STEP) : Nil #

Wheel-tick convenience over #up/#down — same semantics, just names the common case and supplies the shared step default. #up/#down remain the primitives (used by PageUp/PageDown/arrow keys).


[View source]