Urho3D Wiki
Advertisement

Urho's internal GUI system is rather minimal at the moment. There's not much one can do with it and it's made rather complicated (at least when one is used to real big GUI systems like Qt). USP uses the internal GUI, see the game state classes (gs_*.cpp) for the GUI usage there (https://github.com/gawag/Urho-Sample-Platformer/tree/master/Source). This page tries to explain some general stuff and common pitfalls.

GUI example:

USP GUI1
USP GUI2

[There may be wiki articles in the future on how to use other GUI systems inside Urho. The next Urho sample project is quite likely to use something else.]

Urho uses the typical hierarchical UI system of elements being positioned inside and relative to their parents.

Making a window:

Window* window_menu=new Window(context);
// Make the window a child of the root element, which fills the whole screen.
GetSubsystem<UI>()->GetRoot()->AddChild(window_menu);
window_menu->SetSize(300,400);
window_menu->SetLayout(LM_FREE,0,IntRect(10,10,10,10)); // Urho has three layouts: LM_FREE, LM_HORIZONTAL and LM_VERTICAL. // In LM_FREE the child elements of this window can be arranged freely. // In the other two they are arranged as a horizontal or vertical list. // Center this window in it's parent element. window_menu->SetAlignment(HA_CENTER,VA_CENTER);
window_menu->SetName("Window");
window_menu->SetColor(Color(.0,.15,.3,.5)); // you can use transparency

Adding a button to the window:

Button* button=new Button(context);
button->SetPosition(10,350); // the position inside and relative to the parent
button->SetFixedSize(135,40);
button->SetName("Button"); // not required
button->SetStyleAuto(); // this is (weirdly) sometimes required for UI elements
button->SetOpacity(0.75); // transparency
// buttons don't have a text by itself, a text needs to be added as a child Text* t=new Text(context); // setting a font is required
t->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"),20);
t->SetHorizontalAlignment(HA_CENTER);
t->SetVerticalAlignment(VA_CENTER);
t->SetName("Text");
t->SetText("Play");
t->SetStyle("Text");
button->AddChild(t);
window_menu->AddChild(button); // connect the button press event to a function
SubscribeToEvent(button,E_RELEASED,HANDLER(gs_main_menu,HandlePlayPressed));
Advertisement