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

Function main

examples/Table.cpp:11–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <cstdint>
10
11int main() {
12 // Create the main SFML window
13 sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Table Example", sf::Style::Titlebar | sf::Style::Close );
14
15 // We have to do this because we don't use SFML to draw.
16 app_window.resetGLStates();
17
18 // Create an SFGUI. This is required before doing anything with SFGUI.
19 sfg::SFGUI sfgui;
20
21 // Create our main SFGUI window
22 auto window = sfg::Window::Create();
23 window->SetTitle( "Title" );
24
25 // Create our table.
26 auto table = sfg::Table::Create();
27
28 // Some demonstration buttons ;)
29 auto foo = sfg::Button::Create( "Foo" );
30 auto bar = sfg::Button::Create( "Bar" );
31 auto baz = sfg::Button::Create( "Baz" );
32 auto column_span = sfg::Button::Create( "Column Span" );
33 auto row_span = sfg::Button::Create( "Row Span" );
34
35 // Attach a widget to the table.
36 // The first parameter is the widget to attach.
37 //
38 // The second parameter tells the table how to place the widget.
39 // It is a 4-tuple (ignore the fact that it is a rect) containing
40 // in order: column index, row index, column span, row span.
41 // ( 0, 0, 1, 1 ) would mean 0th column, 0th row, occupy 1 column and 1 row.
42 //
43 // Similar to boxes you have optional packing options such as FILL and EXPAND.
44 // With tables you have 2 directions to pack, the first is the horizontal
45 // packing options and the second the vertical packing options.
46 //
47 // The last option is the padding you want to apply to the cell.
48 table->Attach( foo, sf::Rect<std::uint32_t>( { 0, 0 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) );
49
50 // Do the same for the other 4 widgets.
51 table->Attach( bar, sf::Rect<std::uint32_t>( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) );
52 table->Attach( baz, sf::Rect<std::uint32_t>( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) );
53 table->Attach( column_span, sf::Rect<std::uint32_t>( { 0, 3 }, { 2, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) );
54 table->Attach( row_span, sf::Rect<std::uint32_t>( { 1, 0 }, { 1, 3 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) );
55
56 // Because we told our cells to only expand horizontally,
57 // they will only resize if the size of the window changes horizontally.
58
59 // Add our table to the window
60 window->Add( table );
61
62 // Start the game loop
63 while ( app_window.isOpen() ) {
64 // Process events
65 while ( const std::optional event = app_window.pollEvent() ) {
66 // Handle events
67 window->HandleEvent( *event );
68

Callers

nothing calls this directly

Calls 7

SetTitleMethod · 0.80
AttachMethod · 0.80
AddMethod · 0.45
HandleEventMethod · 0.45
UpdateMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected