Urho3D Wiki
Edit Page
GUI

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 17: Line 17:
 
// In LM_FREE the child elements of this window can be arranged freely.
 
// 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.
 
// In the other two they are arranged as a horizontal or vertical list.
  +
<br>
 
 
// Center this window in it's parent element.
 
// Center this window in it's parent element.
window_menu->SetAlignment(HA_CENTER,VA_CENTER);<br>window_menu->SetName("Window");<br>window_menu->SetColor(Color(.0,.15,.3,.5)); // you can use transparency
+
window_menu->SetAlignment(HA_CENTER,VA_CENTER);<br>
  +
window_menu->SetName("Window");<br>
  +
window_menu->SetColor(Color(.0,.15,.3,.5)); // you can use transparency
 
Adding a button to the window:
 
Adding a button to the window:
  +
Button* button=new Button(context);<br>
Button* button=new Button(context);<br>button->SetPosition(10,350); // the position inside and relative to the parent<br>button->SetFixedSize(135,40);<br>button->SetName("Button"); // not required<br>button->SetStyleAuto(); // this is (weirdly) sometimes required for UI elements<br>button->SetOpacity(0.75); // transparency<br>
 
  +
button->SetPosition(10,350); // the position inside and relative to the parent<br>
  +
button->SetFixedSize(135,40);<br>
  +
button->SetName("Button"); // not required<br>
  +
button->SetStyleAuto(); // this is (weirdly) sometimes required for UI elements<br>
  +
button->SetOpacity(0.75); // transparency<br>
 
 
// buttons don't have a text by itself, a text needs to be added as a child
 
// buttons don't have a text by itself, a text needs to be added as a child
 
Text* t=new Text(context);
 
Text* t=new Text(context);
  +
// setting a font is required<br>
// setting a font is required<br>t->SetFont(cache->GetResource<nowiki><Font>("Fonts/Anonymous Pro.ttf"),20);</nowiki><br>t->SetHorizontalAlignment(HA_CENTER);<br>t->SetVerticalAlignment(VA_CENTER);<br>t->SetName("Text");<br>t->SetText("Play");<br>t->SetStyle("Text");<br>button->AddChild(t);<br>
 
  +
t->SetFont(cache->GetResource<nowiki><Font>("Fonts/Anonymous Pro.ttf"),20);</nowiki><br>
  +
t->SetHorizontalAlignment(HA_CENTER);<br>
  +
t->SetVerticalAlignment(VA_CENTER);<br>
  +
t->SetName("Text");<br>
  +
t->SetText("Play");<br>
  +
t->SetStyle("Text");<br>
  +
button->AddChild(t);<br>
  +
<br>
 
window_menu->AddChild(button);
 
window_menu->AddChild(button);
// connect the button press event to a function<br>SubscribeToEvent(button,E_RELEASED,HANDLER(gs_main_menu,HandlePlayPressed));
+
// connect the button press event to a function<br>
  +
SubscribeToEvent(button,E_RELEASED,HANDLER(gs_main_menu,HandlePlayPressed));

Please note that all contributions to the Urho3D Wiki are considered to be released under the CC-BY-SA

Cancel Editing help (opens in new window)