Skip to content

Application

realonepiecefreak edited this page Oct 31, 2024 · 15 revisions

This page describes the main entry points for the library to set up the application and its properties.

Application

The Application is the entry point into the execution flow of ImGui.Forms.
There can only be one instance of Application in the lifetime scope of your .NET application.

Usage

  • Simply create a new instance of Application at the start of your .NET application
var application = new Application();

This instance can then be referred to globally by calling the singleton Application.Instance.

  • Execute and render a form
application.Execute(form);

The form executed can be referred to globally by calling the property Application.Instance.MainForm.

  • Close and dispose the entire application, if you want to programmatically close the application on errors or user actions
Application.Instance.Exit();

Form

The abstract class Form is the base for the form the application should render and contains the actual components, layouts, and window information.

By design, there is only ever one form per Application.

Create your own class and derive from Form to execute it with the Application.

class MainForm : Form
{
    public MainForm()
    {
        // Setup form and properties here
    }
}

Properties

  • Id: The unique id of this form
  • Title: The application title, normally shown at the top of the application window
  • Size: The absolute size of the form and the application window
  • Width: The absolute width of the form and the application window; Equivalent to Size.X
  • Height: The absolute height of the form and the application window; Equivalent to Size.Y
  • AllowDragDrop: Allows files to be dropped across the whole form and application window; See event DragDrop to react to this event
  • Icon: The application icon, normally shown at the top (left) of the application window and in the taskbar
  • MenuBar: The main menu bar, normally shown at the top of the application; Usually contains options like "File", "Edit", and "About"; See MenuBar
  • Content: The content of the form to render; Contains an indefinitely nested structure of Components and Layouts
  • Padding: The space between the application window border and Content
  • DefaultFont: The default font used throughout the rendering process, if not otherwise specified; See Fonts for a more thorough explanation of the font management

Events

  • DragDrop: The event to handle application wide drag drop actions; Components on Content handle drag drop actions beforehand and may be ignored here
  • Load: The event called directly after the application window is shown; Can be async
  • Resized: The event called on resizing the application window; Can be async
  • Closing: The event called directly before closing the application window; Allows to cancel the closing operation

Methods

  • HasOpenModals: Determines if any modals are currently open; May be important to control the responsiveness of custom components

Clone this wiki locally