-
Notifications
You must be signed in to change notification settings - Fork 88
/
hello_imgui.h
185 lines (134 loc) · 6.21 KB
/
hello_imgui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#if defined(__ANDROID__) && defined(HELLOIMGUI_USE_SDL2)
// We need to include SDL, so that it can instantiate its main function under Android
#include "SDL.h"
#endif
#include "hello_imgui/dpi_aware.h"
#include "hello_imgui/hello_imgui_assets.h"
#include "hello_imgui/hello_imgui_error.h"
#include "hello_imgui/hello_imgui_logger.h"
#include "hello_imgui/image_from_asset.h"
#include "hello_imgui/imgui_theme.h"
#include "hello_imgui/hello_imgui_font.h"
#include "hello_imgui/runner_params.h"
#include "hello_imgui/hello_imgui_widgets.h"
#include <string>
#include <cstddef>
#include <cstdint>
#ifdef HELLOIMGUI_USE_SDL2
#ifdef _WIN32
#ifndef HELLOIMGUI_WIN32_AUTO_WINMAIN
// Under Windows, we redefine WinMain ourselves
#include <SDL.h>
#endif
#endif
// Let SDL redefine main under iOS
#ifdef HELLOIMGUI_IOS
#include <SDL.h>
#endif
#endif
struct ImGuiTestEngine;
namespace HelloImGui
{
// =========================== HelloImGui::Run ==================================
/**
@@md#HelloImGui::Run
__HelloImGui::Run()__ will run an application with a single call.
Three signatures are provided:
* `HelloImGui::Run(RunnerParams &)`: full signature, the most customizable version.
Runs an application whose params and Gui are provided by runnerParams.
* `HelloImGui::Run(const SimpleRunnerParams&)`:
Runs an application, using simpler params.
* `HelloImGui::Run(guiFunction, windowTitle, windowSize, windowSizeAuto=false, restoreLastWindowGeometry=false, fpsIdle=10)`
Runs an application, by providing the Gui function, the window title, etc.
Although the API is extremely simple, it is highly customizable, and you can set many options by filling
the elements in the `RunnerParams` struct, or in the simpler `SimpleRunnerParams`.
__HelloImGui::GetRunnerParams()__ will return the runnerParams of the current application.
@@md
*/
// `HelloImGui::Run(RunnerParams &)`: full signature, the most customizable version.
// Runs an application whose params and Gui are provided by runnerParams.
void Run(RunnerParams &runnerParams);
// `HelloImGui::Run(const SimpleRunnerParams&)`:
// Runs an application, using simpler params.
void Run(const SimpleRunnerParams &simpleParams);
// Runs an application, by providing the Gui function, the window title, etc.
void Run(
const VoidFunction &guiFunction,
const std::string &windowTitle = "",
bool windowSizeAuto = false,
bool windowRestorePreviousGeometry = false,
const ScreenSize &windowSize = DefaultWindowSize,
float fpsIdle = 10.f
);
// `GetRunnerParams()`: a convenience function that will return the runnerParams
// of the current application
RunnerParams* GetRunnerParams();
// ============================== Utility functions ===============================
// @@md#UtilityFunctions
// `FrameRate(durationForMean = 0.5)`: Returns the current FrameRate.
// May differ from ImGui::GetIO().FrameRate, since one can choose the duration
// for the calculation of the mean value of the fps
// Returns the current FrameRate. May differ from ImGui::GetIO().FrameRate,
// since one can choose the duration for the calculation of the mean value of the fps
// (Will only lead to accurate values if you call it at each frame)
float FrameRate(float durationForMean = 0.5f);
// `ImGuiTestEngine* GetImGuiTestEngine()`: returns a pointer to the global instance
// of ImGuiTestEngine that was initialized by HelloImGui
// (iif ImGui Test Engine is active).
ImGuiTestEngine* GetImGuiTestEngine();
// `GetBackendDescription()`: returns a string with the backend info
// Could be for example:
// "Glfw - OpenGL3"
// "Glfw - Metal"
// "Sdl - Vulkan"
std::string GetBackendDescription();
// `ChangeWindowSize(const ScreenSize &windowSize)`: sets the window size
// (useful if you want to change the window size during execution)
void ChangeWindowSize(const ScreenSize &windowSize);
// @@md
// ============================== Layout Utils =============================
// @@md#HelloImGui::Layouts
// In advanced cases when several layouts are available, you can switch between layouts.
// See demo inside
// https://github.com/pthom/hello_imgui/tree/master/src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp
// `SwitchLayout(layoutName)`
// Changes the application current layout. Only used in advanced cases
// when several layouts are available, i.e. if you filled
// runnerParams.alternativeDockingLayouts.
void SwitchLayout(const std::string& layoutName);
// `CurrentLayoutName()`: returns the name of the current layout
std::string CurrentLayoutName();
// @@md
// ============================== User prefs Utils =============================
// @@md#HelloImGui::UserPref
// You may store additional user settings in the application settings.
// This is provided as a convenience only, and it is not intended to store large
// quantities of text data. Use sparingly.
// `SaveUserPref(string userPrefName, string userPrefContent)`:
// Shall be called in the callback runnerParams.callbacks.BeforeExit
void SaveUserPref(const std::string& userPrefName, const std::string& userPrefContent);
// `string LoadUserPref(string& userPrefName)`
// Shall be called in the callback runnerParams.callbacks.PostInit
std::string LoadUserPref(const std::string& userPrefName);
// @@md
// ============================== Menus defaults =============================
/**
@@md#MenuIntro
Hello ImGui provides a default menu and status bar, which you can customize by using the params:
`RunnerParams.imGuiWindowParams.` `showMenuBar` / `showMenu_App` / `showMenu_View`
If you want to fully customize the menu:
* set `showMenuBar` to true, then set `showMenu_App` and `showMenu_View` params to false
* implement the callback `RunnerParams.callbacks.ShowMenus`:
it can optionally call `ShowViewMenu` and `ShowAppMenu` (see below).
@@md
*/
// @@md#MenuFunctions
// `ShowViewMenu(RunnerParams & runnerParams)`:
// shows the View menu (where you can select the layout and docked windows visibility
void ShowViewMenu(RunnerParams & runnerParams);
// `ShowAppMenu(RunnerParams & runnerParams)`:
// shows the default App menu (including the Quit item)
void ShowAppMenu(RunnerParams & runnerParams);
// @@md
}