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

Function main

examples/Layout.cpp:9–112  ·  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 Layout 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( "Resize me!" );
22
23 // Create a box with 20 pixels spacing.
24 auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 20.f );
25
26 // Create some buttons.
27 auto button_aligned = sfg::Button::Create( "Aligned 0.8f right and bottom" );
28 auto button_fixed = sfg::Button::Create( "Fixed at (200, 50)" );
29
30 // Create a fixed.
31 auto fixed = sfg::Fixed::Create();
32
33 // Add button_fixed to the fixed at (200, 50).
34 fixed->Put( button_fixed, sf::Vector2f( 200.f, 50.f ) );
35
36 // Add our fixed to the box and set not to expand.
37 box->Pack( fixed, false, true );
38
39 // Create a separator.
40 auto separator = sfg::Separator::Create( sfg::Separator::Orientation::HORIZONTAL );
41
42 // Add separator to box and set not to expand.
43 box->Pack( separator, false, true );
44
45 // Create an alignment.
46 auto alignment = sfg::Alignment::Create();
47
48 // Because we want to align our button horizontally, we need
49 // to place our alignment in a horizontal box set to expand and fill.
50 auto alignment_box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );
51 alignment_box->Pack( alignment, true, true );
52
53 // Add button_aligned to the alignment.
54 alignment->Add( button_aligned );
55
56 // Set scaling parameters.
57 // Scaling sets how much of the total space in the alignment
58 // the child gets to fill up. 1.0f for x and y would mean the
59 // child gets to use the whole space. Setting it to 0.0f for
60 // x and y makes the child get as little space as possible.
61 alignment->SetScale( sf::Vector2f( .0f, .0f ) );
62
63 // Set alignment parameters.
64 // Alignment aligns the child widget within the alignment's area.
65 // 0.0f for x aligns to the left, 1.0f for x aligns to the right.
66 // 0.0f for y aligns to the top, 1.0f for y aligns to the bottom.

Callers

nothing calls this directly

Calls 10

SetTitleMethod · 0.80
PutMethod · 0.80
PackMethod · 0.80
SetScaleMethod · 0.80
SetAlignmentMethod · 0.80
AddMethod · 0.45
HandleEventMethod · 0.45
UpdateMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected