docs
Docs
C++ API
C API
Search API
Ctrl K
1.4
2.0
latest
1.4
Ultralight C++ API
1.4.0
Toggle main menu visibility
Loading...
Searching...
No Matches
App.h
Go to the documentation of this file.
1
/**************************************************************************************************
2
* This file is a part of Ultralight. *
3
* *
4
* See <https://ultralig.ht> for licensing and more. *
5
* *
6
* (C) 2024 Ultralight, Inc. *
7
**************************************************************************************************/
8
#pragma once
9
#include "
Defines.h
"
10
#include <
Ultralight/RefPtr.h
>
11
#include <
Ultralight/Renderer.h
>
12
#include <
Ultralight/platform/Config.h
>
13
14
namespace
ultralight
{
15
16
class
Monitor
;
17
class
Window
;
18
19
///
20
/// Interface for all App-related events. @see App::set_listener
21
///
22
class
AExport
AppListener
{
23
public
:
24
virtual
~AppListener
() {}
25
26
///
27
/// Called whenever the App updates. You should update all app logic here.
28
///
29
/// @note This event is fired right before the run loop calls
30
/// Renderer::Update and Renderer::Render.
31
///
32
virtual
void
OnUpdate
() {}
33
};
34
35
///
36
/// App-specific settings.
37
///
38
struct
AExport
Settings
{
39
///
40
/// The name of the developer of this app.
41
///
42
/// This is used to generate a unique path to store local application data
43
/// on the user's machine.
44
///
45
String
developer_name
=
"MyCompany"
;
46
47
///
48
/// The name of this app.
49
///
50
/// This is used to generate a unique path to store local application data
51
/// on the user's machine.
52
///
53
String
app_name
=
"MyApp"
;
54
55
///
56
/// The root file path for our file system. You should set this to the
57
/// relative path where all of your app data is.
58
///
59
/// This will be used to resolve all file URLs, eg file:///page.html
60
///
61
/// @note This relative path is resolved using the following logic:
62
/// - Windows: relative to the executable path
63
/// - Linux: relative to the executable path
64
/// - macOS: relative to YourApp.app/Contents/Resources/
65
///
66
String
file_system_path
=
"./assets/"
;
67
68
///
69
/// Whether or not we should load and compile shaders from the file system
70
/// (eg, from the /shaders/ path, relative to file_system_path).
71
///
72
/// If this is false (the default), we will instead load pre-compiled shaders
73
/// from memory which speeds up application startup time.
74
///
75
bool
load_shaders_from_file_system
=
false
;
76
77
///
78
/// We try to use the GPU renderer when a compatible GPU is detected.
79
///
80
/// Set this to true to force the engine to always use the CPU renderer.
81
///
82
bool
force_cpu_renderer
=
false
;
83
};
84
85
///
86
/// Main application singleton (use this if you want to let the library manage window creation).
87
///
88
/// This convenience class sets up everything you need to display web-based content in a
89
/// desktop application.
90
///
91
/// The App class initializes the Platform singleton with OS-specific defaults, creates a Renderer,
92
/// and automatically manages window creation, run loop, input events, and painting.
93
///
94
/// ## Creating the App
95
///
96
/// Call App::Create() to initialize the library and create the App singleton.
97
///
98
/// ```
99
/// auto app = App::Create();
100
/// ```
101
///
102
/// ## Creating a Window
103
///
104
/// Call Window::Create() to create one or more windows during the lifetime of your app.
105
///
106
/// ```
107
/// auto window = Window::Create(app->main_monitor(), 1024, 768, false,
108
/// kWindowFlags_Titled | kWindowFlags_Resizable);
109
/// ```
110
///
111
/// ### Creating an Overlay in a Window
112
///
113
/// Each Window can have one or more Overlay instances. Overlays are used to display web-based
114
/// content in a portion of the window.
115
///
116
/// Call Overlay::Create() to create an overlay in a window.
117
///
118
/// ```
119
/// auto overlay = Overlay::Create(window, 1024, 768, 0, 0);
120
/// ```
121
///
122
/// Each Overlay has a View instance that you can use to load web content into.
123
///
124
/// ```
125
/// overlay->view()->LoadURL("https://google.com");
126
/// ```
127
///
128
/// ## Running the App
129
///
130
/// Call App::Run() to start the main run loop.
131
///
132
/// ```
133
/// #include <AppCore/AppCore.h>
134
///
135
/// using namespace ultralight;
136
///
137
/// int main() {
138
/// // Initialize app, window, overlay, etc. here...
139
///
140
/// app->Run();
141
///
142
/// return 0;
143
/// }
144
/// ```
145
///
146
/// ## Shutting Down the App
147
///
148
/// Call App::Quit() to stop the main run loop and shut down the app.
149
///
150
/// ```
151
/// app->Quit();
152
/// ```
153
154
/// @note This is optional, you can use the Renderer class directly if you want to manage your
155
/// own windows and run loop.
156
///
157
class
AExport
App
:
public
RefCounted
{
158
public
:
159
///
160
/// Create the App singleton.
161
///
162
/// @param settings Settings to customize App runtime behavior.
163
///
164
/// @param config Config options for the Ultralight renderer.
165
///
166
/// @return Returns a ref-pointer to the created App instance.
167
///
168
/// @note You should only create one of these per application lifetime.
169
///
170
/// @note Certain Config options may be overridden during App creation,
171
/// most commonly Config::face_winding and Config::cache_path.
172
///
173
static
RefPtr<App>
Create
(
Settings
settings
=
Settings
(),
Config
config =
Config
());
174
175
///
176
/// Get the App singleton.
177
///
178
static
App
*
instance
();
179
180
///
181
/// Get the settings this App was created with.
182
///
183
virtual
const
Settings
&
settings
()
const
= 0;
184
185
///
186
/// Set an AppListener to receive callbacks for app-related events.
187
///
188
/// @note Ownership remains with the caller.
189
///
190
virtual
void
set_listener
(
AppListener
*
listener
) = 0;
191
192
///
193
/// Get the AppListener, if any.
194
///
195
virtual
AppListener
*
listener
() = 0;
196
197
///
198
/// Whether or not the App is running.
199
///
200
virtual
bool
is_running
()
const
= 0;
201
202
///
203
/// Get the main monitor (this is never NULL).
204
///
205
/// @note We'll add monitor enumeration later.
206
///
207
virtual
Monitor
*
main_monitor
() = 0;
208
209
///
210
/// Get the underlying Renderer instance.
211
///
212
virtual
RefPtr<Renderer>
renderer
() = 0;
213
214
///
215
/// Run the main loop.
216
///
217
virtual
void
Run
() = 0;
218
219
///
220
/// Quit the application.
221
///
222
virtual
void
Quit
() = 0;
223
224
protected
:
225
virtual
~App
();
226
};
227
228
}
// namespace ultralight
Defines.h
AExport
#define AExport
Definition
Defines.h:42
Config.h
RefPtr.h
Renderer.h
ultralight::App
Main application singleton (use this if you want to let the library manage window creation).
Definition
App.h:157
ultralight::App::~App
virtual ~App()
ultralight::App::renderer
virtual RefPtr< Renderer > renderer()=0
Get the underlying Renderer instance.
ultralight::App::settings
virtual const Settings & settings() const =0
Get the settings this App was created with.
ultralight::App::instance
static App * instance()
Get the App singleton.
ultralight::App::Create
static RefPtr< App > Create(Settings settings=Settings(), Config config=Config())
Create the App singleton.
ultralight::App::main_monitor
virtual Monitor * main_monitor()=0
Get the main monitor (this is never NULL).
ultralight::App::Quit
virtual void Quit()=0
Quit the application.
ultralight::App::Run
virtual void Run()=0
Run the main loop.
ultralight::App::listener
virtual AppListener * listener()=0
Get the AppListener, if any.
ultralight::App::is_running
virtual bool is_running() const =0
Whether or not the App is running.
ultralight::App::set_listener
virtual void set_listener(AppListener *listener)=0
Set an AppListener to receive callbacks for app-related events.
ultralight::AppListener
Interface for all App-related events.
Definition
App.h:22
ultralight::AppListener::~AppListener
virtual ~AppListener()
Definition
App.h:24
ultralight::AppListener::OnUpdate
virtual void OnUpdate()
Called whenever the App updates.
Definition
App.h:32
ultralight::Monitor
A platform-specific monitor.
Definition
Monitor.h:16
ultralight::RefCounted
Interface for all ref-counted objects that will be managed using the RefPtr<> smart pointer.
Definition
RefPtr.h:47
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:79
ultralight::String
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition
String.h:34
ultralight::Window
A platform-specific window.
Definition
Window.h:123
ultralight
Definition
Bitmap.h:14
ultralight::Config
Core configuration for the renderer.
Definition
Config.h:95
ultralight::Settings
App-specific settings.
Definition
App.h:38
ultralight::Settings::app_name
String app_name
The name of this app.
Definition
App.h:53
ultralight::Settings::file_system_path
String file_system_path
The root file path for our file system.
Definition
App.h:66
ultralight::Settings::force_cpu_renderer
bool force_cpu_renderer
We try to use the GPU renderer when a compatible GPU is detected.
Definition
App.h:82
ultralight::Settings::load_shaders_from_file_system
bool load_shaders_from_file_system
Whether or not we should load and compile shaders from the file system (eg, from the /shaders/ path,...
Definition
App.h:75
ultralight::Settings::developer_name
String developer_name
The name of the developer of this app.
Definition
App.h:45
AppCore
App.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4