Public Functions
| VPlatform(const VPlatform &) | |
| VPlatform & | operator=(const VPlatform &) |
| void | set_name(const std::string & name) |
| void | set_app_version(std::string version) |
| bool | init(const std::string & themes_path, const std::string & styles_path, const std::string & theme_id, const int & app_style_dirs = {}) |
| int & | engine() |
| void | set_http_handler(HttpHandler handler) |
| void | set_upload_handler(UploadHandler handler) |
| void | set_pick_handler(PickHandler handler) |
| void | set_open_url_handler(OpenUrlHandler handler) |
| void | set_navigate_handler(OpenUrlHandler handler) |
| void | set_copy_text_handler(CopyTextHandler handler) |
| void | set_save_text_handler(SaveTextHandler handler) |
| void | set_run_process_handler(RunProcessHandler handler) |
| void | set_purchase_handler(PurchaseHandler handler) |
| void | set_query_purchases_handler(QueryPurchasesHandler handler) |
| void | set_timer_handler(TimerHandler handler) |
| void | set_post_handler(PostHandler handler) |
| void | set_store_handler(std::function<void (const std::string &, const std::string &)> handler) |
| void | set_camera_permission_handler(std::function<void ()> handler) |
| bool | set_viewport_width(double width) |
| bool | set_viewport_height(double height) |
| double | viewport_height() |
| bool | set_maximized(bool maximized) |
| void | set_mobile_icon_scale(double scale) |
| double | mobile_icon_scale() |
| void | set_mobile_font_scale(double scale) |
| double | mobile_font_scale() |
| void | set_mobile_metric_scale(double scale) |
| double | mobile_metric_scale() |
| void | dispatch(const std::string & path, const std::string & event) |
| bool | press_back() |
| bool | handles_back() |
| bool | on_scroll(double delta) |
| bool | reveal_controls() |
| bool | controls_hidden() |
| bool | has_editor_value(const std::string & path) |
| void | set_render_handler(std::function<void ()> handler) |
| void | request_render() |
| RenderNode | build_render_tree() |
| std::string | render_tree_json() |
| int | render_patches() |
| std::string | render_patches_json() |
| bool | set_active_theme(const std::string & id) |
| std::string | add_theme_json(const std::string & json) |
| bool | remove_theme(const std::string & id) |
| void | set_theme_changed_handler(std::function<void (const std::string &)> handler) |
Detailed Description
Platform contract of a VApp: the methods that platform code
calls to start the app, install its services, deliver the user's input,
and read back what to draw.
Platform code means the desktop, web, and Android shells, plus headless
callers like tests and static site renderers. App code doesn't need these
methods. Each VApp has one VPlatform, reached through
VApp::platform(), and like VApp, it's only used
from the UI thread.
Before build_app() runs, the platform names
itself with set_name(), installs its services, and loads the styles and
themes with init(). A service is a handler behind one of VApp's
calls, like the one that sends VApp::http() requests. App code may call
a service as soon as it starts, so the services go in first. A platform
installs only the ones that it supports, and VApp's calls are safe
without them.
To render, the platform calls render_patches() and applies the
patches to its widgets. It renders after each event that it delivers,
like a click through dispatch(), so that the app's changes show:
Vortex::VApp app;
Vortex::VPlatform& platform = app.platform();
platform.set_name("Desktop");
platform.set_http_handler(send_request);
platform.init("themes", "styles", "Dark (huntrsoftwarellc)");
Vortex::build_app(app);
apply(platform.render_patches()); // The whole tree, as one patch
platform.dispatch("App/Save", "click");
apply(platform.render_patches()); // Only what the click changed
A service's callback, like an http() reply, runs outside of an event,
so the platform asks for a render after running it (see
request_render()). Methods that report the window,
like set_viewport_width(), return whether a render is needed.
Member Function Documentation
VPlatform(const VPlatform &)
Not copyable, since it works on one VApp. Hold it by reference.
void set_name(const std::string & name)
Sets the platform's name, "Desktop", "Web", or "Mobile", which turns on the state of the same name for every node.
Styles give these states values of their own, like a window border
that only @Desktop has. Call it once, since a second name adds to
the first rather than replacing it.
void set_app_version(std::string version)
Sets the app's version, like "1.2.0", that
VApp::app_version() returns.
Leave it unset in a build without one, like a development build. Update checks then report an error rather than compare.
bool init(const std::string & themes_path, const std::string & styles_path, const std::string & theme_id, const int & app_style_dirs = {})
Loads the styles and themes, then makes the theme with theme_id
active.
The library's styles load first, then each of app_style_dirs in
order, so that an app's style can build on a library one, like
App << Vortex/App. Each .json file in themes_path loads as a
theme. When none has theme_id, like a saved id whose theme was
removed, the first loaded theme becomes active instead. Returns
false only when no theme loads.
themes_path is a folder of theme .json files.styles_path is the library's styles folder, which holds widgets/
and mounts/.theme_id is a theme's name and publisher, like
"Dark (huntrsoftwarellc)".app_style_dirs are folders of the app's own .lyr styles.int & engine()
Returns the Layers engine that holds the loaded styles, like for a test that reads a style's attributes.
void set_http_handler(HttpHandler handler)
Installs the handler behind VApp::http() (see
HttpHandler).
void set_upload_handler(UploadHandler handler)
Installs the handler behind
VApp::pick_and_upload() (see
UploadHandler).
void set_pick_handler(PickHandler handler)
Installs the handler behind VApp::pick_path()
(see PickHandler).
void set_open_url_handler(OpenUrlHandler handler)
Installs the handler behind VApp::open_url()
(see OpenUrlHandler).
void set_copy_text_handler(CopyTextHandler handler)
Installs the handler behind VApp::copy_text()
(see CopyTextHandler).
void set_save_text_handler(SaveTextHandler handler)
Installs the handler behind VApp::save_text()
(see SaveTextHandler).
void set_run_process_handler(RunProcessHandler handler)
Installs the handler behind
VApp::run_process() (see
RunProcessHandler).
void set_purchase_handler(PurchaseHandler handler)
Installs the handler behind
VApp::start_purchase() (see
PurchaseHandler).
void set_query_purchases_handler(QueryPurchasesHandler handler)
Installs the handler behind
VApp::query_purchases() (see
QueryPurchasesHandler).
void set_timer_handler(TimerHandler handler)
Installs the handler behind VApp::after() (see
TimerHandler).
void set_post_handler(PostHandler handler)
Installs the handler behind VApp::post() (see
PostHandler).
void set_store_handler(std::function<void (const std::string &, const std::string &)> handler)
Installs the handler behind VApp::store(), which
saves value under key in the platform's storage.
An empty value removes the key. At the next startup, the platform
passes the saved values back with
VApp::set_env().
void set_camera_permission_handler(std::function<void ()> handler)
Installs the handler behind
VApp::request_camera_permission(),
which shows the system's camera permission prompt.
The platform reports the answer as a "scanstatus:granted" or
"scanstatus:denied" event (see dispatch()).
bool set_viewport_width(double width)
Reports the window's width (px), which turns the Narrow and
Medium states on or off (see
VApp::is_narrow()).
Returns whether either state changed, so that the platform renders
only then. Widening out of Narrow also shows the controls that
on_scroll() hid.
bool set_viewport_height(double height)
Reports the window's height (px), which a node with a
Size.Height Viewport fraction sizes against.
The height is rounded to whole pixels. Returns whether it changed and the last render had such a node, so that a resize with none on screen skips the render.
double viewport_height()
Returns the window's height (px) from set_viewport_height(), or 0
before the platform reports it.
bool set_maximized(bool maximized)
Reports whether the window is maximized, which turns the Maximized
state on or off, like to drop the window's border.
Returns whether the state changed, so that the platform renders only then.
void set_mobile_icon_scale(double scale)
Sets how much the Mobile state enlarges icons, like 1.5 for half
again as big (see
VApp::kMobileIconScale, the default).
The mobile scales spare styles an @Mobile value on every size, and
a style's own @Mobile value still wins. A new scale shows at the
next render, and 1.0 turns it off.
double mobile_icon_scale()
Returns how much the Mobile state enlarges icons.
void set_mobile_font_scale(double scale)
Sets how much the Mobile state enlarges font sizes (see
VApp::kMobileFontScale, the default).
It works like set_mobile_icon_scale().
double mobile_font_scale()
Returns how much the Mobile state enlarges font sizes.
void set_mobile_metric_scale(double scale)
Sets how much the Mobile state enlarges the other pixel sizes, like
spacing, padding, and corner radii (see
VApp::kMobileMetricScale, the
default).
It works like set_mobile_icon_scale().
apply_mobile_scale() lists the
sizes that each scale covers.
double mobile_metric_scale()
Returns how much the Mobile state enlarges the other pixel sizes.
void dispatch(const std::string & path, const std::string & event)
Delivers an event from the node at path, like a click, to the
handler that the app installed for it.
event |
When | Handler |
|---|---|---|
| "click" | The user clicks the node | bind_click() |
| "input: |
The user edits an Editor, with its text | set_editor_input_handler() |
| "select: |
The user picks a Combo Box option | set_combo_input_handler() |
| "scan: |
A Scanner reads a QR code, with its text | set_scan_result_handler() |
| "scanstatus: |
A Scanner's camera changes, like "denied" | set_scan_status_handler() |
The handlers are VApp's. The node's value changes
before its handler runs, like an Editor's text or a Check Box's
Checked state, so the handler reads the new one. A click on a theme
button switches the theme instead, and one on a list action button
runs the list's action handler. Picking the option that's already
selected, or one that the Combo Box doesn't offer, does nothing.
Clicks on theme buttons, Check Boxes, and list action buttons are routed by the last render tree built, so render before delivering them. Everything after the first colon is the value, so a scanned text can hold colons of its own.
bool press_back()
Android only: Reports a press of the system back button, which
takes one step back in the app (see
BackHandler).
Returns whether the app took a step. On false, including when the
app installed no back handler, the platform handles back itself by
leaving the app.
bool handles_back()
Android only: Returns whether a press of the system back button would take a step back in the app, without changing anything.
Android asks after every update, so that a press that would leave the app shows the system's back preview.
bool on_scroll(double delta)
Reports that a scroll area moved by delta (px), positive when
scrolling down, which hides or shows the controls, like the titlebar
at the bottom of a Narrow window.
Scrolling down by
VApp::kScrollHideThreshold in all
turns on the ControlsHidden state, and scrolling up as far turns it
off. It does nothing unless the Narrow state is on. Returns whether
the state changed, so that the platform renders only then.
bool reveal_controls()
Shows the controls that on_scroll() hid, like when the user scrolls
past the top of a page.
Returns whether they were hidden, so that the platform renders only then.
bool has_editor_value(const std::string & path)
Returns whether the Editor at path has a value for
VApp::editor_text(), from the user's typing
or from the app.
A platform that rebuilds an Editor's widget, like after its section
was hidden, fills it with that value when there is one, rather than
its bound text, so that unsaved edits stay. An empty value counts, so
editor_text() returning "" can't tell the two apart.
void set_render_handler(std::function<void ()> handler)
Installs the handler that renders when
request_render() asks, like by scheduling one
render for the UI thread's next turn.
void request_render()
Asks for a render through the handler that set_render_handler()
installed, or does nothing without one.
Platform code calls it after running an app callback outside of an
event, like an http() reply or a timer, so that the callback's
changes show.
RenderNode build_render_tree()
Builds the render tree from the root style, with the app's binds and
the active theme applied (see RenderNode).
It's for callers that use the whole tree each time, like a test or a
static site renderer. Unlike render_patches(), it doesn't change
what the next patches compare against. Returns an empty node when the
root style isn't loaded.
std::string render_tree_json()
Returns build_render_tree()'s tree as JSON, for platforms whose
widgets aren't in C++, like web and Android.
int render_patches()
Returns what changed since the last call, as patches that the platform
applies to its widgets (see Patch).
The first call returns one patch that inserts the whole tree. Later
calls compare a new render tree with the last one. Each
VApp::push_editor_text() since the
last call adds a patch at the end.
std::string render_patches_json()
Returns render_patches()'s patches as JSON, for platforms whose
widgets aren't in C++, like web and Android.
bool set_active_theme(const std::string & id)
Makes the loaded theme with id active, like
"Dark (huntrsoftwarellc)".
Returns false, and keeps the active theme, when no loaded theme has
that id. The new theme shows at the next render.
std::string add_theme_json(const std::string & json)
Loads a theme from the text of its .json file, like one that the
user imported, and returns its id, or "" when the text isn't a theme.
A theme with the same id as a loaded one replaces it. The theme shows at the next render, like as a new button in the theme picker.
bool remove_theme(const std::string & id)
Unloads the theme with id, like one that the user removed.
When it's the active theme, another loaded theme becomes active
first. Returns false, and changes nothing, when no loaded theme has
that id or it's the only one.
void set_theme_changed_handler(std::function<void (const std::string &)> handler)
Installs the handler that runs with the new id each time the active theme changes, like to save the user's choice for the next launch.
It runs for a click on a theme button, set_active_theme(),
remove_theme() of the active theme, and init(). Install it before
init() to hear about the theme that init() picks too.