| 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 Label 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 | // Create the label. |
| 24 | auto label = sfg::Label::Create(); |
| 25 | |
| 26 | // Set the text of the label. |
| 27 | label->SetText( "Hello World!\nAnother Line" ); |
| 28 | |
| 29 | // Add the label to the window. |
| 30 | |
| 31 | // Windows are a subclass of the Bin widget type. Bins are only |
| 32 | // allowed to contain one child widget so adding more than 1 widget |
| 33 | // to a window will result in a warning and no effect. For adding more |
| 34 | // widgets to a window refer to the Box example later on. For a full |
| 35 | // widget hierarchy refer to the documentation. |
| 36 | window->Add( label ); |
| 37 | |
| 38 | // Start the game loop |
| 39 | while ( app_window.isOpen() ) { |
| 40 | // Process events |
| 41 | while ( const std::optional event = app_window.pollEvent() ) { |
| 42 | // Handle events |
| 43 | window->HandleEvent( *event ); |
| 44 | |
| 45 | // Close window : exit |
| 46 | if ( event->is<sf::Event::Closed>() ) { |
| 47 | return EXIT_SUCCESS; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Update the GUI, note that you shouldn't normally |
| 52 | // pass 0 seconds to the update method. |
| 53 | window->Update( 0.f ); |
| 54 | |
| 55 | // Clear screen |
| 56 | app_window.clear(); |
| 57 | |
| 58 | // Draw the GUI |
| 59 | sfgui.Display( app_window ); |
| 60 | |
| 61 | // Update the window |
| 62 | app_window.display(); |
| 63 | } |
| 64 | |
| 65 | return EXIT_SUCCESS; |
| 66 | } |