-
Notifications
You must be signed in to change notification settings - Fork 0
Data Structures
Namespace: ParentElement.RichText.Core.Data
Lightweight value types used to configure the document, communicate size changes, and describe the current navigation state.
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| 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 |
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),
};Defines the inner margins of the document page.
public struct DocumentMarginspublic DocumentMargins(float left, float right, float top, float bottom)| 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 |
// 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 };Snapshot of the document's current dimensions and scroll position. Delivered via the IDocumentController.OnContentSizeChanged event.
public struct DocumentInfopublic DocumentInfo(float width, float height, Vector2 scrollOffset)| 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 |
editor.OnContentSizeChanged += info =>
{
scrollbar.Maximum = info.Height;
scrollbar.Value = info.ScrollOffset.Y;
};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 NavigationInfopublic NavigationInfo(TextRange selection, IStyle styleAtCaret, SelectionInfo selectionInfo)| 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) |
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";
};A combined scale + offset transform applied when converting pointer (screen) coordinates to document coordinates.
public struct ViewModifier| 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 |
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
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