示例#1
0
int DialogBuilder::AddTextWrap(const wchar_t *text, bool center, int width)
{
	int LineCount = 0;
	for(const auto& i: wrapped_text(string_view(text), width <= 0? ScrX - 1 - 10 : width))
	{
		const auto Text = AddText(null_terminated(i).c_str());
		Text->Flags = center? DIF_CENTERTEXT : 0;
		++LineCount;
	}

	return LineCount;
}
示例#2
0
sf::Vector2f Label::CalculateRequisition() {
	const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) );
	unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) );
	const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) );

	auto metrics = Context::Get().GetEngine().GetTextMetrics( GetWrappedText(), font, font_size );
	metrics.y = Context::Get().GetEngine().GetFontLineHeight( font, font_size );

	sf::String wrapped_text( GetWrappedText() );
	std::basic_string<sf::Uint32> text( wrapped_text.begin(), wrapped_text.end() );

	std::size_t lines = 1;

	do {
		auto next_newline = text.find( L'\n' );

		if( next_newline != std::basic_string<sf::Uint32>::npos ) {
			text = text.substr( next_newline + 1 );
		}
		else {
			break;
		}

		if( !text.empty() ) {
			lines++;
		}
	} while( !text.empty() );

	metrics.y *= static_cast<float>( lines );

	if( m_wrap ) {
		metrics.x = 0.f;
	}

	return metrics;
}