sebastian.vesenmayer Posted June 12, 2018 Share Posted June 12, 2018 Hi community, the documentation for widget usages with c++ is not very big at the moment and most things I have to try by myself which is very time consuming because there are no examples. I hope this will get better. Currently I am stuck with WidgetHBox class. Can anybody tell me how to connect WidgetLabels to them with c++ code. A small example would be great. Thanks Sebastian Link to comment
fox Posted June 13, 2018 Share Posted June 13, 2018 Hi Sebastian! Unfortunately not all types of widgets are currently supplemented with C++ code snippets. All of them are inherited from the Widget class, so you can use addChild() method to add children to some widget. Here is a simple example demonstrating how to add 2 labels to a horizontal box widget: // AppWorldLogic.cpp // incluging the required library #include <UnigineUserInterface.h> /*...*/ using namespace Unigine; GuiPtr gui; WidgetLabelPtr widget_label1; WidgetLabelPtr widget_label2; WidgetHBoxPtr h_box; /*...*/ int AppWorldLogic::init() { /*...*/ // getting a GUI pointer gui = Gui::get(); // creating a horizontal box widget and setting up its parameters h_box = WidgetHBox::create(gui, 150, 20); h_box->setPosition(10, 30); h_box->setBackground(1); h_box->setColor(Math::vec4(1.0f, 0.0f, 0.0f, 1.0f)); // creating a label widget and setting a tooltip for it widget_label1 = WidgetLabel::create(gui, "Label1"); widget_label1->setToolTip("I'm Label1 !"); // creating another label widget and setting a tooltip for it widget_label2 = WidgetLabel::create(gui, "Label2"); widget_label2->setToolTip("I'm Label2 !"); // adding two labels to the horizontal box h_box->addChild(widget_label1->getWidget(), Gui::ALIGN_LEFT); h_box->addChild(widget_label2->getWidget(), Gui::ALIGN_LEFT); // adding the horizontal box to the GUI gui->addChild(h_box->getWidget(), Gui::ALIGN_OVERLAP | Gui::ALIGN_FIXED); return 1; } /*...*/ int AppWorldLogic::shutdown() { // performing some cleanup widget_label1.clear(); widget_label2.clear(); h_box.clear(); gui.clear(); return 1; } That's how it looks: There are code snippets for some of the Widget classes available in the corresponding articles of our documentation (such as WidgetButton, WidgetCheckBox, etc.), as well as a set of examples, that can be found in the C++ API/Widgets samples might come in handy. The following links may also be useful: UI creation example Information on UI files Hope this helps! Thanks! Link to comment
sebastian.vesenmayer Posted June 13, 2018 Author Share Posted June 13, 2018 Hi Fox, thank you for your fast reply, I will try it :) Link to comment
sebastian.vesenmayer Posted June 13, 2018 Author Share Posted June 13, 2018 Thank you, works perfect! Link to comment
Recommended Posts