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

Method CalculateRequisition

src/SFGUI/Label.cpp:173–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173sf::Vector2f Label::CalculateRequisition() {
174 const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
175 unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
176 const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );
177
178 auto metrics = Context::Get().GetEngine().GetTextStringMetrics( GetWrappedText(), font, font_size );
179 metrics.y = Context::Get().GetEngine().GetFontLineHeight( font, font_size );
180
181 sf::String wrapped_text( GetWrappedText() );
182 std::u32string text( wrapped_text.begin(), wrapped_text.end() );
183
184 std::size_t lines = 1;
185
186 do {
187 auto next_newline = text.find( L'\n' );
188
189 if( next_newline != std::u32string::npos ) {
190 text.erase( 0, next_newline + 1 );
191 }
192 else {
193 break;
194 }
195
196 if( !text.empty() ) {
197 lines++;
198 }
199 } while( !text.empty() );
200
201 metrics.y *= static_cast<float>( lines );
202
203 if( m_wrap ) {
204 metrics.x = 0.f;
205 }
206
207 return metrics;
208}
209
210const std::string& Label::GetName() const {
211 static const std::string name( "Label" );

Callers

nothing calls this directly

Calls 4

GetTextStringMetricsMethod · 0.80
GetFontLineHeightMethod · 0.80
endMethod · 0.80
emptyMethod · 0.80

Tested by

no test coverage detected