package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Select/index.html
Module Mosaic_ui.Select
Vertical list selector with optional descriptions.
Vertical list selector with optional descriptions.
A focusable, keyboard-navigable list where exactly one item is highlighted at a time. Each item has a label and an optional description. The widget automatically scrolls to keep the selected item centered in the viewport; rendering is buffered.
Keyboard
- Up / Down — move selection (Shift for fast scroll by
set_fast_scroll_stepitems). - j / k — move selection by one item.
- Enter / KP_enter — activate the current selection (fires the
set_on_activatecallback).
Mouse
- Left click — select the item under the cursor.
- Scroll wheel — navigate up or down by one item.
Scroll behaviour
The viewport displays as many items as fit within the available height. When an item is selected the view scrolls to center it. The set_show_scroll_indicator option displays a proportional position indicator in the rightmost column.
Types
A select widget backed by a Renderable.t.
Construction
val create :
parent:Renderable.t ->
?index:int ->
?id:string ->
?style:Toffee.Style.t ->
?visible:bool ->
?z_index:int ->
?opacity:float ->
?options:item list ->
?selected_index:int ->
?background:Ansi.Color.t ->
?text_color:Ansi.Color.t ->
?focused_background:Ansi.Color.t ->
?focused_text_color:Ansi.Color.t ->
?selected_background:Ansi.Color.t ->
?selected_text_color:Ansi.Color.t ->
?description_color:Ansi.Color.t ->
?selected_description_color:Ansi.Color.t ->
?show_description:bool ->
?show_scroll_indicator:bool ->
?wrap_selection:bool ->
?item_spacing:int ->
?fast_scroll_step:int ->
unit ->
tcreate ~parent () is a select node attached to parent.
The node is focusable and uses buffered rendering. See Props.make for parameter defaults.
val node : t -> Renderable.tnode t is the underlying renderable.
Props
module Props : sig ... endapply_props t props applies props to t. Only properties that differ from the current state trigger layout recomputation and re-render.
Options
set_options t items replaces the item list. The selection index is clamped to the new valid range. Does not fire the set_on_change callback. Triggers re-render.
Selection
val selected_index : t -> intselected_index t is the 0-based index of the selected item.
selected_item t is the currently selected item, or None when the list is empty.
val set_selected_index : t -> int -> unitset_selected_index t i moves the selection to index i, clamped to [0;length - 1]. Fires the set_on_change callback when the clamped index differs from the current selection; no-op otherwise.
Display
val set_show_description : t -> bool -> unitset_show_description t flag shows or hides item description lines. Recalculates layout and triggers re-render when the value changes.
val set_show_scroll_indicator : t -> bool -> unitset_show_scroll_indicator t flag shows or hides the scroll position indicator. Triggers re-render when the value changes.
val set_item_spacing : t -> int -> unitset_item_spacing t n sets vertical spacing between items in cells. n is clamped to minimum 0. Recalculates layout and triggers re-render when the value changes.
Behavior
val set_wrap_selection : t -> bool -> unitset_wrap_selection t flag enables or disables wrapping to the opposite end when navigating past list boundaries. Triggers re-render when the value changes.
val set_fast_scroll_step : t -> int -> unitset_fast_scroll_step t n sets the number of items to skip with Shift+Up/Down. n is clamped to minimum 1. Triggers re-render when the value changes.
Colors
val set_background : t -> Ansi.Color.t -> unitset_background t color sets the unfocused background color.
val set_text_color : t -> Ansi.Color.t -> unitset_text_color t color sets the unfocused text color.
val set_focused_background : t -> Ansi.Color.t -> unitset_focused_background t color sets the focused background color.
val set_focused_text_color : t -> Ansi.Color.t -> unitset_focused_text_color t color sets the focused text color.
val set_selected_background : t -> Ansi.Color.t -> unitset_selected_background t color sets the selected item background color.
val set_selected_text_color : t -> Ansi.Color.t -> unitset_selected_text_color t color sets the selected item text color.
val set_description_color : t -> Ansi.Color.t -> unitset_description_color t color sets the description text color.
val set_selected_description_color : t -> Ansi.Color.t -> unitset_selected_description_color t color sets the selected item description text color.
Callbacks
val set_on_change : t -> (int -> unit) option -> unitset_on_change t callback registers a callback fired when the selected index changes. The callback receives the new index. Pass None to clear. See set_selected_index.
val set_on_activate : t -> (int -> unit) option -> unitset_on_activate t callback registers a callback fired when the current item is activated (Enter or KP_enter). The callback receives the activated item index. Pass None to clear.
Layout
val set_style : t -> Toffee.Style.t -> unitset_style t style sets the layout style on the underlying renderable.
Formatting
val pp : Format.formatter -> t -> unitpp ppf t formats t on ppf for debugging.