Coherent UI provides support for customization of IO handling using the url protocol coui. Any resource that is loaded via the coui protocol is going to be loaded via the Coherent::UI::FileHandler
interface provided to CreateViewContext
.
If a view is loaded via the coui protocol and all its resources are referenced with relative URLs then all the resources are loaded via coui too.
The default implementation of Coherent::UI::FileHandler
takes the name of the resource and uses it as path relative to the current working directory. For example coui://ui/hud.html?first_run=1
will be resolved to <current_working_directory>/ui/hud.html
For a sample using custom IO see Sample 01 - Custom File Handler Tutorial
coui
links are parsed as standard URLs and they are expected to be of the appropriate format. This means that coui
links can have host, port, path, etc. components. The host component is mandatory and the URL parsed forbids paths outside the host directory.
This can lead to unexpected behavior is the coui
link is formatted incorrectly. Let's take for example the following directory structure:
If index.html
refers to image.jpg
using <img src="../Images/image.jpg" />
and the coui
link used is coui://Html/index.html
, the image will not be loaded. This is because the host is assumed to be Html
and the referenced resource is outside the host.
We recommend placing all your UI resources in a single folder acting as a host (or if that's not possible, using an artificial host such as coui://MyArtificialHost/Html/index.html
) to avoid such cases. The example could be fixed using a link such as coui://Resources/Html/index.html
. The referenced resource would thus become coui://Resources/Images/image.jpg
because it would still be in the host directory, Resources. When using the default handler for filesystem assets, placing the UI resources in a single folder is the way to go (Resources in this example). In the case where Resources is an artificial host, the URL should be parsed to suit your needs in the file handler's ReadFile
and WriteFile
methods to obtain the correct asset path.
Coherent::UI::FileHandler
, Coherent::UI::ResourceResponce
and Coherent::UI::ResponseData
allow to easily to implement asynchronous loading of resources. The only special moment is that
Coherent::UI::ResourceResponse::SignalSuccess
Coherent::UI::ResourceResponse::SignalFailure
Coherent::UI::ResourceData::SignalSuccess
Coherent::UI::ResourceData::SignalFailure
MUST be called on the thread that is doing Coherent::UI::ViewContext::Update