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

Method CalculateRequisition

examples/CustomWidget.cpp:152–167  ·  view source on GitHub ↗

In order for SFGUI to know how much space your widget takes up and position other widgets accordingly, it calls the CalculateRequisition() method. This method should return the total screen size of the widget.

Source from the content-addressed store, hash-verified

150 // CalculateRequisition() method. This method should return the
151 // total screen size of the widget.
152 sf::Vector2f CalculateRequisition() override {
153 // The size of a widget might depend on the current properties
154 const std::string& font_name( sfg::Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
155 unsigned int font_size( sfg::Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
156 const sf::Font& font( *sfg::Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );
157
158 // The current engine can also be used to retrieve font metric
159 // data size as size or line height.
160 auto requisition = sfg::Context::Get().GetEngine().GetTextStringMetrics( m_label, font, font_size );
161 requisition.y = sfg::Context::Get().GetEngine().GetFontLineHeight( font, font_size );
162
163 requisition *= 3.f;
164 requisition += sf::Vector2f( 20.f, 20.f );
165
166 return requisition;
167 }
168
169 // You can override certain methods in order to be informed
170 // when certain events happen. This handler handles the state change

Callers

nothing calls this directly

Calls 2

GetTextStringMetricsMethod · 0.80
GetFontLineHeightMethod · 0.80

Tested by

no test coverage detected