Using lambda expressions with CEGUI

By on June 22, 2013

C++ lambdas is just another name for anonymous methods, which can be defined within another method. It’s particularly useful for callback methods.

With CEGUI, it’s easy to define a callback for a pushbutton like this:

// Exit button
	CEGUI::PushButton* button = static_cast<CEGUI::PushButton*>(m_WindowManager->createWindow("TaharezLook/Button" ));
	button->setPosition(CEGUI::UVector2(cegui_reldim(0.40f), cegui_reldim( 0.50f)));
	button->setSize( buttonSize );

	auto handleExitClicked = [&] ( const CEGUI::EventArgs & args ) -> bool
		// Send message

		return true;

	button->subscribeEvent( button->EventMouseClick, handleExitClicked );


This is just a simple example on how to use lambdas with CEGUI.

Posted in: coding
Tagged: , ,


Be the first to comment.

Leave a Reply