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

Method CalculateRequisition

src/SFGUI/Button.cpp:77–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77sf::Vector2f Button::CalculateRequisition() {
78 float padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) );
79 float spacing( Context::Get().GetEngine().GetProperty<float>( "Spacing", shared_from_this() ) );
80 const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
81 unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
82 const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );
83
84 auto requisition = Context::Get().GetEngine().GetTextStringMetrics( m_label, font, font_size );
85 requisition.y = Context::Get().GetEngine().GetFontLineHeight( font, font_size );
86
87 requisition.x += 2 * padding;
88 requisition.y += 2 * padding;
89
90 if( GetChild() ) {
91 requisition.x += GetChild()->GetRequisition().x;
92 requisition.y = std::max( requisition.y, GetChild()->GetRequisition().y + 2 * padding );
93
94 if( GetLabel().getSize() > 0 ) {
95 requisition.x += spacing;
96 }
97 }
98
99 return requisition;
100}
101
102const std::string& Button::GetName() const {
103 static const std::string name( "Button" );

Callers

nothing calls this directly

Calls 2

GetTextStringMetricsMethod · 0.80
GetFontLineHeightMethod · 0.80

Tested by

no test coverage detected