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

Function main

examples/Desktop.cpp:6–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <SFML/Graphics.hpp>
5
6int main() {
7 sf::RenderWindow render_window( sf::VideoMode( { 800, 600 } ), "SFGUI Desktop Example" );
8
9 // Create an SFGUI. This is required before doing anything with SFGUI.
10 sfg::SFGUI sfgui;
11
12 // We have to do this because we don't use SFML to draw.
13 render_window.resetGLStates();
14
15 // Init.
16 sfg::Desktop desktop;
17 desktop.SetProperty( "Button#create_window", "FontSize", 18.f );
18
19 //// Main window ////
20 // Widgets.
21 auto main_window = sfg::Window::Create();
22 main_window->SetTitle( "SFGUI Desktop Example" );
23
24 auto intro_label = sfg::Label::Create( "Click on \"Create window\" to create any number of new windows." );
25 auto create_window_button = sfg::Button::Create( "Create window" );
26 create_window_button->SetId( "create_window" );
27
28 // Layout.
29 auto main_box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.f );
30 main_box->Pack( intro_label, false );
31 main_box->Pack( create_window_button, false );
32
33 main_window->Add( main_box );
34 desktop.Add( main_window );
35
36 auto count = 0u;
37
38 // Signals.
39 create_window_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&count, &desktop, &main_window] {
40 ++count;
41
42 // Create a new window.
43 auto window = sfg::Window::Create();
44
45 window->SetTitle( "A new window (" + std::to_string( count ) + ")" );
46
47 // Widgets.
48 auto destroy_button = sfg::Button::Create( "Destroy" );
49 auto front_button = sfg::Button::Create( "Main window to front" );
50
51 // Layout.
52 auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.f );
53 box->Pack( sfg::Label::Create( "This is a newly created window, from runtime, interactively." ), false );
54 box->Pack( sfg::Label::Create( "You can move me around, try it!" ), false );
55 box->Pack( sfg::Label::Create( "Or click the button below to destroy me. :-(" ), false );
56 box->Pack( destroy_button, false );
57 box->Pack( front_button, false );
58
59 window->Add( box );
60 desktop.Add( window );
61
62 // Signals.
63 destroy_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&desktop] {

Callers

nothing calls this directly

Calls 14

SetPropertyMethod · 0.80
SetTitleMethod · 0.80
SetIdMethod · 0.80
PackMethod · 0.80
ConnectMethod · 0.80
GetActiveWidgetMethod · 0.80
BringToFrontMethod · 0.80
AddMethod · 0.45
GetParentMethod · 0.45
RemoveMethod · 0.45
HandleEventMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected