Display Messages API
The User Interface API provides different possibilities to display messages to the user.
Output Window
The most common approach is to display messages in the default output window of the frontend.
To display a message use the displayMessage()
method of the OTServiceFoundation/UIComponent
if the Frontend is connected.
1void MyApplication::uiConnected(components::UiComponent * _ui) {
2 _ui->displayMessage("Hello World!");
3}
Styled text messages may also be displayed in the output window. To do so simpy send the StyledTextBuilder to the Frontend. Read the Styled Text Builder documentation for code examples.
1#include "OTGui/StyledTextBuilder.h"
2#include "OTServiceFoundation/UiComponent.h"
3
4void MyApplication::uiConnected(components::UiComponent * _ui) {
5 ot::StyledTextBuilder myMessage;
6 // Construct the message
7 // ...
8
9 // Send the request
10 _ui->displayStyledMessage(myMessage);
11}
Styled Text Builder
The StyledTextBuilder
can be used to create a text output with different character format and color settings for one string.
The following example will give more clarity.
Example Code
1#include "OTGui/StyledTextBuilder.h"
2
3void foo(void) {
4 ot::StyledTextBuilder myMessage;
5 myMessage << "This message contains different styles:\n" <<
6 ot::StyledText::Bold << "- Bold Text\n" <<
7 ot::StyledText::Error << "- Bold Error Colored Text\n" << ot::StyledText::ClearStyle <<
8 ot::StyledText::Italic << "- Italic Text\n" <<
9 ot::StyledText::Bold << "- Bold and Italic Text\n" << ot::StyledText::ClearStyle <<
10 "and other combinations of styled color and character format.";
11}
Output of the code example:
This message contains different styles:
- Bold Text
- Bold Error Colored Text
- Italic Text
- Bold and Italic Text
and other combinations of styled color and character format.
The color references used in the StyledText are used to reference a ColorStyleValue
in the currently set ColorStyle
of the frontend.