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

Function main

examples/Notebook.cpp:9–85  ·  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 Notebook 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 notebook.
24 auto notebook = sfg::Notebook::Create();
25
26 // Create a couple of buttons to populate the notebook.
27 auto button1 = sfg::Button::Create( "Hello" );
28 auto button2 = sfg::Button::Create( "World" );
29
30 // Add new pages to the notebook with respective tab labels
31 // containing solely the buttons as their children.
32 notebook->AppendPage( button1, sfg::Label::Create( "Page 1" ) );
33 notebook->AppendPage( button2, sfg::Label::Create( "Page 2" ) );
34 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 3" ) );
35 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 4" ) );
36 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 5" ) );
37 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 6" ) );
38 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 7" ) );
39 notebook->AppendPage( sfg::Label::Create(), sfg::Label::Create( "Page 8" ) );
40
41 notebook->SetScrollable( true );
42 notebook->SetRequisition( sf::Vector2f( 200.f, 0.f ) );
43
44 // Add the notebook to the window.
45 window->Add( notebook );
46
47 sf::Clock clock;
48
49 // Update an initial time to construct the GUI before drawing begins.
50 // This makes sure that there are no frames in which no GUI is visible.
51 window->Update( 0.f );
52
53 // Start the game loop
54 while ( app_window.isOpen() ) {
55 // Process events
56 while ( const std::optional event = app_window.pollEvent() ) {
57 // Handle events
58 window->HandleEvent( *event );
59
60 // Close window : exit
61 if ( event->is<sf::Event::Closed>() ) {
62 return EXIT_SUCCESS;
63 }
64 }
65
66 // Update the GUI every 5ms

Callers

nothing calls this directly

Calls 9

SetTitleMethod · 0.80
AppendPageMethod · 0.80
SetScrollableMethod · 0.80
SetRequisitionMethod · 0.80
AddMethod · 0.45
UpdateMethod · 0.45
HandleEventMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected