| 171 | } |
| 172 | |
| 173 | sf::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 | |
| 210 | const std::string& Label::GetName() const { |
| 211 | static const std::string name( "Label" ); |
nothing calls this directly
no test coverage detected