Apos.Gui 0.11.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Apos.Gui --version 0.11.5                
NuGet\Install-Package Apos.Gui -Version 0.11.5                
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.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apos.Gui --version 0.11.5                
#r "nuget: Apos.Gui, 0.11.5"                
#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.5

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

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.1.0 127 10/14/2024
2.0.3 431 2/6/2024
2.0.2 271 2/6/2024
2.0.1 318 1/29/2024
2.0.0 850 4/24/2023
1.0.12 716 4/11/2023
1.0.11 1,142 3/28/2022
1.0.10 1,012 2/7/2022
1.0.9 960 2/4/2022
1.0.8 1,097 1/29/2022
1.0.7 908 1/29/2022
1.0.6-alpha 692 1/28/2022
0.16.2 1,176 11/28/2020
0.16.1 1,057 11/28/2020
0.16.0 1,109 11/28/2020
0.15.0 1,032 10/20/2020
0.14.3 1,041 10/2/2020
0.14.2 1,107 9/6/2020
0.14.1 1,243 5/25/2020
0.14.0 1,037 5/25/2020
0.13.0 1,048 5/25/2020
0.12.2 1,038 3/22/2020
0.12.1 1,190 1/12/2020
0.11.5 1,061 1/12/2020
0.11.4 1,051 1/5/2020
0.11.1 1,064 11/24/2019
0.10.1 1,028 9/25/2019
0.10.0 1,089 9/18/2019
0.9.14 1,113 3/7/2019
0.9.13 1,162 3/5/2019
0.9.12 1,104 3/5/2019
0.9.11 1,136 2/23/2019
0.9.10 1,168 2/21/2019
0.9.8 1,132 2/19/2019
0.9.7 1,184 2/18/2019
0.9.5 1,238 2/6/2019
0.9.1 1,162 2/4/2019
0.9.0 1,171 2/1/2019