This macro demonstrates simple openui5 panel, shown with RWebWindow.
#include <vector>
#include <string>
struct ComboBoxItem {
std::string fId;
std::string fName;
ComboBoxItem() = default;
ComboBoxItem(
const std::string &
id,
const std::string &
name) : fId(
id), fName(
name) {}
};
struct TestPanelModel {
std::string fSampleText;
std::vector<ComboBoxItem> fComboItems;
std::string fSelectId;
std::string fButtonText;
};
std::shared_ptr<ROOT::RWebWindow> window;
std::unique_ptr<TestPanelModel> model;
int sendcnt = 0;
void ProcessConnection(unsigned connid)
{
printf("connection established %u\n", connid);
window->Send(connid, std::string(
"MODEL:") +
json.Data());
}
void ProcessCloseConnection(unsigned connid)
{
printf("connection closed %u\n", connid);
}
void ProcessData(unsigned connid, const std::string &arg)
{
if (arg == "REFRESH") {
printf("Send model again\n");
model->fButtonText =
Form(
"Custom button %d", ++sendcnt);
window->Send(connid, std::string(
"MODEL:") +
json.Data());
} else if (arg.find("MODEL:") == 0) {
auto m = TBufferJSON::FromJSON<TestPanelModel>(arg.substr(6));
printf(
"New model, selected: %s\n",
m->fSelectId.c_str());
} else {
printf("Fail to decode model: %s\n", arg.c_str());
}
}
}
void webpanel()
{
model = std::make_unique<TestPanelModel>();
model->fSampleText = "This is openui5 widget";
model->fComboItems = {{"item1", "Text 1"}, {"item2", "Text 2"}, {"item3", "Text 3"}, {"item4", "Text 4"}};
model->fSelectId = "item2";
model->fButtonText = "Custom button";
window->SetPanelName("localapp.view.TestPanel");
window->SetCallBacks(ProcessConnection, ProcessData, ProcessCloseConnection);
window->SetGeometry(400, 500);
window->Show();
}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)