Class UITextModeView
UI Canvas variant of the text mode grid renderer. Extends UnityEngine.UI.MaskableGraphic to support Canvas masking, CanvasGroup alpha, and RectTransform-based layout. Renders the cell grid using a fullscreen quad where the fragment shader computes cell indices from pixel position. Grid columns and rows are auto-computed from FontSize and the RectTransform dimensions.
Inheritance
Implements
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
[ExecuteAlways]
[DisallowMultipleComponent]
[RequireComponent(typeof(CanvasRenderer))]
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("Scylla/TextMode/UI TextMode View")]
public class UITextModeView : MaskableGraphic, ICanvasElement, IClippable, IMaskable, IMaterialModifier, ITextModeRenderSource, ITextModeGridProvider, IScyllaInspectorChangeHandler
Properties
BorderColor
Gets the color the border cells show: DefaultBackground while BorderFollowsTheme is set, otherwise fully transparent.
Declaration
public Color32 BorderColor { get; }
Property Value
| Type | Description |
|---|---|
| Color32 |
Remarks
For a view that follows the color theme this is the theme's background. A view that keeps its own colors gets a border in its own background color, so the border always matches the empty cells next to it.
BorderFollowsTheme
Gets or sets whether the CellBorder shows the grid's background color, DefaultBackground. Defaults to true.
Declaration
public bool BorderFollowsTheme { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When false, the border is transparent, so whatever lies behind the view shows through it: the scene, a panel, or the clear color of the camera.
CellBorder
Gets or sets the frame of whole cells around the content grid. Defaults to none.
Declaration
public TextModeCellBorder CellBorder { get; set; }
Property Value
| Type | Description |
|---|---|
| TextModeCellBorder |
Remarks
The view lays out as many cells as fit its RectTransform and centers them. The outer cells on each side form the border: they show DefaultBackground and never hold content. Columns, Rows and Grid cover only the cells inside the frame, so everything that writes into the grid, such as a terminal with its line wrapping, scrolling and cursor, stays inside it.
Reading returns the border in use. It can be smaller than the value set when the view is too small for it, because the content always keeps at least one column and one row. The value set is kept and applies again once there is room.
CellSize
Gets the computed cell size in canvas pixels.
Declaration
public Vector2 CellSize { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
CharSpacing
Gets or sets the character spacing multiplier. 1.0 = natural advance width. Values below 1.0 pack characters tighter. Changing this recomputes the grid layout.
Declaration
public float CharSpacing { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Columns
Gets the auto-computed number of content columns, without the CellBorder.
Declaration
public int Columns { get; }
Property Value
| Type | Description |
|---|---|
| int |
CursorBlinkRate
Gets or sets the cursor blink rate in full cycles per second. Higher values produce faster blinking. Default is 1.0 (1 second on, 1 second off).
Declaration
public float CursorBlinkRate { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
CursorBlinking
Gets or sets whether the cursor blinks. When disabled, the cursor remains visible at all times.
Declaration
public bool CursorBlinking { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
CursorColor
Gets or sets the cursor color.
Declaration
public Color CursorColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
CursorStyle
Gets or sets the cursor visual style.
Declaration
public CursorStyle CursorStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| CursorStyle |
DefaultBackground
Gets or sets the default background color used for empty cells and newly created cells during grid resize. Must be set before the view initializes for the initial grid creation to use the correct color.
Declaration
public Color32 DefaultBackground { get; set; }
Property Value
| Type | Description |
|---|---|
| Color32 |
DefaultForeground
Gets or sets the default foreground color used for cells written without an explicit color, and for cells the grid fills when it is cleared or resized.
Declaration
public Color32 DefaultForeground { get; set; }
Property Value
| Type | Description |
|---|---|
| Color32 |
Remarks
Setting this changes what future writes and clears use. It does not recolor cells that already hold a color, because every cell stores its own. Use TextModeThemeRemapper to retint existing content.
DrawSelf
Gets or sets whether the view draws its grid itself. Defaults to true.
Declaration
public bool DrawSelf { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When false, the view draws an empty mesh, but it keeps uploading cells, running effects, blinking the cursor and handling input and selection. A component that shows the grid in another form, such as the CRT, turns it off and sets it back when it goes away. See ITextModeRenderSource.
Effects
Gets the effect player for this view, creating it the first time it is used.
Declaration
public TextModeEffectPlayer Effects { get; }
Property Value
| Type | Description |
|---|---|
| TextModeEffectPlayer |
Remarks
A view that never runs an effect never creates a player, so the cost of the effects
system on an unused view is one null check per frame. Once created, the player is
advanced in LateUpdate just before the grid is uploaded to the GPU, so effect
writes reach the screen in the same frame they are computed.
Returns null until the view is initialized, because effects need a grid to write into.
FollowColorTheme
Gets or sets whether this view adopts the active color theme when the theme changes.
Declaration
public bool FollowColorTheme { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Enabled by default, which is what makes a global theme switch repaint every view without the game redrawing anything. Turn it off for a view whose colors are owned by another system, so a theme change leaves them alone. The debug console is the case this exists for: it paints a transparent background so its own gradient shows through, and a theme would otherwise overwrite that with an opaque color.
Turning this off suppresses only later theme changes. Colors already applied stay as they are, so set it before the first theme is applied when the view must never be retinted at all.
FontAsset
Gets or sets the TMP font asset used for glyph rendering. Setting a new font at runtime triggers a full re-initialization.
Declaration
public TMP_FontAsset FontAsset { get; set; }
Property Value
| Type | Description |
|---|---|
| TMP_FontAsset |
FontSize
Gets or sets the font size in canvas pixels. Changing the font size recomputes the grid layout and resizes the grid if needed.
Declaration
public float FontSize { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
GlyphCache
Gets the glyph atlas cache.
Declaration
public GlyphAtlasCache GlyphCache { get; }
Property Value
| Type | Description |
|---|---|
| GlyphAtlasCache |
Grid
Gets the cell grid for reading and writing cell data.
Declaration
public CellGrid Grid { get; }
Property Value
| Type | Description |
|---|---|
| CellGrid |
IsInitialized
Gets whether the view is initialized.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LineHeight
Gets or sets the line height multiplier. 1.0 = natural line height. Values above 1.0 add vertical spacing between rows. Changing this recomputes the grid layout.
Declaration
public float LineHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Remarks
Values below 1.0 pack the rows closer together without changing the size of the glyphs. The space a line does not use is given up first, so nothing is lost down to roughly 0.82; below that the glyphs reach into the rows above and below, which draw the overhanging parts rather than clipping them.
Assigning this takes ownership of the value. Until then the view uses the default line height from the TextMode module configuration and follows it when the configuration changes, in the same way it follows the configured SDF settings.
PointerMapper
Gets or sets the mapper that converts screen points to grid positions, or null to use the view's own area. Defaults to null. See PointerMapper.
Declaration
public ITextModePointerMapper PointerMapper { get; set; }
Property Value
| Type | Description |
|---|---|
| ITextModePointerMapper |
Rows
Gets the auto-computed number of content rows, without the CellBorder.
Declaration
public int Rows { get; }
Property Value
| Type | Description |
|---|---|
| int |
SRGBCorrection
Gets or sets whether sRGB-to-linear correction is applied when unpacking cell colors. Enable for correct brightness in Linear color space. Default is true.
Declaration
public bool SRGBCorrection { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
SelectionColor
Gets or sets the background of selected cells.
Declaration
public Color SelectionColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Remarks
Selected cells are drawn in SelectionTextColor on this color, in place of their own colors. The built-in themes pick the pair so a selection reads as inverse text.
SelectionTextColor
Gets or sets the text color of selected cells. See SelectionColor.
Declaration
public Color SelectionTextColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
TextBlinkRate
Gets or sets the text blink rate in full cycles per second (for the Blink cell attribute). Higher values produce faster blinking. Default is 1.0 (1 second on, 1 second off).
Declaration
public float TextBlinkRate { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
mainTexture
Gets the atlas texture for the material.
Declaration
public override Texture mainTexture { get; }
Property Value
| Type | Description |
|---|---|
| Texture |
Overrides
Methods
ApplyTheme(in TextModeColorScheme)
Applies a color theme to this view, replacing the default foreground and background, the cursor color and the selection color with the theme's.
Declaration
public void ApplyTheme(in TextModeColorScheme scheme)
Parameters
| Type | Name | Description |
|---|---|---|
| TextModeColorScheme | scheme | The resolved theme colors to apply. |
Remarks
This changes what the view writes and clears with from now on. Text already on the grid keeps the colors it was written with, because every cell stores its own; pass the grid to TextModeThemeRemapper as well to retint it.
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Declaration
protected override void OnEnable()
Overrides
OnPopulateMesh(VertexHelper)
Populates the mesh with a fullscreen quad filling the RectTransform.
Declaration
protected override void OnPopulateMesh(VertexHelper vh)
Parameters
| Type | Name | Description |
|---|---|---|
| VertexHelper | vh |
Overrides
OnRectTransformDimensionsChange()
Declaration
protected override void OnRectTransformDimensionsChange()
Overrides
ResetCursorBlink()
Resets the cursor blink cycle so it restarts from the visible phase. Call this on keystroke or input activity to keep the cursor visible during active typing, matching standard terminal emulator behavior.
Declaration
public void ResetCursorBlink()
ScreenPointToCell(Vector2, Camera, out CellPosition)
Converts a screen point to a cell position in the grid. Uses UnityEngine.RectTransformUtility.ScreenPointToLocalPointInRectangle(UnityEngine.RectTransform, UnityEngine.Vector2, UnityEngine.Camera, out UnityEngine.Vector2) to convert the screen point to local RectTransform coordinates, then maps to cell indices.
Declaration
public bool ScreenPointToCell(Vector2 screenPoint, Camera eventCamera, out CellPosition cellPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | screenPoint | Screen-space point (e.g. from |
| Camera | eventCamera | Canvas event camera. Pass null for ScreenSpaceOverlay mode. For ScreenSpaceCamera mode, this must be the canvas world camera. |
| CellPosition | cellPosition | The resulting cell position if the point is within the grid. |
Returns
| Type | Description |
|---|---|
| bool | True if the screen point maps to a valid cell in the grid. |
SetCell(int, int, uint, Color32, Color32, CellAttributes)
Sets a cell at the specified position with glyph atlas stamping.
Declaration
public void SetCell(int row, int col, uint codepoint, Color32 fg, Color32 bg, CellAttributes attributes = CellAttributes.None)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | Row index. |
| int | col | Column index. |
| uint | codepoint | Unicode codepoint. |
| Color32 | fg | Foreground color. |
| Color32 | bg | Background color. |
| CellAttributes | attributes | Cell attributes. |
SetGrid(CellGrid)
Replaces the active cell grid reference with an external grid. Used when a TerminalEmulator switches between primary and alternate screen buffers. The new grid must have the same dimensions as the current grid.
Declaration
public void SetGrid(CellGrid newGrid)
Parameters
| Type | Name | Description |
|---|---|---|
| CellGrid | newGrid | The new cell grid to render. |
TryWriteCellProperties(MaterialPropertyBlock)
Writes everything a cell shader needs to shade this view's grid into a property block: the cell buffer, the grid size, the border and its color, the font atlas, the SDF, cursor and selection settings and the current blink phases.
Declaration
public bool TryWriteCellProperties(MaterialPropertyBlock block)
Parameters
| Type | Name | Description |
|---|---|---|
| MaterialPropertyBlock | block | The property block to write into. Existing values are overwritten. |
Returns
| Type | Description |
|---|---|
| bool | True if the view is initialized and the block holds a complete set of properties. |
Remarks
The cell size is not written, because it depends on the target. The caller sets
_CellSize itself.
Events
GridResizing
Raised when the view's layout changed the grid size, just before the view resizes the grid it renders. The arguments are the new row and column counts.
Declaration
public event Action<int, int> GridResizing
Event Type
| Type | Description |
|---|---|
| Action<int, int> |
Remarks
The owner of the grid can resize it here first, in its own way, and the view then finds it at the right size and leaves the content alone. A terminal uses this to keep the line with the cursor on screen instead of letting the view cut off the bottom rows.