Skip to content

Commit

Permalink
chore: myra ui init
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrynik committed Oct 22, 2023
1 parent 601f47c commit 5b6b629
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Apps/GameDesktop/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using LightInject;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Myra;
using Myra.Graphics2D.UI;
using Serilog;

namespace GameDesktop;
Expand All @@ -19,6 +21,8 @@ public class Game : Microsoft.Xna.Framework.Game
private SpriteBatch _spriteBatch;
private float _accumulatedTime;

private Desktop _desktop;


public Game(ILogger logger, IServiceContainer container, float targetFramesPerSecond)
{
Expand Down Expand Up @@ -59,6 +63,45 @@ protected override void LoadContent()
// todo: pass tru logger & log places
// TODO: Error handling
_rootFeature.Initialize();

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;
_logger.ForContext<Game>().Verbose("LoadContent(): end");
}

Expand Down Expand Up @@ -107,6 +150,7 @@ protected override void Draw(GameTime gameTime)
GraphicsDevice.Clear(Color.CornflowerBlue);

_rootFeature.Draw(gameTime, _spriteBatch);
_desktop.Render();

base.Draw(gameTime);
}
Expand Down
1 change: 1 addition & 0 deletions src/Apps/GameDesktop/GameDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<PackageReference Include="MonoGame.Aseprite" Version="5.1.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
<PackageReference Include="Myra" Version="1.4.5" />
<PackageReference Include="Sentry" Version="3.39.1" />
<PackageReference Include="Sentry.Serilog" Version="3.39.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
Expand Down

0 comments on commit 5b6b629

Please sign in to comment.