Example #1
0
void Text::SplitWords(const Gwen::UnicodeString &s, std::vector<Gwen::UnicodeString> & elems )
{
	Gwen::UnicodeString str;

	int w = GetParent()->Width() - GetParent()->GetPadding().left-GetParent()->GetPadding().right;
	for ( int i=0; i<(int)s.length(); i++ )
	{
		if ( s[i] == L'\n' )
		{
			if ( !str.empty() ) { elems.push_back( str ); }

			elems.push_back( L"\n" );
			str.clear();
			continue;
		}

		if ( s[i] == L' ' )
		{
			str += s[i];
			elems.push_back( str );
			str.clear();
			continue;
		}

		str += s[i];

		//if adding character makes the word bigger than the textbox size
		Gwen::Point p = GetSkin()->GetRender()->MeasureText( GetFont(), str );
		if ( p.x > w )
		{
			int addSum = GetPadding().left+GetPadding().right;
			//split words
			str.pop_back();
			elems.push_back( str );
			str.clear();
			--i;
			continue;
		}
	}

	if ( !str.empty() ) { elems.push_back( str ); }
}