package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Scroll_bar/index.html
Module Mosaic_ui.Scroll_bar
Scrollbar with proportional thumb sizing and arrow buttons.
Scroll bar widget with optional arrow buttons and a proportional slider thumb.
A scroll bar manages a scroll position within a range determined by scroll_size and viewport_size. The slider thumb is sized proportionally to the visible portion of content. Arrow buttons at each end provide incremental scrolling with hold-to-repeat.
Coordinate system
The scroll coordinate space is expressed in cells:
- scroll_position — current scroll offset.
- viewport_size — size of the visible area.
- scroll_size — total content size.
- Valid range: [
0;max(0, scroll_size - viewport_size)].
Scroll units
scroll_by supports four unit types:
`Absolute— delta multiplied by 1.`Viewport— delta multiplied by viewport size.`Content— delta multiplied by content size.`Step— delta multiplied by the custom step size (default1).
The type for scroll delta units used by scroll_by.
Props
module Props : sig ... endTypes
The type for scroll bar widgets backed by a Renderable.t.
Constructors
val create :
parent:Renderable.t ->
?index:int ->
?id:string ->
?style:Toffee.Style.t ->
?visible:bool ->
?z_index:int ->
?opacity:float ->
?orientation:orientation ->
?show_arrows:bool ->
?track_color:Ansi.Color.t ->
?thumb_color:Ansi.Color.t ->
?arrow_fg:Ansi.Color.t ->
?arrow_bg:Ansi.Color.t ->
?on_change:(int -> unit) ->
unit ->
tcreate ~parent () is a scroll bar attached to parent. The optional parameters are:
orientation— layout direction. Defaults to`Vertical.show_arrows— display arrow buttons at each end. Defaults tofalse.on_change— callback invoked with the new scroll position whenever it changes.
val node : t -> Renderable.tnode t is the underlying Renderable.t for t.
Scroll state
val scroll_position : t -> intscroll_position t is the current scroll offset of t, clamped to [0;max(0, scroll_size - viewport_size)].
See also set_scroll_position.
val set_scroll_position : t -> int -> unitset_scroll_position t v sets the scroll position of t to v, clamped to the valid range. Fires the on_change callback if the clamped value differs from the current position.
See also scroll_position and scroll_by.
val scroll_size : t -> intscroll_size t is the total content size of t in cells.
See also set_scroll_size.
val set_scroll_size : t -> int -> unitset_scroll_size t v sets the content size of t to v cells. Clamps the scroll position to the updated valid range and recalculates thumb visibility.
See also scroll_size.
val viewport_size : t -> intviewport_size t is the visible area size of t in cells.
See also set_viewport_size.
val set_viewport_size : t -> int -> unitset_viewport_size t v sets the visible area size of t to v cells. Affects thumb sizing and the scroll range.
See also viewport_size.
val scroll_by : t -> float -> unit:scroll_unit -> unitscroll_by t delta ~unit adjusts the scroll position of t by delta expressed in unit. The resulting position is clamped to the valid range. See scroll_unit for the meaning of each unit.
val set_scroll_step : t -> int option -> unitset_scroll_step t step sets the custom step size used when unit is `Step in scroll_by. None resets the step to the default of 1.
Appearance
val set_show_arrows : t -> bool -> unitset_show_arrows t v shows (true) or hides (false) the arrow buttons of t.
val set_track_color : t -> Ansi.Color.t -> unitset_track_color t c sets the track background color of t to c.
val set_thumb_color : t -> Ansi.Color.t -> unitset_thumb_color t c sets the thumb foreground color of t to c.
Visibility
val set_visible_override : t -> bool -> unitset_visible_override t v sets the visibility of t to v and disables automatic visibility control.
See also reset_visibility_control.
val reset_visibility_control : t -> unitreset_visibility_control t re-enables automatic visibility for t based on content overflow, undoing any prior call to set_visible_override.
Callback
val set_on_change : t -> (int -> unit) option -> unitset_on_change t f replaces the change callback of t with f. None removes the callback.
Applying props
apply_props t props replaces the visual properties of t with props. Creation-time fields such as orientation remain unchanged. Does not fire the on_change callback.
See also Props.make.
Keyboard interaction
handle_key t event is true iff event was consumed by t. Handles directional arrows, Page Up/Down, and Home/End to adjust the scroll position.
Formatting
val pp : Format.formatter -> t -> unitpp formats a scroll bar value for debugging.