| 7 | #include <SFML/Graphics.hpp> |
| 8 | |
| 9 | int main() { |
| 10 | // Create the main SFML window |
| 11 | sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Box Example", sf::Style::Titlebar | sf::Style::Close ); |
| 12 | |
| 13 | // We have to do this because we don't use SFML to draw. |
| 14 | app_window.resetGLStates(); |
| 15 | |
| 16 | // Create an SFGUI. This is required before doing anything with SFGUI. |
| 17 | sfg::SFGUI sfgui; |
| 18 | |
| 19 | // Create our main SFGUI window |
| 20 | auto window = sfg::Window::Create(); |
| 21 | window->SetTitle( "Title" ); |
| 22 | |
| 23 | // Since only being able to add one widget to a window is very limiting |
| 24 | // there are Box widgets. They are a subclass of the Container class and |
| 25 | // can contain an unlimited amount of child widgets. Not only that, they |
| 26 | // also have the ability to lay out your widgets nicely. |
| 27 | |
| 28 | // Create the box. |
| 29 | // For layout purposes we must specify in what direction new widgets |
| 30 | // should be added, horizontally or vertically. |
| 31 | auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL ); |
| 32 | |
| 33 | auto button1 = sfg::Button::Create(); |
| 34 | auto button2 = sfg::Button::Create(); |
| 35 | auto label = sfg::Label::Create(); |
| 36 | |
| 37 | button1->SetLabel( "Foo" ); |
| 38 | button2->SetLabel( "Bar" ); |
| 39 | label->SetText( "Baz" ); |
| 40 | |
| 41 | // To add our widgets to the box we use the Pack() method instead of the |
| 42 | // Add() method. This makes sure the widgets are added and layed out |
| 43 | // properly in the box. |
| 44 | box->Pack( button1 ); |
| 45 | box->Pack( label ); |
| 46 | box->Pack( button2 ); |
| 47 | |
| 48 | // Just as with the window we can set the spacing between widgets |
| 49 | // withing a box. |
| 50 | box->SetSpacing( 5.f ); |
| 51 | |
| 52 | // Finally we add our box to the window as it's only child. |
| 53 | // Notice that we don't have to add the children of a box to it's parent |
| 54 | // Because all children and grandchildren and .... are automatically |
| 55 | // considered descendents of the parent. |
| 56 | window->Add( box ); |
| 57 | |
| 58 | // Start the game loop |
| 59 | while ( app_window.isOpen() ) { |
| 60 | // Process events |
| 61 | while ( const std::optional event = app_window.pollEvent() ) { |
| 62 | // Handle events |
| 63 | window->HandleEvent( *event ); |
| 64 | |
| 65 | // Close window : exit |
| 66 | if ( event->is<sf::Event::Closed>() ) { |
nothing calls this directly
no test coverage detected