-
-
Notifications
You must be signed in to change notification settings - Fork 96
Quick Start Tutorial
Danie edited this page Jun 15, 2020
·
38 revisions
- Create MonoGame/FNA project.
- Reference Myra.
- Add following code to the constructor to make the mouse cursor visible:
IsMouseVisible = true;
- Add following field to the Game class: private Desktop _desktop;
- Add following code in the LoadContent method, which will create 2x2 grid and populate it with some widgets:
MyraEnvironment.Game = this;
var grid = new Grid
{
RowSpacing = 8,
ColumnSpacing = 8
};
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
grid.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
grid.RowsProportions.Add(new Proportion(ProportionType.Auto));
var helloWorld = new Label
{
Id = "label",
Text = "Hello, World!"
};
grid.Widgets.Add(helloWorld);
// ComboBox
var combo = new ComboBox
{
GridColumn = 1,
GridRow = 0
};
combo.Items.Add(new ListItem("Red", Color.Red));
combo.Items.Add(new ListItem("Green", Color.Green));
combo.Items.Add(new ListItem("Blue", Color.Blue));
grid.Widgets.Add(combo);
// Button
var button = new TextButton
{
GridColumn = 0,
GridRow = 1,
Text = "Show"
};
button.Click += (s, a) =>
{
var messageBox = Dialog.CreateMessageBox("Message", "Some message!");
messageBox.ShowModal(_desktop);
};
grid.Widgets.Add(button);
// Spin button
var spinButton = new SpinButton
{
GridColumn = 1,
GridRow = 1,
Width = 100,
Nullable = true
};
grid.Widgets.Add(spinButton);
// Add it to the desktop
_desktop = new Desktop();
_desktop.Root = grid;
- Add following code to the Draw method:
GraphicsDevice.Clear(Color.Black);
_desktop.Render();
It would result in following: