undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoStudio::ui::ImGuiManager Class Reference

Manager class for Dear ImGui integration. More...

#include <ImGuiManager.hpp>

Collaboration diagram for undoStudio::ui::ImGuiManager:
Collaboration graph

Classes

struct  Panel
 Panel structure. More...
 

Public Types

using PanelRenderFunc = std::function< void()>
 Panel rendering function type.
 

Public Member Functions

bool initialize (void *window)
 Initialize ImGui with the given window.
 
void shutdown ()
 Shutdown ImGui and release resources.
 
void newFrame ()
 Begin a new ImGui frame.
 
void render ()
 Render all registered panels.
 
void endFrame ()
 End the ImGui frame.
 
void reportDisplayIfChanged ()
 Write the display geometry to the log whenever it changes.
 
void addPanel (const std::string &name, PanelRenderFunc renderFunc)
 Add a panel to the UI.
 
void removePanel (const std::string &name)
 Remove a panel from the UI.
 
void showPanel (const std::string &name, bool show=true)
 Show or hide a panel.
 
bool isPanelVisible (const std::string &name) const
 Check if a panel is visible.
 
void setUndoRTTheme ()
 Set the UI theme to match undoRT website colors.
 
void setDarkTheme ()
 Set the UI theme to dark mode.
 
void setLightTheme ()
 Set the UI theme to light mode.
 
void setCustomTheme (const std::string &themePath)
 Load a custom theme from file.
 
bool loadFont (const std::string &path, float size, const std::string &name="default")
 Load a font for the UI.
 
void enableDocking (bool enable=true)
 Enable or disable window docking.
 
void resetLayout ()
 Reset the docking layout to default.
 
void saveLayout (const std::string &filename="undoStudio_layout.ini")
 Save the current layout to file.
 
void loadLayout (const std::string &filename="undoStudio_layout.ini")
 Load a layout from file.
 
void openRecentProjects ()
 Ask for the recent projects list to be shown on the next frame.
 
void renderRecentProjects ()
 Draw the recent projects list, and set a request when one is picked.
 
void openRecentFiles ()
 Ask for the recent files list to be shown on the next frame.
 
void renderRecentFiles ()
 Draw the recent files list, and ask for the picked one to be opened.
 
const std::string * consumeOpenProjectRequest (std::string &projectPath)
 Take the project a menu asked to open, if one was asked for.
 
void requestOpenProject (const std::string &projectPath)
 Ask for a project to be opened.
 
void requestOpenFile (const std::string &filePath)
 Ask for a file to be opened in the editor.
 
const std::string * consumeOpenFileRequest (std::string &filePath)
 Take the next file that was asked to be opened.
 
void adoptShippedLayout ()
 Copy the layout shipped in resources/ into place when there is none.
 
ImGuiIO & getIO ()
 Get the ImGui IO structure.
 

Static Public Member Functions

static ImGuiManager & getInstance ()
 Get the singleton instance.
 

Static Public Attributes

static constexpr const char * kRecentProjectsPopup = "##recentProjects"
 Name of the recent projects popup, shared by the ask and the draw.
 
static constexpr const char * kRecentFilesPopup = "##recentFiles"
 Name of the recent files popup, shared by the ask and the draw.
 

Private Member Functions

 ImGuiManager ()=default
 
 ~ImGuiManager ()=default
 
 ImGuiManager (const ImGuiManager &)=delete
 
ImGuiManager & operator= (const ImGuiManager &)=delete
 
void renderDockingLayout ()
 Render the docking layout.
 
void renderMenuBar ()
 Render the main menu bar.
 
void createDefaultLayout ()
 Create the default docking layout.
 
ImTextureID loadImageTexture (const std::string &path)
 Load an image as an OpenGL texture for ImGui.
 

Private Attributes

std::vector< Panel > m_panels
 
bool m_dockingEnabled = true
 
bool m_layoutInitialized = false
 
bool m_layoutResetRequested = false
 
ImGuiID m_dockspaceID = 0
 
std::string m_iniFilename = "undoStudio_layout.ini"
 Persistent storage for ImGuiIO::IniFilename.
 
ImTextureID m_logoTexture = 0
 
bool m_showAboutPopup = false
 True once Help > About undoStudio was asked for.
 
bool m_showRecentsPopup = false
 True while the recent projects list is open.
 
std::string m_pendingOpenProject
 
bool m_showRecentFilesPopup = false
 True while the recent files list is open, and cleared with it.
 
std::deque< std::string > m_pendingOpenFiles
 Files asked to be opened, oldest first, by the command line or by a drop.
 
std::string m_lastDisplayReport
 The last display geometry written to the log, so only a change is written.
 

Detailed Description

Manager class for Dear ImGui integration.

ImGuiManager provides a high-level interface for managing the ImGui-based user interface. It handles panel registration, docking, theming, and font management.

Member Typedef Documentation

◆ PanelRenderFunc

using undoStudio::ui::ImGuiManager::PanelRenderFunc = std::function<void()>

Panel rendering function type.

This function type defines the signature for panel rendering functions. Each panel provides its own rendering logic.

Constructor & Destructor Documentation

◆ ImGuiManager() [1/2]

undoStudio::ui::ImGuiManager::ImGuiManager ( )
privatedefault

◆ ~ImGuiManager()

undoStudio::ui::ImGuiManager::~ImGuiManager ( )
privatedefault

◆ ImGuiManager() [2/2]

undoStudio::ui::ImGuiManager::ImGuiManager ( const ImGuiManager &  )
privatedelete

Member Function Documentation

◆ addPanel()

void undoStudio::ui::ImGuiManager::addPanel ( const std::string &  name,
PanelRenderFunc  renderFunc 
)

Add a panel to the UI.

Parameters
nameUnique panel name
renderFuncFunction that renders the panel content

◆ adoptShippedLayout()

void undoStudio::ui::ImGuiManager::adoptShippedLayout ( )

Copy the layout shipped in resources/ into place when there is none.

Copy the layout shipped with the project into place, if there is none yet.

A fresh install opens on the arrangement the project ships rather than on the one createDefaultLayout() builds, so the two cannot drift apart.

The arrangement the project opens with is a file in resources/, not a builder call: it is the one the dock layout is saved from, so what a new user gets is what the project settled on rather than a second description of it that can drift away from the first.

◆ consumeOpenFileRequest()

const std::string * undoStudio::ui::ImGuiManager::consumeOpenFileRequest ( std::string &  filePath)

Take the next file that was asked to be opened.

Parameters
filePathSet to the path, valid until the next call
Returns
The path, or nullptr when nothing was asked for

◆ consumeOpenProjectRequest()

const std::string * undoStudio::ui::ImGuiManager::consumeOpenProjectRequest ( std::string &  projectPath)

Take the project a menu asked to open, if one was asked for.

The menu bar is the core and the workspace that opens a project belongs to an undoApp, so the request crosses as a flag rather than as a call: one click leaves it, and the undoApp that owns the tree takes it on its next frame. The same shape the add-METHOD dialog uses.

Parameters
projectPathSet when a project is wanted
Returns
The path, or nullptr when nothing was asked for

◆ createDefaultLayout()

void undoStudio::ui::ImGuiManager::createDefaultLayout ( )
private

Create the default docking layout.

◆ enableDocking()

void undoStudio::ui::ImGuiManager::enableDocking ( bool  enable = true)

Enable or disable window docking.

Parameters
enabletrue to enable docking, false to disable

◆ endFrame()

void undoStudio::ui::ImGuiManager::endFrame ( )

End the ImGui frame.

This method finalizes the frame and renders the ImGui draw data.

◆ getInstance()

ImGuiManager & undoStudio::ui::ImGuiManager::getInstance ( )
static

Get the singleton instance.

Returns
Reference to the single ImGuiManager instance

◆ getIO()

ImGuiIO & undoStudio::ui::ImGuiManager::getIO ( )

Get the ImGui IO structure.

Returns
Reference to ImGuiIO

◆ initialize()

bool undoStudio::ui::ImGuiManager::initialize ( void *  window)

Initialize ImGui with the given window.

Parameters
windowNative window handle
Returns
true on success, false on failure

◆ isPanelVisible()

bool undoStudio::ui::ImGuiManager::isPanelVisible ( const std::string &  name) const

Check if a panel is visible.

Parameters
nameName of the panel
Returns
true if visible, false otherwise

◆ loadFont()

bool undoStudio::ui::ImGuiManager::loadFont ( const std::string &  path,
float  size,
const std::string &  name = "default" 
)

Load a font for the UI.

Parameters
pathPath to the font file (.ttf)
sizeFont size in pixels
nameOptional name for the font
Returns
true on success, false on failure

◆ loadImageTexture()

ImTextureID undoStudio::ui::ImGuiManager::loadImageTexture ( const std::string &  path)
private

Load an image as an OpenGL texture for ImGui.

Parameters
pathPath to the image file (PNG recommended)
Returns
ImTextureID (GLuint) or 0 if failed

◆ loadLayout()

void undoStudio::ui::ImGuiManager::loadLayout ( const std::string &  filename = "undoStudio_layout.ini")

Load a layout from file.

Parameters
filenamePath to the layout file

◆ newFrame()

void undoStudio::ui::ImGuiManager::newFrame ( )

Begin a new ImGui frame.

This method should be called at the beginning of each frame before any UI rendering.

◆ openRecentFiles()

void undoStudio::ui::ImGuiManager::openRecentFiles ( )

Ask for the recent files list to be shown on the next frame.

◆ openRecentProjects()

void undoStudio::ui::ImGuiManager::openRecentProjects ( )

Ask for the recent projects list to be shown on the next frame.

◆ operator=()

ImGuiManager & undoStudio::ui::ImGuiManager::operator= ( const ImGuiManager &  )
privatedelete

◆ removePanel()

void undoStudio::ui::ImGuiManager::removePanel ( const std::string &  name)

Remove a panel from the UI.

Parameters
nameName of the panel to remove

◆ render()

void undoStudio::ui::ImGuiManager::render ( )

Render all registered panels.

This method renders all panels that have been registered with the manager.

◆ renderDockingLayout()

void undoStudio::ui::ImGuiManager::renderDockingLayout ( )
private

Render the docking layout.

This method renders the main docking space and manages the layout of docked panels.

◆ renderMenuBar()

void undoStudio::ui::ImGuiManager::renderMenuBar ( )
private

Render the main menu bar.

◆ renderRecentFiles()

void undoStudio::ui::ImGuiManager::renderRecentFiles ( )

Draw the recent files list, and ask for the picked one to be opened.

The pick goes through requestOpenFile rather than opening anything here, for the same reason the project list does not open a project: the editor that shows a file belongs to an undoApp, and the core asks rather than calls.

◆ renderRecentProjects()

void undoStudio::ui::ImGuiManager::renderRecentProjects ( )

Draw the recent projects list, and set a request when one is picked.

◆ reportDisplayIfChanged()

void undoStudio::ui::ImGuiManager::reportDisplayIfChanged ( )

Write the display geometry to the log whenever it changes.

One line for the window, one per monitor and one per platform viewport, and nothing at all while none of them moves. A popup is a platform viewport of its own, and a mixed-DPI setup is invisible from here: the numbers that decide whether a popup is drawn once or redrawn every frame are the scale of the monitor the window is on and the scale ImGui gives the viewport, and both are only visible at run time.

A viewport that is created and destroyed every frame is what a log full of lines means, so the identifier is in the report: the same popup appearing under a new id on the next line is a popup being rebuilt, and one line per frame is the reading to take from it.

◆ requestOpenFile()

void undoStudio::ui::ImGuiManager::requestOpenFile ( const std::string &  filePath)

Ask for a file to be opened in the editor.

Where a path handed to the IDE on the command line, or dropped onto the window, is left until an undoApp takes it. Both of those arrive here and both are the core, while the editor that opens them belongs to an undoApp, so the request crosses the same way the recent-projects one does.

A file handed over while another is already open replaces it, which is what opening a file means everywhere else; the queue below holds one because a drop can carry several and they are opened in the order they were given, leaving the last one as the one on screen.

Parameters
filePathThe file to open, as the user wrote it

