API Reference
This page provides an overview of the Elaris.UI API structure, namespaces, and common patterns.
Namespace Organization
Section titled “Namespace Organization”Elaris.UI uses a clear namespace structure:
Ambystech.Elaris.UI- Core application and main typesAmbystech.Elaris.UI.Widgets- Base widget classAmbystech.Elaris.UI.Widgets.Layout- Layout widgetsAmbystech.Elaris.UI.Widgets.Display- Display widgetsAmbystech.Elaris.UI.Widgets.Input- Input widgetsAmbystech.Elaris.UI.Widgets.Data- Data widgetsAmbystech.Elaris.UI.Widgets.Menu- Menu widgetsAmbystech.Elaris.UI.Rendering- Rendering systemAmbystech.Elaris.UI.Input- Input handlingAmbystech.Elaris.UI.Core- Core utilitiesAmbystech.Elaris.UI.Enums- Enumerations
Core Classes
Section titled “Core Classes”Application
Section titled “Application”The main application class that manages the event loop and rendering.
| Method | Description |
|---|---|
Run(Widget rootWidget) | Starts the application with the specified root widget |
Stop() | Stops the application |
SetFocus(Widget widget) | Sets the focused widget |
| Property | Type | Description |
|---|---|---|
Screen | Screen? | The current screen instance |
TargetFps | int | Target frames per second (default: 30) |
InitialFocusWidget | Widget? | Widget to receive initial focus |
Screen
Section titled “Screen”The terminal screen abstraction with double-buffered rendering.
| Method | Description |
|---|---|
Clear() | Clears the back buffer |
SetCell(int x, int y, Cell cell) | Sets a cell in the back buffer |
WriteText(int x, int y, string text, ...) | Writes text to the back buffer |
FillRectangle(Rectangle rect, ...) | Fills a rectangle |
DrawRectangle(Rectangle rect, ...) | Draws a rectangle border |
Render() | Renders the back buffer to console |
Resize(int width, int height) | Resizes the screen buffer |
Widget
Section titled “Widget”The abstract base class for all UI widgets.
| Method | Description |
|---|---|
Add(Widget child) | Adds a child widget |
Remove(Widget child) | Removes a child widget |
Clear() | Removes all children |
Render(Screen screen) | Renders the widget |
| Property | Type | Description |
|---|---|---|
Bounds | Rectangle | Widget bounds |
X, Y, Width, Height | int | Position and size |
Visible | bool | Visibility |
Enabled | bool | Enabled state |
ForegroundColor | Color | Text color |
BackgroundColor | Color | Background color |
ZIndex | int | Rendering order |
Parent | Widget? | Parent widget |
Children | IReadOnlyList<Widget> | Child widgets |
IsFocusable | bool | Can receive focus |
HasFocus | bool | Currently has focus |
Common Patterns
Section titled “Common Patterns”Creating and Running an Application
Section titled “Creating and Running an Application”var app = new Application();var rootWidget = new Frame("My App");app.Run(rootWidget);Adding Widgets
Section titled “Adding Widgets”var container = new Container();var label = new Label("Hello");container.Add(label);Handling Events
Section titled “Handling Events”button.Click += () =>{ Console.WriteLine("Clicked!");};Using Colors
Section titled “Using Colors”// Using ColorHelpervar color = ColorHelper.FromRgb(100, 200, 255);var hexColor = ColorHelper.FromHex("#64C8FF");
// Using System.Drawing.Colorvar white = Color.White;var transparent = Color.Transparent;Enumerations
Section titled “Enumerations”LayoutMode
Section titled “LayoutMode”Absolute- Children maintain manual positionsVertical- Children stacked verticallyHorizontal- Children arranged horizontallyFill- Children fill container
BorderStyle
Section titled “BorderStyle”None- No borderSingle- Single-line borderDouble- Double-line borderRounded- Rounded corners
ButtonStyle
Section titled “ButtonStyle”Standard- Standard buttonRounded- Rounded cornersOutline- Outlined buttonGradient- Gradient background
HorizontalAlignment
Section titled “HorizontalAlignment”Left- Left alignedCenter- Center alignedRight- Right aligned
VerticalAlignment
Section titled “VerticalAlignment”Top- Top alignedMiddle- Middle alignedBottom- Bottom aligned
Helper Classes
Section titled “Helper Classes”ColorHelper
Section titled “ColorHelper”Static utility class for color operations.
| Method | Description |
|---|---|
FromRgb(byte r, byte g, byte b) | Creates color from RGB |
FromRgba(byte r, byte g, byte b, byte a) | Creates color from RGBA |
FromHex(string hex) | Creates color from hex string |
TryFromHex(string hex, Color fallback) | Tries to parse hex color |
Lerp(Color start, Color end, float t) | Linear interpolation |
XML Documentation
Section titled “XML Documentation”Elaris.UI includes comprehensive XML documentation comments. When viewing the code in an IDE, you’ll see detailed documentation for all public members.
Related Topics
Section titled “Related Topics”- Architecture - System architecture
- Base Widget - Widget base class
- Widgets - All widget types