Class · aurore

aurore::Application

On this page
aurore/core/application.hpp
#include <aurore/core/application.hpp>

class aurore::Application

Description

The app: its window, its stack of activities, the focus, the inputs and the main loop. Every member is static: there is one app per process, run from the main thread.

Static functions 130

static void mapKey(AuroreKeyCombination key, ControllerButton button)

The keyboard keys that press a controller button, on top of Enter (A), Escape (B) and the arrows. By default X, Y, L, R, Shift+L (ZL), Shift+R (ZR), P or + (Plus), M or - (Minus) and Backspace (B); keys are named after their place on a US keyboard (docs/input.md). A key a view registers an action for keeps that action only, and none applies while a text is being typed.

application.hpp:724
static void unmapKey(AuroreKeyCombination key)

The keyboard keys that press a controller button, on top of Enter (A), Escape (B) and the arrows. By default X, Y, L, R, Shift+L (ZL), Shift+R (ZR), P or + (Plus), M or - (Minus) and Backspace (B); keys are named after their place on a US keyboard (docs/input.md). A key a view registers an action for keeps that action only, and none applies while a text is being typed.

application.hpp:725
static void clearKeyMap()

The keyboard keys that press a controller button, on top of Enter (A), Escape (B) and the arrows. By default X, Y, L, R, Shift+L (ZL), Shift+R (ZR), P or + (Plus), M or - (Minus) and Backspace (B); keys are named after their place on a US keyboard (docs/input.md). A key a view registers an action for keeps that action only, and none applies while a text is being typed.

application.hpp:726
static const std::vector< std::pair< AuroreKeyCombination, ControllerButton > > & getKeyMap()

The keyboard keys that press a controller button, on top of Enter (A), Escape (B) and the arrows. By default X, Y, L, R, Shift+L (ZL), Shift+R (ZR), P or + (Plus), M or - (Minus) and Backspace (B); keys are named after their place on a US keyboard (docs/input.md). A key a view registers an action for keeps that action only, and none applies while a text is being typed.

application.hpp:727
static bool init()

Inits the Aurore application. Returns true if it succeeded, false otherwise.

application.hpp:116
static void setAppId(std::string appId)

Sets the application ID reported to the windowing system (Wayland app_id / X11 WM_CLASS). Desktop environments use it to associate the window with its .desktop entry, which is required for showing the correct icon in the taskbar. Must be called before createWindow().

application.hpp:125
static const std::string & getAppId()

The application ID given to setAppId(), "" by default.

application.hpp:127
static void setCadran(bool on)

Aurore draws every app in Cadran's look (docs/cadran.md): init() and createWindow() start it. false, before init(), keeps Aurore's own look instead.

application.hpp:134
static bool isCadran()

Whether the app is drawn in Cadran's look (see setCadran()).

application.hpp:136
static void createWindow(std::string title)

Creates the application window with the given title. Must be called after calling init().

application.hpp:142
static bool mainLoop()

Application main loop iteration. Must be called in an infinite loop until it returns false.

application.hpp:148
static Platform * getPlatform()

The platform the app runs on (window, inputs, video, audio, fonts), made by init().

application.hpp:151
static AudioPlayer * getAudioPlayer()

The platform's sound player.

application.hpp:153
static YGConfig * getYogaConfig()

The Yoga configuration every view's node is created with (web defaults, yoga's messages in the log).

application.hpp:159
static NVGcontext * getNVGContext()

The nanovg context every view draws with.

application.hpp:162
static void onWindowResized(int width, int height)

Called by the video context when the content window is resized

application.hpp:177
static void setWindowSize(int width, int height)

Do not call this function, use it internally. Called when the video context is ready (to setup the initial content scaling).

application.hpp:183
static void onWindowReposition(int xPos, int yPos)

Called by the video context when the content window is Repositioned

application.hpp:188
static void setWindowPosition(int xPos, int yPos)

Do not call this function, use it internally. Called when the video context is ready (to setup the initial window position).

application.hpp:194
static std::vector< Activity * > getActivitiesStack()

A copy of the stack of activities, the first pushed first.

application.hpp:197
static void pushActivity(Activity *view,TransitionAnimation animation = TransitionAnimation::FADE)

Pushes a view on this applications's view stack.

The view will automatically be resized to take the whole screen.

The view will gain focus if applicable.

The first activity to be pushed cannot be popped.

application.hpp:209
static void replaceActivity(Activity *activity,TransitionAnimation animation = TransitionAnimation::FADE)

Pushes the activity in place of the one on top, in one transition: the one replaced is not shown again on the way, nor given the focus back later, and is deleted once the new one is shown (a wizard's next step, a sign-in screen giving way to the home screen). With an empty stack it is a push.

application.hpp:218
static bool popActivity(TransitionAnimation animation = TransitionAnimation::FADE,std::function< void(void)> cb = [] {},bool free = true)

Pops the last pushed activity from the stack and gives focus back where it was before.

return false if no actifity to pop.

application.hpp:226
static void giveFocus(View *view)

Gives the focus to the given view or clears the focus if given nullptr.

application.hpp:233
static void forgetView(View *view)

Drops every reference the focus system holds to a view that is being destroyed.

application.hpp:239
static void setHighlightIdleFade(bool fade)

When on, the focus highlight fades out after a moment without any button pressed (0.8 s, then 0.4 s), and comes back at the next one: for a screen watched more than browsed (a player, a slideshow). Off by default.

application.hpp:247
static void setFocusAnnouncer(std::function< void(const std::string &)> announcer)

Called with the focused view's description (View:: getAccessibilityDescription: "Save, button") each time the focus moves: where a screen reader, a text-to-speech engine or a log plugs in. Nothing by default; an empty function removes it.

application.hpp:255
static void announce(const std::string &text)

Gives text to the focus announcer, outside of a focus move: a value changed in place (View::announceAccessibilityValue), a toast (notify says its text). Nothing for an empty text. getLastAnnouncement() is the last text given, announcer or not (for tests).

application.hpp:263
static const std::string & getLastAnnouncement()
static void setReduceMotion(bool reduce)

Reduced motion: the movements that are only there for show are skipped (the transition= of views, the highlight's glide, the scrolling of lists and of texts cut short, the toasts' and dropdowns' slide, the switch cells' bounce; Cadran's entrances, glides and breathing glow). Off by default. getReduceMotion(), which transitions read, is also true while Cadran's effects leave movement out (Preferences › Visual effects "reduced", the lighter effects in hand, AURORE_STILL_FOCUS); the highlight's glide follows the app's setting only.

application.hpp:277
static bool getReduceMotion()
static bool isReduceMotionSet()

The app's own setting alone, without Cadran's.

application.hpp:280
static Time getLastInputTime()

When the last input came (a button, a key, a touch, the mouse), on the clock of getCPUTimeUsec(): what the theme's particles stop after.

application.hpp:286
static void setTextScale(float scale)

Every Label drawn scale times its size (Label::setFontScale), and the screens laid out again for it at once (every view told through View::onTextScaleChanged). 1 by default; Cadran's text size setting goes through here.

application.hpp:294
static float getTextScale()
static void setDensity(float density)

The density of the lengths (aurore::setDensity): DENSITY_COMFORTABLE by default, DENSITY_COMPACT, DENSITY_DENSE for a small screen. The text keeps its size (setTextScale). Read when the views are made: set it before the first screen; AURORE_DENSITY gives it on the desktop.

application.hpp:303
static float getDensity()
static WidthClass getWidthClass()

The class of the screen's width now (widthClassOf(contentWidth)). XML reads it when a view is made; a view that lays itself out in code reads it there too, and the window size changed event says when it may have changed. ORIGINAL_WINDOW_WIDTH sets it for a small screen (480 on a 320-pixel one); AURORE_DESIGN_SIZE=480x360 tries it on the desktop.

application.hpp:313
static void usePreset(const LayoutPreset &preset)

Lays every screen out for preset (PRESET_SMALL_SCREEN on a small screen): its design size, density and text scale. Before init(); a platform may give one (Platform::getLayoutPreset), the app's wins, and AURORE_PRESET (small or standard) wins over both on the desktop.

application.hpp:321
static float getPresetTextScale()

The text scale of the preset in use (1 without one): what Cadran's text size setting multiplies.

application.hpp:324
static void registerModel(const std::string &name, DataModel *model)

The data models XML bindings read (View::bind, bind="text: name.key"), by name, for every screen. An Activity's own (Activity::registerModel) come first. The model must outlive its registration.

application.hpp:331
static void unregisterModel(const std::string &name)
static DataModel * getModel(const std::string &name)
static View * getHoveredView()

The view under the mouse pointer that has a hover: style (desktop), or nullptr.

application.hpp:339
static Style getStyle()
static Theme getTheme()

The colours of the variant in use (light or dark), with the theme file's over them.

application.hpp:348
static ThemeVariant getThemeVariant()

The variant in use, as the platform reports it.

application.hpp:350
static Event< ThemeVariant > * getThemeChangedEvent()

Fired when the theme changed: another variant (Platform::setThemeVariant), a theme file (Theme::loadFile, Theme::reset) or a colour changed (Theme::addColor). Checked once a frame, before it is drawn; by then every view of the screens took the change (View::onThemeChanged). For what keeps colours of its own.

application.hpp:359
static bool hasThemeBackground()

Whether the theme in use draws a picture behind the screens in the variant in use (its background_image, loaded).

application.hpp:365
static void drawThemeBackground(NVGcontext *vg,float x,float y,float width,float height)

Draws what is behind the screens over x, y, width, height: the clear colour, the theme's background image and its veil. For a panel drawn over other views in a translucent surface colour (a drawer over a page), so that it hides them and still shows the picture. Nothing without a background image.

application.hpp:374
static void drawThemeBackground(NVGcontext *vg,float x,float y,float width,float height,float radius)

The same in a shape with round corners of radius, and the strips of the theme's decorations (decor.top, decor.bottom) over it: under a translucent dialog or sheet (View::setThemeArea).

application.hpp:381
static ImeManager * getImeManager()

The platform's text input (the keyboard shown for an EditTextDialog).

application.hpp:384
static bool loadFontFromFile(std::string fontName,std::string filePath)

Loads a font from a given file and stores it in the font stash. A AURORE_ASSET() path ("@res/...") is read from the resources built into the program when they are (USE_LIBROMFS). Returns true if the operation succeeded.

application.hpp:392
static bool loadFontFromMemory(std::string fontName,void *data,size_t size,bool freeData)

Loads a font from a given memory buffer and stores it in the font stash. Returns true if the operation succeeded.

application.hpp:398
static bool loadFontFromMemory(std::string fontName,void *data,size_t size,bool freeData,int faceIndex)

The same, with the face at faceIndex of a font collection (.ttc).

application.hpp:403
static int getFont(std::string fontName)

Returns the nanovg handle to the given font name, or FONT_INVALID if no such font is currently loaded.

application.hpp:409
static bool addFontFallback(const std::string &font,const std::string &fallback)

Glyphs missing from the font loaded as font are looked up in the one loaded as fallback. False when either is not loaded.

application.hpp:415
static int getDefaultFont()

The font a new Label draws with: the regular font (the Chinese one on the Switch).

application.hpp:418
static void notify(const std::string &text, View *leading = nullptr)

Shows a toast with text, and leading (an icon) before it when given; the focus announcer says the text.

application.hpp:422
static void onControllerButtonPressed(enum ControllerButton button,bool repeating)

Handles a controller button as the main loop does: the focused view's actions first, then the focus moves. For the platforms and the test harness.

application.hpp:426
static void onKeyboardPressed(AuroreKeyCombination key, bool repeating)

Handles a key as the main loop does (the actions registered on keys).

application.hpp:429
static void crash(std::string text)

"Crashes" the app (displays a fullscreen CrashFrame) Shows text in a dialog that cannot be dismissed, with one button that quits the app: for an error the app cannot go on after. Can be called from any thread.

application.hpp:439
static void quit()

Asks the main loop to stop: the next mainLoop() returns false, after the exit events.

application.hpp:442
static void clear()

Deletes every activity on the stack and clears the focus.

application.hpp:444
static void blockInputs(bool muteSounds = false)

Blocks any and all user inputs

application.hpp:449
static void unblockInputs()

Unblocks inputs after a call to blockInputs()

application.hpp:455
static bool isInputBlocks()
static const ControllerState & getControllerState()

The controller's buttons and sticks as read this frame.

application.hpp:461
static void setCommonFooter(std::string footer)

A text the app keeps for its footers (the library does not draw it).

application.hpp:464
static std::string * getCommonFooter()
static void setMaximumUIScale(float scale)

Caps how large the UI is allowed to grow relative to the design size. Set to 0 to disable the cap.

application.hpp:475
static float getMaximumUIScale()
static void setGlobalQuit(bool enabled)

Sets whether BUTTON_START will globally be used to close the application.

application.hpp:481
static void setFPSStatus(bool enabled)

Whether getFPS() is counted (60 when off).

application.hpp:484
static bool getFPSStatus()
static size_t getFPS()

The frames per second over the last second.

application.hpp:487
static void setLimitedFPS(size_t fps)

Set the FPS limit

Parameters

fps

0 to disable limit

application.hpp:493
static void setSwapInterval(int interval)

Set the swap interval Must be called after createWindow. On some platforms, it is impossible to set it back to 0 after setting it to a non-zero values, so you can use VideoContext::swapInterval = 0; (#include "aurore/core/video.hpp") before creating the window.

Test results:

Platforms that always vsync (interval: 1):

iOS18/GLES3/SDL PS4/GLES2/SDL

Platforms that only support enable and disable vsync (interval: 0,1):

Android9/GLES2/SDL macOS13.0+/GL3.2/GLFW (will fixed to 120fps with vsync enabled, https://github.com/glfw/glfw/pull/2277) Windows11/GL3.2/GLFW Linux Wayland/GL3.2/GLFW

Platforms that not support disable vsync (interval: 1,2,3,4):

Windows11/D3D11/GLFW Switch/DEKO3D

Platforms that support arbitrary values (interval: 0,1,2,3,4):

PsVita/GXM PsVita/GLES2/SDL macOS13.0+/GL3.2/SDL Linux X11/GL3.2/GLFW Linux X11/GL3.2/SDL Linux Wayland/GL3.2/SDL Switch/GL4.3/GLFW Switch/GL4.3/SDL

Parameters

interval

0 to disable vsync

application.hpp:529
static void setAutomaticDeactivation(bool value)

If the value is set to true, the program will limit FPS to Application::DeactivatedFPS after Application::DeactivatedTime milliseconds of inactivity.

default is false;

application.hpp:537
static bool getAutomaticDeactivation()
static bool hasActiveEvent()

Whether the app is active: an input lately, an animation under way, or no automatic deactivation. Always true on the Switch.

application.hpp:542
static void setActiveEvent(bool value)

Marks the app active now (and asks for a redraw), or no longer.

application.hpp:544
static void setDeactivatedTime(int millisecond)

After this long without an input, the app is drawn at the deactivated FPS.

application.hpp:546
static void setDeactivatedFPS(int value)

The frame rate once deactivated (5 by default).

application.hpp:548
static int getDeactivatedFPS()
static double getDeactivatedFrameTime()

A frame's time once deactivated, in seconds.

application.hpp:551
static void setRedrawOnDemand(bool enabled)

Redraw on demand: a frame is drawn only when something may have changed on screen (an input, a running animation, a sync or delayed task that ran, a view's layout invalidated, a window resized, or requestRedraw()), and at least once a second. On the other frames the inputs are still read, but nothing is drawn or presented, which saves most of the CPU and GPU time of an idle screen.

A view that changes how it looks without any of these (a colour set from a timer of its own...) calls requestRedraw().

default is false: every frame is drawn.

application.hpp:566
static bool isRedrawOnDemand()
static void requestRedraw()

Asks for the next frames to be drawn, with redraw on demand.

application.hpp:573
static uint64_t getDrawnFrameCount()

Number of frames drawn since the start (frames skipped by redraw on demand are not counted).

application.hpp:579
static void setRedrawDebug(bool enabled)

Debugging redraw on demand: each frame it skips is drawn all the same, without being presented, and compared with the last frame presented. A difference is something that changed on screen without asking for a redraw (a missing invalidate() or requestRedraw()): it is logged as a warning, with the area and the views drawn there (once per area). Reads every frame back: slow, and OpenGL drivers only. Off by default; AURORE_REDRAW_DEBUG=1 in the environment turns it on (desktop).

application.hpp:590
static bool isRedrawDebug()
static uint64_t getMissedRedrawCount()

With setRedrawDebug(): the number of skipped frames found different from the last frame presented, and the last such area, in the views' coordinates.

application.hpp:599
static Rect getLastMissedRedrawArea()
static GenericEvent * getGlobalFocusChangeEvent()

Fired with the new focus each time the focus moves.

application.hpp:603
static VoidEvent * getGlobalHintsUpdateEvent()

Fired when the footer's hints must be read again (the focus moved, keys swapped).

application.hpp:605
static Event< InputType > * getGlobalInputTypeChangeEvent()

Fired when the input type changes (a touch after the buttons, or the reverse).

application.hpp:607
static VoidEvent * getRunLoopEvent()

Fired once per main loop iteration, after the frame and the sync tasks.

application.hpp:609
static VoidEvent * getPostFrameEvent()

Fired after each frame presented.

application.hpp:611
static VoidEvent * getExitEvent()

Fired when the app starts to exit, before the activities are deleted.

application.hpp:613
static VoidEvent * getExitDoneEvent()

Fired once the activities and the views left are deleted.

application.hpp:615
static VoidEvent * getWindowSizeChangedEvent()

Fired when the window's size changed.

application.hpp:617
static VoidEvent * getWindowCreationDoneEvent()
static VoidEvent * getWindowShouldCloseEvent()

Fired when the window is closed or quit() was asked, before the exit.

application.hpp:621
static Event< bool > * getWindowFocusChangedEvent()

Fired with true or false when the window gains or loses the system's focus.

application.hpp:623
static View * getCurrentFocus()

The view that has the focus, or nullptr.

application.hpp:626
static std::string getTitle()

The window's title, as given to createWindow().

application.hpp:629
static void registerXMLView(std::string name, XMLViewCreator creator)

Registers a view to be created from XML. You must give the name of the XML node as well as a function that creates the view.

If you need attributes, register them with the given functions in the view class constructor directly. They will be called one by one after the view is instantiated.

You should not add any children in the function, it is already taken care of.

application.hpp:640
static bool XMLViewsRegisterContains(std::string name)

Whether an XML tag is registered (registerXMLView()).

application.hpp:643
static std::vector< std::string > getXMLViewNames()

The XML tags registered (registerXMLView).

application.hpp:646
static XMLViewCreator getXMLViewCreator(std::string name)

The function registered for an XML tag.

application.hpp:648
static std::string getLocale()

Returns the current system locale.

application.hpp:653
static void addToFreeQueue(View *view)

Deletes view at the end of the current main loop iteration (once no ptrLock() holds it). View::freeView() calls it.

application.hpp:657
static InputType getInputType()

Returns the current input type.

application.hpp:662
static void setInspectorEnabled(bool enabled)

The built-in inspector (docs/inspector.md): F12 on a keyboard, or both sticks pressed in together (L3 + R3) on a controller, opens it over the screen with the view tree, the focus chain, the yoga box and the theme values of a view, and the frame's timings. Off by default; the AURORE_INSPECTOR CMake option, or AURORE_INSPECTOR=1 in the environment on a desktop, turns it on at init(). Closed, it only watches for its toggle.

application.hpp:676
static bool isInspectorEnabled()
static void setHotReload(bool enabled,const std::string &resourcesDir = "")

Hot reload, on a desktop (docs/hot_reload.md): the XML files the activity on top was built from, and the files read by Theme::loadFile(), are watched, and the activity is built again when one of them changes (the focus is put back where it was when it can be). resourcesDir, when given, is a resources folder (the app's sources' resources/) the XML files are read from in place of the ones built in (libromfs) or copied next to the app. Off by default; AURORE_HOT_RELOAD=1, or AURORE_HOT_RELOAD=<resources folder>, in the environment turns it on at init(). Does nothing on the consoles.

application.hpp:691
static bool isHotReload()
static bool rebuildActivity()

Builds the content of the activity on top again from its createContentView(), as hot reload does. False when it cannot (an activity given its view in its constructor) or the new content throws while being made (its XML, onContentAvailable(), or a tab shown, made when it takes the focus): the old one then stays, with the focus, and the error is shown in a notification.

application.hpp:701
static void enableDebuggingView(bool enable)

Draws the debug layer (DebugLayer) over the app.

application.hpp:704
static bool isDebuggingViewEnabled()
static void setSwapInputKeys(bool swap)

Swaps A and B (and X and Y) for the app's actions, as on a Japanese console.

application.hpp:715
static bool isSwapInputKeys()
static void setDrawCoursor(bool draw)

Draws the mouse pointer with nanovg (for platforms with no system pointer).

application.hpp:736
static bool isDrawCursor()
static bool isHintsLiteMode()
static void setHintsLiteMode(const bool value)

Set hints lite mode, which will only show hints for A button and B button.

application.hpp:753
static void tryDeinitFirstResponder(View *view)

Stops the touch gestures view is tracking, before it is removed.

application.hpp:759
static void addToWatchedKeys(const AuroreKeyCombination key)

Reads key each frame from now on (counted: one removeWatchedKeys() per add).

application.hpp:762
static void removeWatchedKeys(const AuroreKeyCombination key)

Static attributes 13

static uint32_t ORIGINAL_WINDOW_WIDTH = 1280

The design width, in layout units.

application.hpp:108
static uint32_t ORIGINAL_WINDOW_HEIGHT = 720

The design height.

application.hpp:109
static std::string appId = ""
static float contentWidth

The size of the UI in layout units: ORIGINAL_WINDOW_WIDTH wide, as high as the window's ratio gives.

application.hpp:164
static float contentHeight
static float presetTextScale = 1.0f
static bool presetChosen = false
static unsigned windowWidth

The window's size in pixels.

application.hpp:169
static unsigned windowHeight
static int windowXPos

The window's position on the screen (desktop).

application.hpp:172
static int windowYPos
static float windowScale

Pixels per layout unit (windowWidth / ORIGINAL_WINDOW_WIDTH, capped by setMaximumUIScale()).

application.hpp:468
static float maximumUIScale = 0.0f

Friends 1

friend class EditTextDialog

Read from Aurore's headers by Doxygen at each build · library/include