◆ requestOpenProject()

void undoStudio::ui::ImGuiManager::requestOpenProject ( const std::string &  projectPath)

Ask for a project to be opened.

The counterpart of requestOpenFile, and the same crossing: the recent list and the keyboard shortcut already reach the Workspace this way, and a project named on the command line or dropped as a folder belongs with them.

Parameters
projectPathThe project directory, or its .undoProject folder

◆ resetLayout()

void undoStudio::ui::ImGuiManager::resetLayout ( )

Reset the docking layout to default.

◆ saveLayout()

void undoStudio::ui::ImGuiManager::saveLayout ( const std::string &  filename = "undoStudio_layout.ini")

Save the current layout to file.

Parameters
filenamePath to the layout file

◆ setCustomTheme()

void undoStudio::ui::ImGuiManager::setCustomTheme ( const std::string &  themePath)

Load a custom theme from file.

Parameters
themePathPath to the theme file

◆ setDarkTheme()

void undoStudio::ui::ImGuiManager::setDarkTheme ( )

Set the UI theme to dark mode.

◆ setLightTheme()

void undoStudio::ui::ImGuiManager::setLightTheme ( )

Set the UI theme to light mode.

◆ setUndoRTTheme()

void undoStudio::ui::ImGuiManager::setUndoRTTheme ( )

Set the UI theme to match undoRT website colors.

◆ showPanel()

void undoStudio::ui::ImGuiManager::showPanel ( const std::string &  name,
bool  show = true 
)

Show or hide a panel.

Parameters
nameName of the panel
showtrue to show, false to hide

◆ shutdown()

void undoStudio::ui::ImGuiManager::shutdown ( )

Shutdown ImGui and release resources.

Member Data Documentation

◆ kRecentFilesPopup

constexpr const char* undoStudio::ui::ImGuiManager::kRecentFilesPopup = "##recentFiles"
staticconstexpr

Name of the recent files popup, shared by the ask and the draw.

◆ kRecentProjectsPopup

constexpr const char* undoStudio::ui::ImGuiManager::kRecentProjectsPopup = "##recentProjects"
staticconstexpr

Name of the recent projects popup, shared by the ask and the draw.

◆ m_dockingEnabled

bool undoStudio::ui::ImGuiManager::m_dockingEnabled = true
private

◆ m_dockspaceID

ImGuiID undoStudio::ui::ImGuiManager::m_dockspaceID = 0
private

◆ m_iniFilename

std::string undoStudio::ui::ImGuiManager::m_iniFilename = "undoStudio_layout.ini"
private

Persistent storage for ImGuiIO::IniFilename.

◆ m_lastDisplayReport

std::string undoStudio::ui::ImGuiManager::m_lastDisplayReport
private

The last display geometry written to the log, so only a change is written.

◆ m_layoutInitialized

bool undoStudio::ui::ImGuiManager::m_layoutInitialized = false
private

◆ m_layoutResetRequested

bool undoStudio::ui::ImGuiManager::m_layoutResetRequested = false
private

◆ m_logoTexture

ImTextureID undoStudio::ui::ImGuiManager::m_logoTexture = 0
private

◆ m_panels

std::vector<Panel> undoStudio::ui::ImGuiManager::m_panels
private

◆ m_pendingOpenFiles

std::deque<std::string> undoStudio::ui::ImGuiManager::m_pendingOpenFiles
private

Files asked to be opened, oldest first, by the command line or by a drop.

◆ m_pendingOpenProject

std::string undoStudio::ui::ImGuiManager::m_pendingOpenProject
private

Set by the menu, taken by the undoApp

◆ m_showAboutPopup

bool undoStudio::ui::ImGuiManager::m_showAboutPopup = false
private

True once Help > About undoStudio was asked for.

◆ m_showRecentFilesPopup

bool undoStudio::ui::ImGuiManager::m_showRecentFilesPopup = false
private

True while the recent files list is open, and cleared with it.

◆ m_showRecentsPopup

bool undoStudio::ui::ImGuiManager::m_showRecentsPopup = false
private

True while the recent projects list is open.


The documentation for this class was generated from the following files: