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

Method CalculateRequisition

src/SFGUI/ComboBox.cpp:350–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350sf::Vector2f ComboBox::CalculateRequisition() {
351 float padding( Context::Get().GetEngine().GetProperty<float>( "ItemPadding", shared_from_this() ) );
352 const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
353 unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
354 const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );
355
356 // Determine highest needed width of all items.
357 sf::Vector2f metrics( 0.f, 0.f );
358 for ( IndexType item = 0; item < GetItemCount(); ++item ) {
359 metrics.x = std::max( metrics.x, Context::Get().GetEngine().GetTextStringMetrics( m_entries[static_cast<std::size_t>( item )], font, font_size ).x );
360 }
361
362 metrics.y = Context::Get().GetEngine().GetFontLineHeight( font, font_size );
363
364 // This is needed for the arrow.
365 metrics.x += metrics.y;
366
367 sf::Vector2f requisition(
368 metrics.x + 3 * padding,
369 metrics.y + 2 * padding
370 );
371
372 return requisition;
373}
374
375const std::string& ComboBox::GetName() const {
376 static const std::string name( "ComboBox" );

Callers

nothing calls this directly

Calls 2

GetTextStringMetricsMethod · 0.80
GetFontLineHeightMethod · 0.80

Tested by

no test coverage detected