Gum UI Documentation

repository·main·Indexed 20 days ago

https://github.com/vchelaru/gum

A general-purpose, object-oriented UI layout tool that exports to human-readable XML and supports various C# environments and graphics runtimes including MonoGame, KNI, SkiaSharp, raylib, and Silk.NET. The suite includes a WYSIWYG editor (Gum Tool), platform-agnostic runtimes, a layout engine, and the GumCli command-line tool for project management, validation, and C# code generation. It implements the MVVM pattern for data binding and provides Python bindings via the gumui package.

Tokens
351.1K
Snippets
800
Records
1.6K
Agent score
67%

What's inside Gum

  1. Overview of Code-Only Styling in Gum

    main

    In a code-only Gum project, you can style UI controls using several different approaches depending on whether you want to apply styles globally, to specific instances, or based on user interaction.

    Available styling strategies include:

    • Global Styling: Using ActiveStyles to provide default styles for all Gum UI elements.
    • Per-Control Styling: Modifying style values directly on individual control instances.
    • State-Based Styling: Specifying styles that trigger in response to user actions like hover or push.
    • Visual Customization: Adding or removing visual children to change a control's appearance.
    • Complex Control Customization: Specialized styling for composite controls like ListBox, ComboBox, Menu, and MenuItem.
  2. What is Gum?

    main

    Gum is a UI solution platform designed for C# game developers. It provides a platform-agnostic layout and control core, runtime libraries for various frameworks, and a WYSIWYG editor (the Gum tool) for visual UI authoring.

    Core Components:

    • Layout and Control Core: A platform-agnostic foundation for UI elements.
    • Runtime Libraries: Support for MonoGame, KNI, FNA, SkiaSharp, and raylib.
    • Gum Tool: A WYSIWYG editor used to author UI visually.
  3. Overview of SokolGum backend

    main

    SokolGum is an experimental Gum backend that targets Sokol.NET. It renders UI using sokol_gp (2D primitives, scissor, and blend) and integrates text rendering via fontstash callbacks into the same sgp command stream. This ensures that text respects Z-order, scissor clipping, and blend modes in the same way as sprites and rectangles.

    Note: This backend is experimental and does not currently support Input (mouse/keyboard/touch), Forms controls (Buttons, Sliders, etc.), or Data binding.

  4. Overview of Gum core features

    main

    Gum is a general-purpose UI layout tool built on object-oriented principles. It is designed to be flexible and extensible. Key features include:

    • Inheritance: Support for object-oriented UI hierarchies.
    • Object Instances: Working with specific instances of UI elements.
    • Variables: Support for default and overriding variables.
    • States: Categorized and uncategorized UI states.
    • Layout Engine: A highly flexible engine for positioning and sizing.
    • XML Export: Exports to human-readable XML.
    • Extensibility: Can be extended using MEF or by modifying the source code directly.
  5. Overview of Gum UI

    main

    Gum is a Game UI Layout tool and engine designed for creating flexible and efficient UI layouts. It features a WYSIWYG editor for designing layouts and an object-oriented design that focuses on reusable components.

    Key capabilities include:

    • Reusable Components: Create components that can be instanced and customized within screens or other components.
    • Fluid Layouts: Support for multiple size and position units, allowing for adjustable origins, position units, size units, and stacking.
    • Runtime Agnostic: The layout engine can be included in any .NET project without requiring a specific graphical API. It can be rendered via Skia (for WPF, Avalonia, etc.) or integrated directly into game engines like MonoGame, KNI, FNA, raylib, and Silk.NET.
  6. Overview of KernSmith.GumCommon

    main

    KernSmith.GumCommon is a shared integration layer designed to bridge KernSmith bitmap font generation with Gum's BmfcSave font descriptor. It acts as a mapping layer that translates Gum's font configurations into KernSmith's FontGeneratorOptions, driving the font generation pipeline.

    This package is intended to be used as a foundation for platform-specific Gum integration packages, such as:

    • KernSmith.MonoGameGum
    • KernSmith.FnaGum
    • KernSmith.KniGum

    By using this common package, platform-specific implementations only need to manage framework-specific concerns (like texture creation) while the core font generation logic is handled by KernSmith.GumCommon.

  7. Overview of Font Loading Strategies in Gum

    main

    Gum provides several strategies for loading and rendering fonts, depending on your target runtime and whether you want to manage font files manually or dynamically.

    Available Strategies

    • Dynamic KernSmith Generation: Recommended for MonoGame, KNI, and Raylib. It generates font atlases in memory at runtime using the KernSmith library.
    • Dynamic Generation on SkiaGum: Used by SkiaGum and Silk.NET. These runtimes use SkiaSharp to rasterize glyphs directly without needing KernSmith.
    • Custom Font File: Loading a specific .fnt file shipped with your game.
    • Direct BitmapFont Assignment: A fully manual approach.
    • Build-Time Font Cache: Pre-baked atlases created using the Gum tool (recommended for Sokol or FNA where dynamic generation is not yet available).

    Runtime Availability Matrix

    RuntimeDynamic Generation Support
    MonoGameYes (via KernSmith)
    KNIYes (via KernSmith)
    RaylibYes (via KernSmith.RaylibGum)
    FNANo (Use Build-Time Font Cache)
    SokolNo (Use Build-Time Font Cache)
    SkiaGumYes (via SkiaSharp)
    Silk.NETYes (via SkiaGum/SkiaSharp)
  8. Overview of KernSmith.KniGum

    main

    KernSmith.KniGum provides runtime bitmap font generation for KNI (Kni is Not XNA) projects that utilize the Gum UI framework.

    Key characteristics:

    • In-Memory Generation: Generates BitmapFont instances entirely in memory. No disk I/O is required.
    • Runtime Workflow: Fonts are rasterized, packed, and loaded into GPU textures at runtime.
    • Framework Compatibility: Adapted for the KNI framework (nkast.Xna.Framework) and Gum.KNI dependencies.
    • Target Framework: net8.0.
    • Dependencies: Depends on the KernSmith bitmap-font rasterizer.
  9. Overview of the Gum technologies

    main

    Gum is a suite of technologies designed for creating game user interfaces (UI). It consists of three primary components:

    1. Gum Tool: A WYSIWYG (What You See Is What You Get) editor for designing interactive UIs and HUDs.
    2. Gum Runtimes: Libraries that allow you to load Gum projects or create code-only UIs across various game platforms.
    3. Gum Layout Engine: A platform-agnostic .NET NuGet package that handles UI layout and can be used independently of the standard runtimes.
  10. Understand Gum's ecosystem and integrations

    main

    Gum is integrated with several specialized libraries to provide extended capabilities within its ecosystem. Users can leverage these partnerships for specific tasks:

    • Shape Rendering: Use Apos.Shapes.
    • Shader Compilation: Use ShadowDusk.
    • Dynamic Font Creation: Use KernSmith.

    Additionally, Gum is officially featured in MonoGame documentation and is used in the Ascent 3D sample project. For browser-based experimentation, you can use the XnaFiddle.net playground.

  11. Explore Gum Code and Layout Concepts

    main

    The Gum documentation is organized into several key areas to help you build UIs in code:

    • About Gum in Code: Understand the core layout overview and how Gum integrates with different frameworks (e.g., WPF).
    • Getting Started: Guides for setting up empty projects in various engines (Meadow, MonoGame, .NET MAUI, Pygame, raylib, Silk.NET, WPF) and initializing Gum.
    • Controls: Detailed documentation for UI components like Button, CheckBox, Grid, StackPanel, TextBox, and more.
    • Layout: Concepts for positioning elements using Anchor, Dock, Stacking, and Grid systems.
    • Styling: Instructions for both code-only styling (using ActiveStyles or States) and using the Gum Tool.
    • Events and Interactivity: How to handle mouse, touch, keyboard, and gamepad input, as well as event bubbling and focus management.
    • Binding and MVVM: Tutorials and deep dives into binding visual properties to ViewModels.
  12. Use the ListBox control

    main

    The ListBox control provides a scrollable list of items for displaying and selecting from a list. It inherits from ScrollViewer, meaning it supports properties like MouseWheelScrollSpeed to control scrolling behavior.

    To use a ListBox, add it to the root or a parent container and populate its Items property.

    // Initialize
    var listBox = new ListBox();
    listBox.AddToRoot();
    listBox.X = 50;
    listBox.Y = 50;
    listBox.Width = 400;
    listBox.Height = 200;