Skip to content

Data Structures

Dustin Horne edited this page Mar 5, 2026 · 1 revision

Data Structures

Namespace: ParentElement.RichText.Core.Data

Lightweight value types used to configure the document, communicate size changes, and describe the current navigation state.


DocumentSettings

Controls the document page layout and default formatting. Pass an instance to the DocumentController constructor and use ApplyDocumentSettings to update it at runtime.

public struct DocumentSettings

Properties

Property Type Default Description
PageWidth float 800 Width of the document page in pixels
PageHeight float 1056 Height of one page in pixels (US Letter @ 96 dpi)
PageGap float 24 Vertical gap between pages when page breaks are shown
DocumentMargins DocumentMargins default Inner margins applied within the page boundary
DocumentBackgroundColor SKColor White Background color of the page area
CanvasBackgroundColor SKColor #E8E8E8 Background color of the canvas surrounding the page
TextStyle IStyle DefaultStyle Default character style for new text
Alignment TextAlignment Left Default paragraph alignment
ShowPageBreaks bool false Whether to render a visual page separator

Example

var settings = new DocumentSettings
{
    PageWidth            = 816,   // US Letter at 96 dpi
    PageHeight           = 1056,
    ShowPageBreaks       = true,
    DocumentMargins      = new DocumentMargins(72, 72, 72, 72),
    DocumentBackgroundColor = SKColors.White,
    CanvasBackgroundColor   = new SKColor(0xE8, 0xE8, 0xE8),
};

DocumentMargins

Defines the inner margins of the document page.

public struct DocumentMargins

Constructor

public DocumentMargins(float left, float right, float top, float bottom)

Properties

Property Type Description
Left float Left margin in pixels
Right float Right margin in pixels
Top float Top margin in pixels
Bottom float Bottom margin in pixels

Example

// 0.75-inch margins at 96 dpi
var margins = new DocumentMargins(left: 72, right: 72, top: 72, bottom: 72);

// Object-initializer syntax
var margins = new DocumentMargins { Left = 40, Right = 40, Top = 24, Bottom = 24 };

DocumentInfo

Snapshot of the document's current dimensions and scroll position. Delivered via the IDocumentController.OnContentSizeChanged event.

public struct DocumentInfo

Constructor

public DocumentInfo(float width, float height, Vector2 scrollOffset)

Fields

Field Type Description
Width float Document page width in pixels
Height float Total rendered content height in pixels
ScrollOffset Vector2 Current scroll position of the viewport

Example

editor.OnContentSizeChanged += info =>
{
    scrollbar.Maximum = info.Height;
    scrollbar.Value   = info.ScrollOffset.Y;
};

NavigationInfo

Snapshot of the caret position, selection, and style. Delivered via the IDocumentController.OnNavigation event every time the caret moves or the selection changes.

public struct NavigationInfo

Constructor

public NavigationInfo(TextRange selection, IStyle styleAtCaret, SelectionInfo selectionInfo)

Properties

Property Type Description
Selection TextRange The current selection range within the document
StyleAtCaret IStyle Resolved character style at the caret position
SelectionInfo SelectionInfo Detailed selection metadata (word, paragraph boundaries)

Example

editor.OnNavigation += info =>
{
    // Sync toolbar state
    boldButton.IsChecked   = info.StyleAtCaret.Bold ?? false;
    italicButton.IsChecked = info.StyleAtCaret.Italic ?? false;
    fontPicker.Value       = info.StyleAtCaret.FontFamily ?? "Arial";
    sizePicker.Value       = (int)(info.StyleAtCaret.FontSize ?? 12);

    // Update status bar
    statusBar.Text = info.SelectionInfo.IsSelection
        ? $"{info.SelectionInfo.Length} characters selected"
        : "Ready";
};

ViewModifier

A combined scale + offset transform applied when converting pointer (screen) coordinates to document coordinates.

public struct ViewModifier

Properties

Property Type Access Description
Scale Vector2 get / set Zoom scale. Setting this recomputes ScaledOffset
Offset Vector2 get / set Pixel scroll offset. Setting this recomputes ScaledOffset
ScaledOffset Vector2 get Offset / Scale — pre-divided for efficient coordinate transforms

How It Works

Point.FromView(ViewModifier) uses ScaledOffset to transform a screen-space point into document space:

documentX = screenX / scale.X + scaledOffset.X
documentY = screenY / scale.X + scaledOffset.Y

Example

var view = new ViewModifier
{
    Scale  = new Vector2(zoomFactor, zoomFactor),
    Offset = new Vector2(scrollX, scrollY),
};

var docPoint = screenPoint.FromView(view);
editor.Click(docPoint);

See also: IDocumentController · Geometry

Clone this wiki locally