Apos.Gui 0.11.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Apos.Gui --version 0.11.4
NuGet\Install-Package Apos.Gui -Version 0.11.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apos.Gui" Version="0.11.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apos.Gui --version 0.11.4
#r "nuget: Apos.Gui, 0.11.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Apos.Gui as a Cake Addin
#addin nuget:?package=Apos.Gui&version=0.11.4

// Install Apos.Gui as a Cake Tool
#tool nuget:?package=Apos.Gui&version=0.11.4

Apos.Gui

UI library for MonoGame.

Discord

Documentation

Build

NuGet NuGet NuGet

Features

  • Mouse, Keyboard, Gamepad, Touchscreen
  • UI scaling

Showcase

<img src="Images/Showcase.gif" alt="Apos GUI Loop" width="800" height="480" />

Usage samples

First, find a font ttf file to use (Call it FontFile.ttf), put it in a subfolder called "Fonts" in your content folder. Add it to the MonoGame content pipeline and select copy in "Build Action" instead of ~build~.

In your game's LoadContent(), get the Helper classes ready:

protected override void LoadContent() {
    InputHelper.Game = this;
    GuiHelper.Window = Window;
    GuiHelper.Scale = 1f;

    GuiHelper.FontSize = 30;
    using MemoryStream ms = new MemoryStream();
    TitleContainer.OpenStream($"{Content.RootDirectory}/Fonts/FontFile.ttf").CopyTo(ms);
    byte[] fontBytes = ms.ToArray();
    GuiHelper.Font = DynamicSpriteFont.FromTtf(fontBytes, GuiHelper.FontSize);
}

You can create a simple UI with the following code:

ComponentFocus focus;

Action<Component> grabFocus = c => {
    focus.Focus = c;
};

var screen = new ScreenPanel();
screen.Layout = new LayoutVerticalCenter();

var p = new Panel();
p.Layout = new LayoutVerticalCenter();
p.AddHoverCondition(Default.ConditionHoverMouse);
p.AddAction(Default.IsScrolled, Default.ScrollVertically);

p.Add(Default.CreateButton("Fun", c => {
    Console.WriteLine("This is fun.");
    return true;
}, grabFocus));
p.Add(Default.CreateButton("Quit", c => {
    Console.WriteLine("Quitting the game.");
    Exit();
    return true;
}, grabFocus));
screen.Add(p);

focus = new ComponentFocus(screen, Default.ConditionPreviousFocus, Default.ConditionNextFocus);

The above code will create 2 buttons, "Fun" and "Quit". You can use your mouse, keyboard, or gamepad to interact with them.

In your Update(GameTime gameTime), call the following functions:

protected override void Update(GameTime gametime) {
    //Call UpdateSetup at the start.
    InputHelper.UpdateSetup();
    GuiHelper.UpdateSetup();

    focus.UpdateSetup();
    focus.UpdateInput();
    focus.Update();

    //Call UpdateCleanup at the end.
    InputHelper.UpdateCleanup();
}

In your Draw(GameTime gameTime), call:

protected override void Draw(GameTime gameTime) {
    GraphicsDevice.Clear(Color.Black);
    focus.Draw(spritebatch);
    base.Draw(gameTime);
}

Working usage code can be found in the AposGameStarter project. Look into menu.cs.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 317 2/6/2024
2.0.2 230 2/6/2024
2.0.1 287 1/29/2024
2.0.0 818 4/24/2023
1.0.12 686 4/11/2023
1.0.11 1,109 3/28/2022
1.0.10 983 2/7/2022
1.0.9 914 2/4/2022
1.0.8 1,043 1/29/2022
1.0.7 882 1/29/2022
1.0.6-alpha 665 1/28/2022
0.16.2 1,145 11/28/2020
0.16.1 1,029 11/28/2020
0.16.0 1,081 11/28/2020
0.15.0 989 10/20/2020
0.14.3 1,014 10/2/2020
0.14.2 1,076 9/6/2020
0.14.1 1,205 5/25/2020
0.14.0 1,007 5/25/2020
0.13.0 1,018 5/25/2020
0.12.2 989 3/22/2020
0.12.1 1,163 1/12/2020
0.11.5 1,035 1/12/2020
0.11.4 1,025 1/5/2020
0.11.1 1,038 11/24/2019
0.10.1 999 9/25/2019
0.10.0 1,061 9/18/2019
0.9.14 1,086 3/7/2019
0.9.13 1,121 3/5/2019
0.9.12 1,071 3/5/2019
0.9.11 1,111 2/23/2019
0.9.10 1,143 2/21/2019
0.9.8 1,108 2/19/2019
0.9.7 1,159 2/18/2019
0.9.5 1,211 2/6/2019
0.9.1 1,136 2/4/2019
0.9.0 1,147 2/1/2019