Getting started

Install

Install using the following dotnet command:

dotnet add package Apos.Gui --prerelease

Setup

Import the library with:

using Apos.Gui;
using FontStashSharp;

Find a font ttf file, call it font-file.ttf and put it 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(), give your game instance and font to GuiHelper and create an IMGUI object:

protected override void LoadContent() {
    FontSystem fontSystem = FontSystemFactory.Create(GraphicsDevice, 2048, 2048);
    fontSystem.AddFont(TitleContainer.OpenStream($"{Content.RootDirectory}/font-file.ttf"));

    GuiHelper.Setup(this, fontSystem);

    _ui = new IMGUI();
}

IMGUI _ui;

In your update loop, call the following functions:

protected override void Update(GameTime gameTime) {
    // Call UpdateSetup at the start.
    GuiHelper.UpdateSetup(gameTime);
    _ui.UpdateStart(gameTime);

    // Create your UI.
    MenuPanel.Push();
    if (Button.Put("Show fun").Clicked) {
        _showFun = !_showFun;
    }
    if (_showFun) {
        Label.Put("This is fun!");
    }
    if (Button.Put("Quit").Clicked) {
        Exit();
    }
    MenuPanel.Pop();

    // Call UpdateEnd and UpdateCleanup at the end.
    _ui.UpdateEnd(gameTime);
    GuiHelper.UpdateCleanup();

    base.Update(gameTime);
}

bool _showFun = false;

This last code shows a simple menu with two buttons and a conditional label.

Finally, in your draw loop:

protected override void Draw(GameTime gameTime) {
    GraphicsDevice.Clear(Color.Black);

    _ui.Draw(gameTime);

    base.Draw(gameTime);
}

Read more

Check the Design choices to understand the thinking process behind this library.

Edit this page on GitHub