Skip to content

Commit

Permalink
Use for-range
Browse files Browse the repository at this point in the history
  • Loading branch information
billyquith committed Aug 13, 2016
1 parent 155a883 commit 1e7b5c5
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions source/gwork/source/Controls/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ void Text::SplitWords(const Gwk::String& s, std::vector<Gwk::String>& elems)
{
Gwk::String str;

int w = GetParent()->Width()-GetParent()->GetPadding().left-GetParent()->GetPadding().right;
int w = GetParent()->Width()
- (GetParent()->GetPadding().left + GetParent()->GetPadding().right);

for (int i = 0; i < (int)s.length(); i++)
{
Expand Down Expand Up @@ -281,8 +282,8 @@ void Text::RefreshSizeWrap()
{
delete line;
}

m_lines.clear();

std::vector<Gwk::String> words;
SplitWords(GetText(), words);

Expand All @@ -301,7 +302,7 @@ void Text::RefreshSizeWrap()
int x = 0, y = 0;
Gwk::String strLine;

for (std::vector<Gwk::String>::iterator it = words.begin(); it != words.end(); ++it)
for (auto&& it = words.begin(); it != words.end(); ++it)
{
bool bFinishLine = false;
bool bWrapped = false;
Expand All @@ -316,10 +317,10 @@ void Text::RefreshSizeWrap()
strLine += *it;
Gwk::Point p = GetSkin()->GetRender()->MeasureText(GetFont(), strLine);

if (p.x > Width())
if (p.x > w)
if (p.x > Width() && p.x > w)
{
bFinishLine = true; bWrapped = true;
bFinishLine = true;
bWrapped = true;
}
}

Expand Down Expand Up @@ -385,15 +386,11 @@ Text* Text::GetLine(int i)

int Text::GetLineFromChar(int i)
{
TextLines::iterator it = m_lines.begin();
TextLines::iterator itEnd = m_lines.end();
int iChars = 0;
int iLine = 0;

while (it != itEnd)
for (auto&& line : m_lines)
{
Text* line = *it;
++it;
iChars += line->Length();

if (iChars > i)
Expand All @@ -404,20 +401,16 @@ int Text::GetLineFromChar(int i)

if (iLine > 0)
return iLine-1;

return iLine;
}

int Text::GetStartCharFromLine(int i)
{
TextLines::iterator it = m_lines.begin();
TextLines::iterator itEnd = m_lines.end();
int iChars = 0;

while (it != itEnd)
for (auto&& line : m_lines)
{
Text* line = *it;
++it;

if (i == 0)
return Gwk::Clamp(iChars, 0, Length());

Expand Down

0 comments on commit 1e7b5c5

Please sign in to comment.