Class ScrollTextAreaBuilder
Fluent builder for creating and configuring ScrollTextArea instances at runtime. All configuration methods return the same builder instance, enabling chainable method calls. Call Build() or TryBuild(out ScrollTextArea) as the terminal step to construct the Unity GameObject and obtain the component.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public sealed class ScrollTextAreaBuilder
Remarks
ScrollTextArea is a smooth-scrolling text display component that supports momentum physics and elastic bounce similar to mobile list scrolling. The builder exposes grouped configuration regions for basic layout, font, buffer behavior, background, physics, input, events, line alignment, text selection, and the scrollbar overlay.
The created GameObject receives an optional Image background component
and the ScrollTextArea MonoBehaviour. The object is automatically
assigned to the UI layer. Font configuration defaults to the ScyllaMono SDF
font unless overridden via WithFont(TMP_FontAsset).
Example usage:
var log = new ScrollTextAreaBuilder()
.WithParent(panelTransform)
.WithSize(500f, 300f)
.WithFontSize(14f)
.WithTextColor(Color.white)
.WithBackgroundColor(new Color(0.05f, 0.05f, 0.05f, 1f))
.WithModernScrollbar()
.WithAutoScroll(true)
.Build();
log.AppendLine("Hello, world!");
Methods
AtPosition(float, float)
Sets the anchored position offset of the component.
Declaration
public ScrollTextAreaBuilder AtPosition(float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | Horizontal offset in pixels from the anchor point. |
| float | y | Vertical offset in pixels from the anchor point. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
AtPosition(Vector2)
Sets the anchored position offset of the component.
Declaration
public ScrollTextAreaBuilder AtPosition(Vector2 position)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | Pixel offset from the anchor point applied to the |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
Build()
Builds and returns a fully configured ScrollTextArea component.
Declaration
public ScrollTextArea Build()
Returns
| Type | Description |
|---|---|
| ScrollTextArea | The newly created ScrollTextArea component. Never returns
|
Remarks
Creates a new root GameObject, applies the configured anchor and size,
optionally adds a background Image component, then attaches and
configures a ScrollTextArea MonoBehaviour. The object is
assigned to the UI layer. If no explicit font was set, the ScyllaMono
SDF font is loaded via FontUtil.LoadDefaultMonoSDF.
TryBuild(out ScrollTextArea)
Attempts to build the ScrollTextArea component, suppressing any exception and reporting failure through the return value instead.
Declaration
public bool TryBuild(out ScrollTextArea scrollTextArea)
Parameters
| Type | Name | Description |
|---|---|---|
| ScrollTextArea | scrollTextArea | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
UseDefaultMonoFont()
Reverts the font selection to the default ScyllaMono SDF monospace font. This is the default behavior when no explicit font has been set.
Declaration
public ScrollTextAreaBuilder UseDefaultMonoFont()
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithAnchor(UIAlignment)
Sets the anchor and pivot configuration for the component's RectTransform
by deriving a UIAnchor from the specified alignment.
Declaration
public ScrollTextAreaBuilder WithAnchor(UIAlignment alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAlignment | alignment | A UIAlignment value representing one of the nine standard anchor positions. Internally resolved via FromAlignment(UIAlignment). |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithAnchor(UIAnchor)
Sets the anchor and pivot configuration for the component's RectTransform
using an explicit UIAnchor value.
Declaration
public ScrollTextAreaBuilder WithAnchor(UIAnchor anchor)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAnchor | anchor | The UIAnchor describing |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithAutoScroll(bool)
Controls whether the component automatically scrolls to the bottom when new content is appended and the scroll position is already at the bottom.
Declaration
public ScrollTextAreaBuilder WithAutoScroll(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
Remarks
When true (the default), the view follows new content only if
the user has not manually scrolled away. To always force the view to
the bottom regardless of current scroll position, use
WithForceScrollToEnd(bool) instead.
See Also
WithBackground(bool, Color?)
Enables or disables the background Image component added to the
root GameObject, and optionally sets its color.
Declaration
public ScrollTextAreaBuilder WithBackground(bool enabled, Color? color = null)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
| Color? | color | Optional background color. When provided, sets the background color. When
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithBackgroundColor(Color)
Sets the background color and implicitly enables the background.
Declaration
public ScrollTextAreaBuilder WithBackgroundColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color applied to the background |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithBackgroundSprite(Sprite)
Sets a custom sliced sprite used as the background, and implicitly enables the background.
Declaration
public ScrollTextAreaBuilder WithBackgroundSprite(Sprite sprite)
Parameters
| Type | Name | Description |
|---|---|---|
| Sprite | sprite | The |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithBufferCapacity(int)
Sets the maximum number of lines the text buffer retains. When the buffer is full the oldest lines are discarded as new lines are appended.
Declaration
public ScrollTextAreaBuilder WithBufferCapacity(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The maximum line count, clamped to the range [MIN_CAPACITY, MAX_CAPACITY]. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithClassicScrollbar(Color, Color, float)
Configures a classic always-visible scrollbar with a visible track and no auto-hide behavior. Implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithClassicScrollbar(Color thumbColor, Color trackColor, float width = 10)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | thumbColor | The RGBA color of the thumb indicator. |
| Color | trackColor | The RGBA color of the background track. |
| float | width | The scrollbar width in pixels. Clamped to a minimum of 1 pixel. Defaults to 10 pixels. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithDecelerationRate(float)
Sets the deceleration rate that controls how quickly momentum-based scrolling slows to a stop after a drag gesture ends.
Declaration
public ScrollTextAreaBuilder WithDecelerationRate(float rate)
Parameters
| Type | Name | Description |
|---|---|---|
| float | rate | The deceleration rate, clamped to the range [0.01, 0.5]. Higher values cause momentum to dissipate faster, producing a snappier feel. Lower values allow the content to coast for longer before stopping. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithDragScroll(bool)
Enables or disables the ability to scroll by dragging the content area with a pointer.
Declaration
public ScrollTextAreaBuilder WithDragScroll(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithDragSensitivity(float)
Sets the drag scroll sensitivity multiplier applied to pointer movement delta during a drag gesture.
Declaration
public ScrollTextAreaBuilder WithDragSensitivity(float sensitivity)
Parameters
| Type | Name | Description |
|---|---|---|
| float | sensitivity | The sensitivity multiplier. Clamped to a minimum of 0.1. Values above 1.0 amplify the drag response; values below 1.0 dampen it. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithElasticDuration(float)
Sets the duration in seconds for the elastic bounce-back animation that returns the content to the boundary after an overshoot.
Declaration
public ScrollTextAreaBuilder WithElasticDuration(float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| float | duration | The bounce-back duration in seconds. Clamped to a minimum of 0.1 seconds. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithElasticStrength(float)
Sets the elastic strength that determines how much the content resists overshoot beyond the top or bottom scroll boundary.
Declaration
public ScrollTextAreaBuilder WithElasticStrength(float strength)
Parameters
| Type | Name | Description |
|---|---|---|
| float | strength | The elastic strength factor, clamped to the range [0.1, 1.0]. Higher values produce a stiffer feel with less visible overshoot; lower values allow more exaggerated bounce. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithEventPublishing(bool)
Enables or disables publishing of scroll and content events via the Scylla event system (SEX).
Declaration
public ScrollTextAreaBuilder WithEventPublishing(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithFont(TMP_FontAsset)
Sets the TMP font asset used to render text content in the scroll area. Calling this method with a non-null value disables the default monospace font fallback.
Declaration
public ScrollTextAreaBuilder WithFont(TMP_FontAsset font)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_FontAsset | font | The |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithFontSize(float)
Sets the font size in points for text rendered in the scroll area.
Declaration
public ScrollTextAreaBuilder WithFontSize(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size | The desired font size, clamped to the range [MIN_FONT_SIZE, MAX_FONT_SIZE] (1 to 500 points). |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithForceScrollToEnd(bool)
Controls whether the component always scrolls to the bottom whenever new content is appended, regardless of the current scroll position.
Declaration
public ScrollTextAreaBuilder WithForceScrollToEnd(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
Remarks
When true (the default), every AppendLine call causes
an immediate jump to the bottom, even if the user has manually scrolled
up. For a less intrusive behavior that only follows new content when
already at the bottom, use WithAutoScroll(bool) instead.
See Also
WithLineSnapping(bool)
Enables or disables line snapping, which causes the scroll position to snap to the nearest line boundary when momentum scrolling comes to rest.
Declaration
public ScrollTextAreaBuilder WithLineSnapping(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithLineSpacing(float)
Sets the line spacing as a percentage adjustment relative to the font's base line height.
Declaration
public ScrollTextAreaBuilder WithLineSpacing(float spacing)
Parameters
| Type | Name | Description |
|---|---|---|
| float | spacing | The line spacing percentage delta. Default is |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
Remarks
A value of 0 corresponds to 100% of the base line height
with no additional adjustment. Positive values add space between lines;
negative values reduce the gap.
WithModernScrollbar(Color?)
Configures a modern minimal scrollbar style similar to iOS and macOS, using a semi-transparent white thumb, an invisible track, and auto-hide. Implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithModernScrollbar(Color? thumbColor = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Color? | thumbColor | Optional custom thumb color. When |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithName(string)
Sets the name of the created root GameObject.
Declaration
public ScrollTextAreaBuilder WithName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to assign. When |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithPadding(float)
Sets the uniform padding between the component border and the text content area.
Declaration
public ScrollTextAreaBuilder WithPadding(float padding)
Parameters
| Type | Name | Description |
|---|---|---|
| float | padding | The padding in pixels applied equally on all sides. Clamped to a minimum
of |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithParent(Transform)
Sets the parent transform that the component's GameObject will be attached to.
Declaration
public ScrollTextAreaBuilder WithParent(Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parent | The parent transform. Pass |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithPhysics(float, float, float)
Configures all three physics parameters in a single call.
Declaration
public ScrollTextAreaBuilder WithPhysics(float decelerationRate, float elasticStrength, float elasticDuration)
Parameters
| Type | Name | Description |
|---|---|---|
| float | decelerationRate | Deceleration rate clamped to [0.01, 0.5]. See WithDecelerationRate(float). |
| float | elasticStrength | Elastic strength clamped to [0.1, 1.0]. See WithElasticStrength(float). |
| float | elasticDuration | Bounce-back duration in seconds (minimum 0.1). See WithElasticDuration(float). |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbar(bool)
Enables or disables the scrollbar indicator overlaid on the right side of the component.
Declaration
public ScrollTextAreaBuilder WithScrollbar(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarAutoHide(bool, float, float)
Configures the scrollbar auto-hide behavior and implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithScrollbarAutoHide(bool autoHide = true, float delay = 1, float fadeDuration = 0.3)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | autoHide |
|
| float | delay | Idle time in seconds before the fade animation begins. Clamped to a
minimum of |
| float | fadeDuration | Duration of the fade-out animation in seconds. Clamped to a minimum of 0.01 seconds. Defaults to 0.3 seconds. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarColors(Color, Color?)
Sets both the scrollbar thumb and track colors in a single call and implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithScrollbarColors(Color thumbColor, Color? trackColor = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | thumbColor | The RGBA color of the thumb indicator. |
| Color? | trackColor | Optional RGBA color of the track. When |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarMinThumbHeight(float)
Sets the minimum height of the scrollbar thumb in pixels, ensuring the thumb remains large enough to interact with even when the content is very long. Implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithScrollbarMinThumbHeight(float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | height | The minimum thumb height in pixels. Clamped to a minimum of 1 pixel. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarThumbColor(Color)
Sets the scrollbar thumb color and implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithScrollbarThumbColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color of the draggable thumb indicator. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarTrackColor(Color)
Sets the scrollbar track color and implicitly enables the scrollbar. Set the alpha to zero for a completely invisible track.
Declaration
public ScrollTextAreaBuilder WithScrollbarTrackColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color of the background track behind the thumb. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithScrollbarWidth(float)
Sets the scrollbar width in pixels and implicitly enables the scrollbar.
Declaration
public ScrollTextAreaBuilder WithScrollbarWidth(float width)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | The scrollbar width in pixels. Clamped to a minimum of 1 pixel. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithSelection(bool)
Enables or disables pointer-driven text line selection. When enabled, the user can hold a modifier key (such as Shift) and drag to select full lines. Without the modifier held, drag scrolling operates normally.
Declaration
public ScrollTextAreaBuilder WithSelection(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithSelectionColor(Color)
Sets the highlight color used to draw the selection overlay behind selected lines. Calling this method implicitly enables selection.
Declaration
public ScrollTextAreaBuilder WithSelectionColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA highlight color. Defaults to semi-transparent blue (0.2, 0.4, 0.8, 0.5). The alpha channel controls how opaque the overlay appears over the text. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithSize(float, float)
Sets the explicit width and height of the component's RectTransform.
Declaration
public ScrollTextAreaBuilder WithSize(float width, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | Width in pixels. Clamped to a minimum of 10 pixels. |
| float | height | Height in pixels. Clamped to a minimum of 10 pixels. |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithSize(Vector2)
Sets the explicit width and height of the component's RectTransform.
Declaration
public ScrollTextAreaBuilder WithSize(Vector2 size)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | size | A |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
See Also
WithTextColor(Color)
Sets the color of all text rendered in the scroll area.
Declaration
public ScrollTextAreaBuilder WithTextColor(Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The RGBA color applied to the text. Defaults to |
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |
WithViewportLineAlignment(bool)
Enables or disables automatic adjustment of the viewport height to be an exact multiple of the font line height, preventing partial lines from being visible at the bottom of the area.
Declaration
public ScrollTextAreaBuilder WithViewportLineAlignment(bool enabled = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| ScrollTextAreaBuilder | This builder instance, enabling fluent method chaining. |