MyraUIGenerator 1.0.10
dotnet add package MyraUIGenerator --version 1.0.10
NuGet\Install-Package MyraUIGenerator -Version 1.0.10
<PackageReference Include="MyraUIGenerator" Version="1.0.10"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="MyraUIGenerator" Version="1.0.10" />
<PackageReference Include="MyraUIGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add MyraUIGenerator --version 1.0.10
#r "nuget: MyraUIGenerator, 1.0.10"
#:package MyraUIGenerator@1.0.10
#addin nuget:?package=MyraUIGenerator&version=1.0.10
#tool nuget:?package=MyraUIGenerator&version=1.0.10
Myra UI Generator
A source generator for Myra UI XML files that automatically creates strongly-typed C# accessor classes.
Features
- 🔧 Automatic Code Generation: Scans Myra XML files and generates strongly-typed C# classes
- 🎯 Type Safety: Compile-time access to UI widgets with IntelliSense support
- ⚙️ Configurable: Customize namespace and XML directory paths
- 🚀 Zero Runtime Overhead: Pure compile-time code generation
- 📦 NuGet Package: Easy to add to any MonoGame + Myra project
Installation
dotnet add package MyraUIGenerator
Or add to your .csproj:
<ItemGroup>
<PackageReference Include="MyraUIGenerator" Version="1.0.0" />
</ItemGroup>
Usage
1. Add XML Files to AdditionalFiles
In your .csproj, include your Myra XML files:
<ItemGroup>
<AdditionalFiles Include="Content/UI/*.xml" />
</ItemGroup>
2. Configure (Optional)
Create or update .editorconfig in your project root:
[*.cs]
# Namespace for generated UI classes
myra_ui_generator.namespace = YourNamespace.UI.Generated
# Directory where XML files are located (relative to project root)
myra_ui_generator.xml_directory = Content/UI
If not configured, defaults are:
- Namespace:
GeneratedUI - Directory:
Content/UI
3. Use Generated Classes
For a file named TitleScreen.xml:
using YourNamespace.UI.Generated;
using Myra.Graphics2D.UI;
// Load the UI
var project = UiLoader.Load("TitleScreen.xml");
// Create and initialize the generated class
var ui = new TitleScreenUI();
ui.Initialize(project.Root);
// Use strongly-typed access
ui.StartButton.Click += OnStartClicked;
ui.TitleLabel.Text = "Welcome!";
ui.SettingsButton.IsEnabled = true;
Generated Code
For TitleScreen.xml with widgets:
Id="StartButton"(Button)Id="TitleLabel"(Label)Id="SettingsButton"(Button)
The generator creates TitleScreenUI.g.cs:
namespace YourNamespace.UI.Generated;
public partial class TitleScreenUI
{
public Button StartButton { get; private set; }
public Label TitleLabel { get; private set; }
public Button SettingsButton { get; private set; }
public void Initialize(Widget root)
{
StartButton = root.FindChildById("StartButton") as Button;
TitleLabel = root.FindChildById("TitleLabel") as Label;
SettingsButton = root.FindChildById("SettingsButton") as Button;
}
}
Supported Widget Types
The generator recognizes these Myra XML elements:
Label→LabelButton→ButtonCheckBox→CheckBoxTextBox→TextBoxPanel→PanelVerticalStackPanel→VerticalStackPanelHorizontalStackPanel→HorizontalStackPanelGrid→GridScrollViewer→ScrollViewerSlider→SliderProgressBar→ProgressBarListBox→ListBoxComboBox→ComboBoxImage→ImageTextBlock→TextBlock- Unknown types →
Widget(fallback)
Property Names
Property names in the generated classes match the Id attribute values from your XML files exactly. For example:
- Widget with
Id="StartButton"→ Property namedStartButton - Widget with
Id="TitleLabel"→ Property namedTitleLabel - Widget with
Id="HealthBar"→ Property namedHealthBar
Requirements
- .NET Standard 2.0 or later
- Myra UI library
- MonoGame (or compatible framework)
Documentation
📚 Complete documentation is available in the GitHub Wiki
The wiki includes:
- Getting started guides
- Configuration options
- Usage examples and patterns
- API reference
- Troubleshooting guide
- Contributing guidelines
Wiki documentation is automatically synced from the wiki/ directory in this repository.
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please open an issue or pull request on GitHub.
Changelog
1.0.0
- Initial release
- Configurable namespace and directory
- Support for common Myra widget types
- Property names match XML
Idattributes exactly
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.