RmlUi from C++¶
The classes are the same in C++: RmlRegion, RmlContext,
RmlDocument, RmlElement, RmlEvent and
RmlInputHandler, declared in rmlRegion.h, rmlContext.h and so
on. A C++ program links the RmlUi component of the CMake package, which
brings the RmlUi library with it:
find_package(Acron REQUIRED COMPONENTS Framework RmlUi)
add_executable(mygame main.cxx)
target_link_libraries(mygame PRIVATE Acron::Framework::p3framework Acron::RmlUi::p3rmlui)
The same works with the web and Android SDKs, whose executable helpers
(acron_web_executable, acron_android_executable) link the
framework already; nothing has to be registered, the module is set up on first
use. RmlUi needs C++17, which the helpers ask for. The Wii SDK has no RmlUi:
its renderer has no programmable shaders, which RmlUi’s rendering is written
for.
A document, its input, and a listener:
PT(RmlRegion) region = RmlRegion::make("menu", window->get_graphics_output());
region->set_sort(20);
PT(RmlInputHandler) input = new RmlInputHandler("rml-input");
window->get_mouse().attach_new_node(input);
region->set_input_handler(input);
PT(RmlDocument) doc = region->get_context()->load_document("ui/menu.rml");
doc->show();
doc->get_element_by_id("play")->add_event_listener("click", [](RmlEvent &event) {
start_game();
});
RmlElement.add_event_listener() takes a function (a lambda) in C++, as
well as a CallbackObject; the RmlEvent is only valid during
the call. RmlContext.load_document_from_memory() loads a document held
in a string, which saves shipping files with a small program.
The samples/rmlui-menu program is a complete example: a menu whose buttons
a click, a tap or a gamepad’s A button presses, with a list that scrolls by
dragging, built from one CMakeLists.txt for the desktop, the web and
Android.