Class LineScrollTextArea
A line-by-line scrolling text display component for terminal and console-style output.
Scrolls by discrete logical lines rather than pixels and uses TextMeshProUGUI
for rendering.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
[RequireComponent(typeof(RectTransform))]
public sealed class LineScrollTextArea : MonoBehaviour
Remarks
LineScrollTextArea manages a LineScrollTextBuffer that tracks
content lines, a computed window size (number of fully visible lines), and a TMP
rendering component inside a RectMask2D-clipped viewport. The viewport is sized
to exactly windowSize * lineHeight pixels so that only whole lines are ever shown.
Partial-line transitions are handled by an overflow mechanism: the buffer can
produce one extra line above and below the visible window. Those overflow lines
are rendered off-screen and clipped by the viewport mask, while the text rect's
anchoredPosition is shifted to reveal a fractional portion during edge
bounce animations.
Scroll input is external. The component provides two high-level input methods - HandleScrollInput(bool, bool) and HandlePageScrollInput(bool, bool) - that accept raw boolean button states and internally handle initial-delay and key-repeat timing. Call ResetScrollInputState() when the component loses focus.
An optional edge bounce animation (EdgeBounceEnabled) plays a sine-wave offset when the user tries to scroll past the top or bottom boundary.
Text selection is opt-in via SelectionEnabled. Call HandleSelectionInput(Vector2, bool, bool, bool, bool) every frame to drive line-based selection. Selected text can be retrieved with SelectedText or copied to the clipboard via CopySelectionToClipboard().
Fields
DEFAULT_BUFFER_CAPACITY
Default buffer capacity (maximum logical lines).
Declaration
public const int DEFAULT_BUFFER_CAPACITY = 1000
Field Value
| Type | Description |
|---|---|
| int |
DEFAULT_EDGE_BOUNCE_AMPLITUDE
Default edge bounce amplitude in pixels.
Declaration
public const float DEFAULT_EDGE_BOUNCE_AMPLITUDE = 10
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_EDGE_BOUNCE_DURATION
Default edge bounce duration in seconds.
Declaration
public const float DEFAULT_EDGE_BOUNCE_DURATION = 0.15
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_FONT_SIZE
Default font size for the text area.
Declaration
public const float DEFAULT_FONT_SIZE = 14
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_PADDING
Default padding around the text content (in pixels).
Declaration
public const float DEFAULT_PADDING = 0
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLLBAR_AUTO_HIDE_DELAY
Default delay before scrollbar auto-hide starts in seconds.
Declaration
public const float DEFAULT_SCROLLBAR_AUTO_HIDE_DELAY = 0.75
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLLBAR_FADE_DURATION
Default duration for scrollbar fade animation in seconds.
Declaration
public const float DEFAULT_SCROLLBAR_FADE_DURATION = 0.3
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLLBAR_MARGIN
Default margin between scrollbar and viewport edge in pixels.
Declaration
public const float DEFAULT_SCROLLBAR_MARGIN = 2
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLLBAR_MIN_THUMB_HEIGHT
Minimum height for the scrollbar thumb in pixels.
Declaration
public const float DEFAULT_SCROLLBAR_MIN_THUMB_HEIGHT = 20
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLLBAR_THUMB_COLOR
Default scrollbar thumb color (semi-transparent white).
Declaration
public static readonly Color DEFAULT_SCROLLBAR_THUMB_COLOR
Field Value
| Type | Description |
|---|---|
| Color |
DEFAULT_SCROLLBAR_TRACK_COLOR
Default scrollbar track color (fully transparent).
Declaration
public static readonly Color DEFAULT_SCROLLBAR_TRACK_COLOR
Field Value
| Type | Description |
|---|---|
| Color |
DEFAULT_SCROLLBAR_WIDTH
Default scrollbar width in pixels.
Declaration
public const float DEFAULT_SCROLLBAR_WIDTH = 6
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLL_INITIAL_DELAY
Default delay before key repeat starts (in seconds).
Declaration
public const float DEFAULT_SCROLL_INITIAL_DELAY = 0.4
Field Value
| Type | Description |
|---|---|
| float |
DEFAULT_SCROLL_REPEAT_INTERVAL
Default interval between scroll repeats when key is held (in seconds).
Declaration
public const float DEFAULT_SCROLL_REPEAT_INTERVAL = 0.04
Field Value
| Type | Description |
|---|---|
| float |
Properties
AutoScroll
Gets or sets whether auto-scroll is enabled.
Declaration
public bool AutoScroll { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Buffer
Gets the underlying text buffer that stores and manages all logical content lines. Use this to access line data, total line counts, and buffer-level scroll state directly.
Declaration
public LineScrollTextBuffer Buffer { get; }
Property Value
| Type | Description |
|---|---|
| LineScrollTextBuffer |
BufferCapacity
Gets or sets the buffer capacity (maximum number of logical lines). Setting this value will recreate the buffer, clearing any existing content.
Declaration
public int BufferCapacity { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
EdgeBounceEnabled
Gets or sets whether the edge bounce effect is enabled. When enabled, a visual bounce animation plays when scrolling hits the top or bottom boundary.
Declaration
public bool EdgeBounceEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Font
Gets or sets the font asset.
Declaration
public TMP_FontAsset Font { get; set; }
Property Value
| Type | Description |
|---|---|
| TMP_FontAsset |
FontSize
Gets or sets the font size.
Declaration
public float FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
HasSelection
Gets whether there is an active (non-empty) selection.
Declaration
public bool HasSelection { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsAtBottom
Gets whether the view is at the bottom (newest content visible).
Declaration
public bool IsAtBottom { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsAtTop
Gets whether the view is at the top (oldest content visible).
Declaration
public bool IsAtTop { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LineCount
Gets the current line count in the buffer.
Declaration
public int LineCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
LineHeight
Gets the calculated line height in pixels, as determined by the TMP font metrics. Returns 0 if the component has not been initialized yet.
Declaration
public float LineHeight { get; }
Property Value
| Type | Description |
|---|---|
| float |
NeedsRefresh
Gets whether the component needs a display refresh.
Declaration
public bool NeedsRefresh { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Padding
Gets or sets the padding around the text content (in pixels).
Declaration
public float Padding { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
RectTransform
Gets the RectTransform of this component.
Declaration
public RectTransform RectTransform { get; }
Property Value
| Type | Description |
|---|---|
| RectTransform |
ScrollInitialDelay
Gets or sets the delay before key repeat starts when holding a scroll key (in seconds).
Declaration
public float ScrollInitialDelay { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ScrollRepeatInterval
Gets or sets the interval between scroll repeats when key is held (in seconds).
Declaration
public float ScrollRepeatInterval { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ScrollbarAutoHide
Gets or sets whether the scrollbar auto-hides when not scrolling.
Declaration
public bool ScrollbarAutoHide { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ScrollbarAutoHideDelay
Gets or sets the delay before scrollbar auto-hide starts in seconds.
Declaration
public float ScrollbarAutoHideDelay { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ScrollbarEnabled
Gets or sets whether the scrollbar is enabled. When enabled, a visual scrollbar indicator appears on the right side of the viewport.
Declaration
public bool ScrollbarEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ScrollbarFadeDuration
Gets or sets the duration for scrollbar fade animation in seconds.
Declaration
public float ScrollbarFadeDuration { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ScrollbarMinThumbHeight
Gets or sets the minimum scrollbar thumb height in pixels.
Declaration
public float ScrollbarMinThumbHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ScrollbarThumbColor
Gets or sets the scrollbar thumb color.
Declaration
public Color ScrollbarThumbColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
ScrollbarTrackColor
Gets or sets the scrollbar track color. Set alpha to 0 for an invisible track.
Declaration
public Color ScrollbarTrackColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
ScrollbarWidth
Gets or sets the scrollbar width in pixels.
Declaration
public float ScrollbarWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
SelectedText
Gets the currently selected text content.
Declaration
public string SelectedText { get; }
Property Value
| Type | Description |
|---|---|
| string |
Selection
Gets the current selection range.
Declaration
public TextSelectionRange Selection { get; }
Property Value
| Type | Description |
|---|---|
| TextSelectionRange |
SelectionColor
Gets or sets the selection highlight color.
Declaration
public Color SelectionColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
SelectionEnabled
Gets or sets whether text selection is enabled.
Declaration
public bool SelectionEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
TextColor
Gets or sets the text color.
Declaration
public Color TextColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
TextComponent
Gets the TextMeshProUGUI component used for rendering.
Declaration
public TextMeshProUGUI TextComponent { get; }
Property Value
| Type | Description |
|---|---|
| TextMeshProUGUI |
WindowSize
Gets the current window size (number of visible lines).
Declaration
public int WindowSize { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AppendLine(string)
Appends a single line of text to the buffer. If AutoScroll is
true, the buffer automatically advances the view to keep the newest
content visible.
Declaration
public void AppendLine(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to append. May be |
AppendLines(params string[])
Appends multiple lines of text to the buffer in a single batch. Auto-scroll behavior follows the same rules as AppendLine(string).
Declaration
public void AppendLines(params string[] lines)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | lines | The lines to append. The method is a no-op if this array is |
Clear()
Clears all content from the buffer.
Declaration
public void Clear()
ClearSelection()
Clears the current selection.
Declaration
public void ClearSelection()
CopySelectionToClipboard()
Copies selected text to the system clipboard.
Declaration
public void CopySelectionToClipboard()
ForceRefresh()
Immediately recalculates display metrics (window size, line height) and redraws
the text content without waiting for the next Update. Use this when
external layout changes have resized the component and the next frame update is
too late.
Declaration
public void ForceRefresh()
HandlePageScrollInput(bool, bool)
Handles page scroll input with key repeat support. Call this method every frame with the current state of page scroll inputs. The component will handle timing for initial delay and repeat interval.
Declaration
public void HandlePageScrollInput(bool pageUpPressed, bool pageDownPressed)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | pageUpPressed | Whether the page up input is currently pressed. |
| bool | pageDownPressed | Whether the page down input is currently pressed. |
HandleScrollInput(bool, bool)
Handles scroll input with key repeat support. Call this method every frame with the current state of scroll inputs. The component will handle timing for initial delay and repeat interval.
Declaration
public void HandleScrollInput(bool scrollUpPressed, bool scrollDownPressed)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | scrollUpPressed | Whether the scroll up input is currently pressed. |
| bool | scrollDownPressed | Whether the scroll down input is currently pressed. |
HandleSelectionInput(Vector2, bool, bool, bool, bool)
Handles selection input. Call every frame when selection is enabled. Selection is line-based: clicking and dragging with modifier key selects full lines. When modifier key is not held, normal interaction should be used instead.
Declaration
public bool HandleSelectionInput(Vector2 mousePosition, bool leftButtonPressed, bool leftButtonPressedThisFrame, bool leftButtonReleasedThisFrame, bool modifierPressed)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | mousePosition | The current mouse position in screen coordinates. |
| bool | leftButtonPressed | Whether the left mouse button is currently pressed. |
| bool | leftButtonPressedThisFrame | Whether the left mouse button was pressed this frame. |
| bool | leftButtonReleasedThisFrame | Whether the left mouse button was released this frame. |
| bool | modifierPressed | Whether the selection modifier key (e.g., Shift) is held. |
Returns
| Type | Description |
|---|---|
| bool | True if selection is being handled. |
ResetScrollInputState()
Resets the scroll input state. Call this when the component loses focus or input context changes.
Declaration
public void ResetScrollInputState()
ScrollDownLine()
Scrolls down by one line.
Declaration
public void ScrollDownLine()
ScrollDownPage()
Scrolls down by one page (the number of visible lines in the window).
Declaration
public void ScrollDownPage()
ScrollToBottom()
Scrolls to the bottom (newest content).
Declaration
public void ScrollToBottom()
ScrollToTop()
Scrolls to the top (oldest content).
Declaration
public void ScrollToTop()
ScrollUpLine()
Scrolls up by one line.
Declaration
public void ScrollUpLine()
ScrollUpPage()
Scrolls up by one page (the number of visible lines in the window).
Declaration
public void ScrollUpPage()
SelectAll()
Selects all text in the buffer.
Declaration
public void SelectAll()
SetEventPublishing(bool)
Enables or disables Scylla event publishing for the buffer.
When enabled, buffer-level events such as line-added notifications are published
via ScyllaEvents. Event publishing is disabled by default for performance.
Declaration
public void SetEventPublishing(bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
TryGetLineIndexFromScreenPoint(Vector2, out int)
Attempts to get the logical line index at a screen position. Used for line-based selection.
Declaration
public bool TryGetLineIndexFromScreenPoint(Vector2 screenPos, out int lineIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | screenPos | The screen position. |
| int | lineIndex | The logical line index if successful. |
Returns
| Type | Description |
|---|---|
| bool | True if the conversion was successful. |