How myraui/myra works
Purpose and Build Entry Points
Myra is a .NET game UI library targeting MonoGame, FNA, Stride, and a platform-agnostic adapter model. Build solution selection is runtime-specific: build/Myra.MonoGame.sln, build/Myra.FNA.Core.sln, build/Myra.Stride.sln, and build/Myra.PlatformAgnostic.sln. The core package variants are src/Myra/Myra.MonoGame.csproj, src/Myra/Myra.FNA.Core.csproj, src/Myra/Myra.Stride.csproj, and src/Myra/Myra.PlatformAgnostic.csproj.
UI Runtime and Widget Tree
The central retained-mode UI model is Widget, arranged under containers and managed by Desktop. Widgets perform layout, rendering, and input participation; containers compose controls into panel, grid, stack, scroll, and split layouts.
• src/Myra/Graphics2D/UI/Widget.cs
• src/Myra/Graphics2D/UI/Desktop.cs
• src/Myra/Graphics2D/UI/Containers/Grid.cs
Input, Events, and Windowing
Host input enters through MyraEnvironment and platform abstractions, is routed by Desktop/InputEventsManager, then delivered to widgets using Myra event types and handling strategies. Desktop-level facilities also own dialogs, windows, focus, and modal/non-modal interaction boundaries.
• src/Myra/MyraEnvironment.Input.cs
• src/Myra/Graphics2D/UI/InputEventsManager.cs
• src/Myra/Events/MyraEventArgs.cs
Rendering and Platform Boundary
Core UI rendering targets abstract IMyraRenderer and IMyraPlatform contracts rather than a single graphics API. RenderContext and texture-atlas primitives provide the shared 2D draw model; engine-specific projects supply graphics/input integration. Platform-agnostic sample adapters demonstrate implementations for MonoGame, OpenTK, Raylib, and Silk.NET.
• src/Myra/Platform/IMyraRenderer.cs
• src/Myra/Platform/IMyraPlatform.cs
• src/Myra/Graphics2D/RenderContext.cs
Assets, Skins, and MML
MML is an XML serialization layer that loads/saves widget trees and property values through contexts, serializers, and attached-property registration. Stylesheets resolve widget visual styles, fonts, and texture regions; default skin assets ship with the library. Asset-manager extension points bridge these resources into supported engines.
• src/Myra/MML/LoadContext.cs
• src/Myra/Graphics2D/UI/Styles/Stylesheet.cs
• src/Myra/MyraAssetManagerExtensions.cs
Tools and Consumer Entry Points
MyraPad is the standalone WYSIWYG MML designer: its executable starts at src/MyraPad/Program.cs, coordinates editor state in src/MyraPad/Studio.cs, and exports generated C# via src/MyraPad/ExporterCS.cs. MyraViewer is a separate MML viewing executable at src/MyraViewer/Program.cs. Samples are integration entry points, especially samples/Myra.Samples.AllWidgets/Program.cs.
Delivery and External Dependencies
The repository is a .NET library/tooling workspace published through GitHub Actions release and beta workflows, with NuGet as the primary distribution service. Material runtime integrations are MonoGame, FNA, and Stride; clipboard support is implemented per OS through the embedded TextCopy-derived layer.
• .github/workflows/build-and-publish-release.yml
• src/Myra/TextCopy/Clipboard.cs
• src/Myra/TextCopy/LinuxClipboard.cs
Main entry points: Widget.cs Widget · Desktop.cs Desktop · LoadContext.cs MML load context · InputEventsManager.cs Input events manager
Components 21
Core UI Runtime
- Widget · Base for layout, rendering, and input participation.
src/Myra/Graphics2D/UI/Widget.cs - Layout containers · Panels, grids, stacks, scroll, and split layouts.
src/Myra/Graphics2D/UI/Containers/Grid.cs - Desktop · Owns the widget tree, windows, dialogs, focus, and modal boundaries.
src/Myra/Graphics2D/UI/Desktop.cs - Myra environment input
src/Myra/MyraEnvironment.Input.cs - Input events manager
src/Myra/Graphics2D/UI/InputEventsManager.cs - Myra event types
src/Myra/Events/MyraEventArgs.cs
Platform Integration
- IMyraRenderer
src/Myra/Platform/IMyraRenderer.cs - IMyraPlatform
src/Myra/Platform/IMyraPlatform.cs - Render context · Shared rendering and texture-atlas primitives.
src/Myra/Graphics2D/RenderContext.cs - Clipboard support · Embedded TextCopy-derived implementation.
src/Myra/TextCopy/Clipboard.cs
Assets and Markup
- MML load context · Loads widget trees and property values.
src/Myra/MML/LoadContext.cs - Stylesheets · Resolves widget styles, fonts, and texture regions.
src/Myra/Graphics2D/UI/Styles/Stylesheet.cs - Asset manager extensions
src/Myra/MyraAssetManagerExtensions.cs
Tools and Consumers
- MyraPad · Standalone designer executable.
src/MyraPad/Program.cs - Studio
src/MyraPad/Studio.cs - C# exporter
src/MyraPad/ExporterCS.cs - MyraViewer
src/MyraViewer/Program.cs - AllWidgets sample
samples/Myra.Samples.AllWidgets/Program.cs
Build and Delivery
- Runtime build solutions · MonoGame, FNA, Stride, and platform-agnostic solution entry points.
- Core package variants · Runtime-specific Myra package projects.
- Release publishing · Publishes library packages to NuGet.
.github/workflows/build-and-publish-release.yml
Connections 22
- Runtime build solutions → Core package variants: selects
- Core package variants → Widget: packages
- Layout containers → Widget: compose
- Desktop → Widget: manages
- Myra environment input → Input events manager: forwards host input
- Input events manager → Desktop: routes through
- Input events manager → Myra event types: uses
- Desktop → Widget: delivers input to
- Widget → Render context: renders with
- Render context → IMyraRenderer: targets
- Myra environment input → IMyraPlatform: uses platform services
- Stylesheets → Widget: styles
- MML load context → Widget: constructs
- MML load context → Stylesheets: loads visual resources
- Asset manager extensions → Stylesheets: bridges assets
- MyraPad → Studio: coordinates
- Studio → MML load context: edits MML
- Studio → C# exporter: exports through
- MyraViewer → MML load context: views
- AllWidgets sample → Desktop: integrates
- Clipboard support → IMyraPlatform: implements OS service
- Release publishing → Core package variants: publishes