package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Text_surface/index.html
Module Mosaic_ui.Text_surfaceSource
Text rendering surface with wrapping, viewport, and selection.
Text rendering surface with wrapping, viewport, and selection.
A surface wraps a Text_buffer.t and a Renderable.t, providing line wrapping, viewport-based scrolling, intrinsic measurement, and selection overlay rendering. The surface registers render and measure callbacks on the renderable automatically.
Used by Text for static rich text display, by Textarea for multi-line editing, and potentially by other renderables that need text buffer rendering.
See Text_buffer for the underlying styled text storage.
A text rendering surface.
Wrapping mode.
`None: no wrapping; lines extend beyond the viewport.`Char: break at grapheme cluster boundaries.`Word: break at word boundaries (spaces, hyphens, etc.); falls back to`Charwhen a word exceeds the wrap width.
Construction
create node buffer is a surface that renders buffer through node. Registers render and measure callbacks on node.
Accessors
buffer t is the underlying text buffer.
node t is the underlying renderable.
Wrapping
set_wrap t mode changes the wrapping mode. Invalidates display lines and marks layout dirty.
wrap_width t is the explicit wrap width, or None when the width is derived from the renderable's layout width.
set_wrap_width t w sets an explicit wrap width. None derives the width from the renderable's layout. Invalidates display lines and marks layout dirty.
truncate t is true when lines are truncated with an ellipsis. Only applies when wrap t = `None.
set_truncate t v enables or disables line truncation. When enabled and wrap = `None, lines exceeding the viewport width are cut with an ellipsis character. Invalidates display lines and marks layout dirty.
Viewport
set_scroll_x t x sets the horizontal scroll offset, clamped to [0;max_scroll_x]. Requests a render if changed.
set_scroll_y t y sets the vertical scroll offset, clamped to [0;max_scroll_y]. Requests a render if changed.
Display lines
A display line is a list of styled spans that fit within the wrap width.
type display_info = {lines : display_line array;(*The wrapped display lines.
*)line_sources : int array;(*
*)line_sources.(i)is the logical line index that display lineioriginates from.line_grapheme_offsets : int array;(*
*)line_grapheme_offsets.(i)is the grapheme offset of display lineiin the full text. Used for mapping highlights and cursor positions.line_wrap_indices : int array;(*
*)line_wrap_indices.(i)is the sub-line index within its logical line:0for the first display line,1for the first continuation, etc. Useful for line numbering and gutter rendering.max_line_width : int;(*The widest display line in columns.
*)
}Wrapped display line metrics.
display_info t is the current wrapped line metrics. Cached; recomputed when content or wrap settings change.
Selection
set_selection_bg t color sets the selection background color.
set_selection_fg t color sets the selection foreground color.
set_selection t ~start ~end_ sets the selection range by grapheme offsets into the buffer content. Offsets are clamped to content bounds. The selection is active when start <> end_. Returns true if the selection state changed.
selection t is Some (start, end_) when a selection is active, with start < end_ as normalized grapheme offsets. None when no selection is active.
val set_local_selection :
t ->
anchor_x:int ->
anchor_y:int ->
focus_x:int ->
focus_y:int ->
boolset_local_selection t ~anchor_x ~anchor_y ~focus_x ~focus_y sets the selection from viewport-local coordinates. Coordinates are converted to grapheme offsets accounting for scroll position. Activates the selection unconditionally. Returns true if the selection changed.
See update_local_selection for updating an existing drag.
val update_local_selection :
t ->
anchor_x:int ->
anchor_y:int ->
focus_x:int ->
focus_y:int ->
boolupdate_local_selection t ~anchor_x ~anchor_y ~focus_x ~focus_y is like set_local_selection but only considers offset changes (does not re-check active state). Returns true if the selection changed.
reset_selection t clears any active selection and requests a render.
selected_text t is the text within the current selection. Returns "" if no selection is active.