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

Function main

examples/Spinner.cpp:9–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <SFML/Graphics.hpp>
8
9int main() {
10 // Create the main SFML window
11 sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Spinner 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 our spinner
24 auto spinner = sfg::Spinner::Create();
25
26 // Set how big the spinner should be
27 spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) );
28
29 // Create a button and connect the click signal.
30 auto button = sfg::Button::Create( "Toggle" );
31 button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&spinner] {
32 // If the spinner is spinning...
33 if( spinner->Started() ) {
34 // ... stop the spinner.
35 spinner->Stop();
36
37 return;
38 }
39
40 // ... otherwise start it.
41 spinner->Start();
42 } );
43
44 // Create a horizontal box layouter and add widgets to it.
45 auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL, 5.0f );
46 box->Pack( spinner );
47 box->Pack( button, false );
48
49 // Add the box to the window.
50 window->Add( box );
51
52 // Our clock to make the spinner spin ;)
53 sf::Clock clock;
54
55 // Update an initial time to construct the GUI before drawing begins.
56 // This makes sure that there are no frames in which no GUI is visible.
57 window->Update( 0.f );
58
59 // Start the game loop
60 while ( app_window.isOpen() ) {
61 // Process events
62 while ( const std::optional event = app_window.pollEvent() ) {
63 // Handle events
64 window->HandleEvent( *event );
65
66 // Close window : exit

Callers

nothing calls this directly

Calls 12

SetTitleMethod · 0.80
SetRequisitionMethod · 0.80
ConnectMethod · 0.80
StartedMethod · 0.80
StopMethod · 0.80
StartMethod · 0.80
PackMethod · 0.80
AddMethod · 0.45
UpdateMethod · 0.45
HandleEventMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected