From 44925ad19051d4ffe239b3ba99ea27e7275409dc Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Wed, 22 Jul 2015 12:33:59 -0500 Subject: GUI TextBox Allows the GUI to create a scrollable text box for long text that may not all fit on the screen. Also includes code to allow the console to wrap on spaces and other such characters instead of wrapping in the middle of a word. To see an example of how to add a text box to the XML, see: https://gerrit.omnirom.org/#/c/14183/ Change-Id: Ifd139172ede290046b58ea3fe526e2e06da1d4ef --- gui/scrolllist.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'gui/scrolllist.cpp') diff --git a/gui/scrolllist.cpp b/gui/scrolllist.cpp index a033205bb..d857e06b3 100644 --- a/gui/scrolllist.cpp +++ b/gui/scrolllist.cpp @@ -607,3 +607,43 @@ void GUIScrollList::SetPageFocus(int inFocus) mUpdate = 1; } } + +bool GUIScrollList::AddLines(std::vector* origText, std::vector* origColor, size_t* lastCount, std::vector* rText, std::vector* rColor) +{ + if (*lastCount == origText->size()) + return false; // nothing to add + + size_t prevCount = *lastCount; + *lastCount = origText->size(); + + // Due to word wrap, figure out what / how the newly added text needs to be added to the render vector that is word wrapped + // Note, that multiple consoles on different GUI pages may be different widths or use different fonts, so the word wrapping + // may different in different console windows + for (size_t i = prevCount; i < *lastCount; i++) { + string curr_line = origText->at(i); + string curr_color; + if (origColor) + curr_color = origColor->at(i); + for(;;) { + size_t line_char_width = gr_ttf_maxExW(curr_line.c_str(), mFont->GetResource(), mRenderW); + if (line_char_width < curr_line.size()) { + //string left = curr_line.substr(0, line_char_width); + size_t wrap_pos = curr_line.find_last_of(" ,./:-_;", line_char_width - 1); + if (wrap_pos == string::npos) + wrap_pos = line_char_width; + else if (wrap_pos < line_char_width - 1) + wrap_pos++; + rText->push_back(curr_line.substr(0, wrap_pos)); + if (origColor) + rColor->push_back(curr_color); + curr_line = curr_line.substr(wrap_pos); + } else { + rText->push_back(curr_line); + if (origColor) + rColor->push_back(curr_color); + break; + } + } + } + return true; +} -- cgit v1.2.3