From 1e7b5c53b87e2cda180042b5012c5f8335d9d7ba Mon Sep 17 00:00:00 2001 From: BQ Date: Sat, 13 Aug 2016 18:53:46 +0100 Subject: [PATCH] Use for-range --- source/gwork/source/Controls/Text.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/source/gwork/source/Controls/Text.cpp b/source/gwork/source/Controls/Text.cpp index 355017ab..926e0713 100644 --- a/source/gwork/source/Controls/Text.cpp +++ b/source/gwork/source/Controls/Text.cpp @@ -232,7 +232,8 @@ void Text::SplitWords(const Gwk::String& s, std::vector& 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++) { @@ -281,8 +282,8 @@ void Text::RefreshSizeWrap() { delete line; } - m_lines.clear(); + std::vector words; SplitWords(GetText(), words); @@ -301,7 +302,7 @@ void Text::RefreshSizeWrap() int x = 0, y = 0; Gwk::String strLine; - for (std::vector::iterator it = words.begin(); it != words.end(); ++it) + for (auto&& it = words.begin(); it != words.end(); ++it) { bool bFinishLine = false; bool bWrapped = false; @@ -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; } } @@ -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) @@ -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());