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

Function main

examples/Entry.cpp:9–106  ·  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 Entry Example", sf::Style::Titlebar | sf::Style::Close );
12
13 // Create an SFGUI. This is required before doing anything with SFGUI.
14 sfg::SFGUI sfgui;
15
16 // We have to do this because we don't use SFML to draw.
17 app_window.resetGLStates();
18
19 // Create our main SFGUI window
20 auto window = sfg::Window::Create();
21 window->SetTitle( "Title" );
22
23 // Create our box.
24 auto box = sfg::Box::Create( sfg::Box::Orientation::HORIZONTAL );
25
26 // Create a button.
27 auto button = sfg::Button::Create();
28 button->SetLabel( "Set" );
29
30 // Create a label.
31 auto label = sfg::Label::Create();
32 label->SetText( "no text yet" );
33
34 // Create our entry widget itself.
35 auto entry = sfg::Entry::Create();
36
37 // Connect the button.
38 button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&label, &entry] {
39 // When the button is clicked set the contents of the label
40 // to the contents of the entry widget.
41 label->SetText( entry->GetText() );
42 } );
43
44 // Until now all widgets only expanded to fit the text inside of it.
45 // This is not the case with the entry widget which can be empty
46 // but still has to have a reasonable size.
47 // To disable the automatic sizing of widgets in general you can
48 // use the SetRequisition() method. it takes an sf::Vector as it's
49 // parameter. Depending on which side you want to have a minimum size,
50 // you set the corresponding value in the vector.
51 // Here we chose to set the minimum x size of the widget to 80.
52 entry->SetRequisition( sf::Vector2f( 80.f, 0.f ) );
53
54 // Setting sizing back to automatic is as easy as setting
55 // x and y sizes to 0.
56
57 // Pack into box
58 box->Pack( entry );
59 box->Pack( button );
60 box->Pack( label );
61
62 // Set box spacing
63 box->SetSpacing( 5.f );
64
65 // Add our box to the window
66 window->Add( box );

Callers

nothing calls this directly

Calls 12

SetTitleMethod · 0.80
ConnectMethod · 0.80
SetRequisitionMethod · 0.80
PackMethod · 0.80
SetSpacingMethod · 0.80
SetLabelMethod · 0.45
SetTextMethod · 0.45
AddMethod · 0.45
UpdateMethod · 0.45
HandleEventMethod · 0.45
clearMethod · 0.45
DisplayMethod · 0.45

Tested by

no test coverage detected