|
| 1 | +MyraPad is WYSIWYG [[MML]] based UI designer. |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +It is included in the Myra binary distribution, which is Myra.v.v.v.v.zip from the latest release at https://github.com/rds1983/Myra/releases. |
| 6 | + |
| 7 | +Following video demonstrates creation of simple main menu project in MyraPad: |
| 8 | +https://youtu.be/NZUCq2RMgZU |
| 9 | + |
| 10 | +It creates UI with the following [[MML]]: |
| 11 | +```xml |
| 12 | +<Project> |
| 13 | + <Panel> |
| 14 | + <TextBlock Text="My Awesome Game" TextColor="#FFA500FF" HorizontalAlignment="Center" /> |
| 15 | + <VerticalMenu HorizontalAlignment="Center" VerticalAlignment="Center" > |
| 16 | + <MenuItem Id="_menuStartNewGame" Text="Start New Game" /> |
| 17 | + <MenuItem Id="_menuOptions" Text="Options" /> |
| 18 | + <MenuItem Id="_menuQuit" Text="Quit" /> |
| 19 | + </VerticalMenu> |
| 20 | + </Panel> |
| 21 | +</Project> |
| 22 | +``` |
| 23 | + **Note**. MyraPad itself is made with Myra. |
| 24 | + |
| 25 | +# Export To C# |
| 26 | +MyraPad can export projects to C#: |
| 27 | +https://youtu.be/94bPYKw4cAI |
| 28 | + |
| 29 | + **Note**. Notice that export setting had been saved in the project in the newly appeared tag <ExportOptions>. Thus it wouldn't be required to enter it again. |
| 30 | + |
| 31 | +That procedure created two files: MainMenu.cs and MenuMenu.Generated.cs. Now if export would be rerun, only MainMenu.Generated.cs would be rewritten. So it is safe to add any user code to MainMenu.cs |
| 32 | + |
| 33 | +Let's take a look at contents of produced files. |
| 34 | + |
| 35 | +MainMenu.cs: |
| 36 | +```c# |
| 37 | +/* Generated by MyraPad at 27.07.2019 13:00:34 */ |
| 38 | +using Myra.Graphics2D.UI; |
| 39 | + |
| 40 | +namespace MyraPadTest.UI |
| 41 | +{ |
| 42 | + public partial class MainMenu: Panel |
| 43 | + { |
| 44 | + public MainMenu() |
| 45 | + { |
| 46 | + BuildUI(); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +MainMenu.Generated.cs |
| 53 | +```c# |
| 54 | +/* Generated by MyraPad at 27.07.2019 13:49:27 */ |
| 55 | +using Microsoft.Xna.Framework; |
| 56 | +using Myra.Graphics2D.UI; |
| 57 | + |
| 58 | +namespace MyraPadTest.UI |
| 59 | +{ |
| 60 | + partial class MainMenu |
| 61 | + { |
| 62 | + private void BuildUI() |
| 63 | + { |
| 64 | + var textBlock1 = new TextBlock(); |
| 65 | + textBlock1.Text = "My Game"; |
| 66 | + textBlock1.TextColor = Color.Orange; |
| 67 | + textBlock1.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; |
| 68 | + |
| 69 | + _menuStartNewGame = new MenuItem(); |
| 70 | + _menuStartNewGame.Id = "_menuStartNewGame"; |
| 71 | + _menuStartNewGame.Text = "Start New Game"; |
| 72 | + |
| 73 | + _menuOptions = new MenuItem(); |
| 74 | + _menuOptions.Id = "_menuOptions"; |
| 75 | + _menuOptions.Text = "Options"; |
| 76 | + |
| 77 | + _menuQuit = new MenuItem(); |
| 78 | + _menuQuit.Id = "_menuQuit"; |
| 79 | + _menuQuit.Text = "Quit"; |
| 80 | + |
| 81 | + var verticalMenu1 = new VerticalMenu(); |
| 82 | + verticalMenu1.HorizontalAlignment = Myra.Graphics2D.UI.HorizontalAlignment.Center; |
| 83 | + verticalMenu1.VerticalAlignment = Myra.Graphics2D.UI.VerticalAlignment.Center; |
| 84 | + verticalMenu1.Items.Add(_menuStartNewGame); |
| 85 | + verticalMenu1.Items.Add(_menuOptions); |
| 86 | + verticalMenu1.Items.Add(_menuQuit); |
| 87 | + |
| 88 | + |
| 89 | + Widgets.Add(textBlock1); |
| 90 | + Widgets.Add(verticalMenu1); |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + public MenuItem _menuStartNewGame; |
| 95 | + public MenuItem _menuOptions; |
| 96 | + public MenuItem _menuQuit; |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +Notice that tags with id(all **MenuItem**) had been exported as class fields. Thus it's possible to work with it from code. |
| 102 | +I.e. if we update the MainMenu constructor with the following code: |
| 103 | +```c# |
| 104 | +public MainMenu() |
| 105 | +{ |
| 106 | + BuildUI(); |
| 107 | + _menuQuit.Selected += (s, a) => { Exit(); }; |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +Then the app would quit when 'Quit' menu item is clicked. |
0 commit comments