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

Function main

examples/CustomWidget.cpp:224–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222};
223
224int main() {
225 // Create SFML's window.
226 sf::RenderWindow render_window( sf::VideoMode( { 800, 600 } ), "Custom Widget" );
227
228 // Create an SFGUI. This is required before doing anything with SFGUI.
229 sfg::SFGUI sfgui;
230
231 // Create our custom widget.
232 auto custom_widget = MyCustomWidget::Create( "Custom Text" );
233
234 // Create a simple button and connect the click signal.
235 auto button = sfg::Button::Create( "Button" );
236 button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&custom_widget] { custom_widget->SetLabel( L"You just clicked the other guy!" ); } );
237
238 // Create a vertical box layouter with 5 pixels spacing and add our custom widget and button
239 // and button to it.
240 auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.0f );
241 box->Pack( custom_widget );
242 box->Pack( button, false );
243
244 // Create a window and add the box layouter to it. Also set the window's title.
245 auto window = sfg::Window::Create();
246 window->SetTitle( "Custom Widget" );
247 window->Add( box );
248
249 // Create a desktop and add the window to it.
250 sfg::Desktop desktop;
251 desktop.Add( window );
252
253 // We're not using SFML to render anything in this program, so reset OpenGL
254 // states. Otherwise we wouldn't see anything.
255 render_window.resetGLStates();
256
257 // Main loop!
258 sf::Clock clock;
259
260 while( render_window.isOpen() ) {
261 // Event processing.
262 while( const std::optional event = render_window.pollEvent() ) {
263 desktop.HandleEvent( *event );
264
265 // If window is about to be closed, leave program.
266 if( event->is<sf::Event::Closed>() ) {
267 return 0;
268 }
269 }
270
271 // Update SFGUI with elapsed seconds since last call.
272 desktop.Update( clock.restart().asSeconds() );
273
274 // Rendering.
275 render_window.clear();
276 sfgui.Display( render_window );
277 render_window.display();
278 }
279
280 return 0;
281}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected