Contains a set of options to construct the internal webview with. More...
#include <mostlyharmless_WebviewBase.h>
Public Attributes | |
bool | enableDebug { false } |
std::function< std::optional< Resource >(const std::string &)> | contentProvider { nullptr } |
std::optional< std::string > | initScript {} |
Contains a set of options to construct the internal webview with.
std::function<std::optional<Resource>(const std::string&)> mostly_harmless::gui::WebviewBase::Options::contentProvider { nullptr } |
If not serving from ram, leave this as a nullptr, and call navigate
instead.
If serving the content from ram, the webview will query the backend for files to load, with a call to this lambda.
As mentioned in the docs for Resource, you should load these at construction, and keep a map route:Resource
on hand. This lambda then, should query that map for the requested route, and return the associated resource if it exists, std::nullopt otherwise. Assuming a std::unordered_map<std::string, mostly_harmless::gui::WebviewEditor::Resource>
called m_resources
, an implementation could be along the lines of:
bool mostly_harmless::gui::WebviewBase::Options::enableDebug { false } |
If true, the user will be able to right click / inspect element / etc. If false, that behaviour is disabled.
std::optional<std::string> mostly_harmless::gui::WebviewBase::Options::initScript {} |
An optional (javascript) script to be executed before the page loads. If you're hosting from RAM, prefer this to the internal webview's addInitScript function - this is because internally in choc, navigate is called before the init script is added, meaning that a script added with addInitScript won't execute until a refresh. This arg sidesteps that, by passing it into the internal webview's constructor.