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.
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.
line_sources.(i) is the logical line index that display line i originates from.
*)
line_grapheme_offsets : int array;
(*
line_grapheme_offsets.(i) is the grapheme offset of display line i in 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: 0 for the first display line, 1 for the first continuation, etc. Useful for line numbering and gutter rendering.
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.
set_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.
update_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.