Main application singleton (use this if you want to let the library manage window creation).
This convenience class sets up everything you need to display web-based content in a desktop application.
The App class initializes the Platform singleton with OS-specific defaults, creates a Renderer, and automatically manages window creation, run loop, input events, and painting.
Creating the App
Call App::Create() to initialize the library and create the App singleton.
static RefPtr< App > Create(Settings settings=Settings(), Config config=Config())
Create the App singleton.
Creating a Window
Call Window::Create() to create one or more windows during the lifetime of your app.
static RefPtr< Window > Create(Monitor *monitor, double width, double height, bool fullscreen, WindowFlags window_flags)
Create a new Window.
@ Resizable
The user can resize the window by dragging its edges.
Definition Window.h:339
@ Titled
A title bar.
Definition Window.h:338
Adding a Panel to a Window
A window's content is a layout of panels, each showing a View. A bare AddPanel() fills the whole window.
auto panel = window->AddPanel();
PanelSpec panel(PanelOptions options={}, RefPtr< Panel > *out=nullptr)
Describe a panel in a builder expression (see Builder.h for an example).
Definition Builder.h:90
Each Panel has a View instance that you can use to load web content into.
panel->view()->LoadURL(
"https://google.com");
Running the App
Call App::Run() to start the main run loop.
int main() {
app->Run();
return 0;
}
Root namespace for every public Ultralight type, function, and enumeration.
Shutting Down the App
Call App::Quit() to stop the main run loop and shut down the app.
- Note
- This is optional, you can use the Renderer class directly if you want to manage your own windows and run loop.
|
| virtual const Settings & | settings () const =0 |
| | Get the settings this App was created with.
|
| virtual void | set_listener (AppListener *listener)=0 |
| | Set an AppListener to receive callbacks for app-related events.
|
| virtual AppListener * | listener ()=0 |
| | Get the AppListener (can be nullptr).
|
| virtual bool | is_running () const =0 |
| | Whether or not the App is running.
|
| virtual Monitor * | main_monitor ()=0 |
| | Get the main monitor (this is never NULL).
|
| virtual uint32_t | monitor_count () const |
| | Get the number of connected monitors.
|
| virtual Monitor * | monitor (uint32_t index) |
| | Get a monitor by index (from 0 to monitor_count() - 1).
|
| virtual RefPtr< Renderer > | renderer ()=0 |
| | Get the underlying Renderer instance.
|
| virtual void | Run ()=0 |
| | Run the main loop (this returns after Quit()).
|
| virtual void | Quit ()=0 |
| | Quit the application.
|
| virtual bool | RunOnce (double max_wait_seconds=0.0)=0 |
| | Advance the app by one iteration of the main loop, on behalf of your own run loop.
|
| virtual void | PostTask (void(*task)(void *user_data), void *user_data, void(*destroy_user_data)(void *user_data)=nullptr)=0 |
| | Post a task to run on the main thread during a future update of the app's loop.
|
| virtual void | PostDelayedTask (double delay_ms, void(*task)(void *user_data), void *user_data, void(*destroy_user_data)(void *user_data)=nullptr)=0 |
| | Post a task to run on the main thread once a delay has elapsed.
|
| virtual TimerHandle | SetInterval (double interval_ms, void(*callback)(void *user_data), void *user_data, void(*destroy_user_data)(void *user_data)=nullptr)=0 |
| | Create a repeating timer that fires on the main thread.
|
| template<typename F, typename = std::enable_if_t<std::is_invocable_v<std::decay_t<F>&>>> |
| void | PostTask (F &&callback) |
| | Post a callable to run on the main thread during a future update of the app's loop.
|
| template<typename F, typename = std::enable_if_t<std::is_invocable_v<std::decay_t<F>&>>> |
| void | PostDelayedTask (double delay_ms, F &&callback) |
| | Post a callable to run on the main thread once a delay has elapsed.
|
| template<typename F, typename = std::enable_if_t<std::is_invocable_v<std::decay_t<F>&>>> |
| TimerHandle | SetInterval (double interval_ms, F &&callback) |
| | Create a repeating timer that invokes a callable on the main thread.
|
| virtual bool | is_idle () const =0 |
| | Whether or not the app is currently considered idle (low CPU utilization and no recent user input, sustained past the configured threshold).
|
| virtual double | thread_utilization () const =0 |
| | Get the current main-thread CPU utilization (0.0-1.0), averaged over the last ~1 second.
|
| virtual bool | GetGPUMemoryStats (GPUMemoryStats &stats) |
| | Get GPU memory statistics from the App's GPU driver.
|
| virtual bool | is_profiler_active () const =0 |
| | Whether or not the built-in profiler is active (see Settings::enable_profiler).
|
| virtual const char * | profiler_trace_path () const =0 |
| | Get the file path of the active profiler trace file.
|
| virtual void | AddRef () const =0 |
| | Increment the reference count (thread-safe).
|
| virtual void | Release () const =0 |
| | Decrement the reference count (thread-safe).
|
| virtual int | ref_count () const =0 |
| | Get the current reference count.
|
| virtual WeakControlBlock * | weak_control_block () const |
| | Get the control block used to track weak references to this object.
|
| virtual bool RunOnce |
( |
double | max_wait_seconds = 0.0 | ) |
|
|
pure virtual |
Advance the app by one iteration of the main loop, on behalf of your own run loop.
This pumps pending OS events, updates the renderer, and refreshes the display and repaints windows once the display interval has elapsed. When no events are pending, it waits up to max_wait_seconds for one.
You should call this repeatedly from your own loop instead of calling Run().
- Parameters
-
| max_wait_seconds | The longest this call may block waiting for an event or timer tick. Pass 0.0 to return immediately after processing whatever is pending. |
- Returns
- Returns whether or not the app is still running (false once Quit() has been called).
- Note
- On macOS this pumps the event queue manually rather than running the native run loop, so menu key-equivalent routing can differ from Run().