MCPcopy Create free account
hub / github.com/TankOs/SFGUI / main

Function main

examples/HelloWorld.cpp:6–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <SFML/Graphics.hpp>
5
6int main() {
7 // Create SFML's window.
8 sf::RenderWindow render_window( sf::VideoMode( { 800, 600 } ), "Hello world!" );
9
10 // Create an SFGUI. This is required before doing anything with SFGUI.
11 sfg::SFGUI sfgui;
12
13 // Create the label.
14 auto label = sfg::Label::Create( "Hello world!" );
15
16 // Create a simple button and connect the click signal.
17 auto button = sfg::Button::Create( "Greet SFGUI!" );
18 button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [label] { label->SetText( "Hello SFGUI, pleased to meet you!" ); } );
19
20 // Create a vertical box layouter with 5 pixels spacing and add the label
21 // and button to it.
22 auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.0f );
23 box->Pack( label );
24 box->Pack( button, false );
25
26 // Create a window and add the box layouter to it. Also set the window's title.
27 auto window = sfg::Window::Create();
28 window->SetTitle( "Hello world!" );
29 window->Add( box );
30
31 // Create a desktop and add the window to it.
32 sfg::Desktop desktop;
33 desktop.Add( window );
34
35 // We're not using SFML to render anything in this program, so reset OpenGL
36 // states. Otherwise we wouldn't see anything.
37 render_window.resetGLStates();
38
39 // Main loop!
40 sf::Clock clock;
41
42 while( render_window.isOpen() ) {
43 // Event processing.
44 while( const std::optional event = render_window.pollEvent() ) {
45 desktop.HandleEvent( *event );
46
47 // If window is about to be closed, leave program.
48 if( event->is<sf::Event::Closed>() ) {
49 return 0;
50 }
51 }
52
53 // Update SFGUI with elapsed seconds since last call.
54 desktop.Update( clock.restart().asSeconds() );
55
56 // Rendering.
57 render_window.clear();
58 sfgui.Display( render_window );
59 render_window.display();
60 }
61
62 return 0;
63}

Callers

nothing calls this directly

Calls 9

ConnectMethod · 0.80
PackMethod · 0.80
SetTitleMethod · 0.80
SetTextMethod · 0.45
AddMethod · 0.45
HandleEventMethod · 0.45
UpdateMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected