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/console.cpp | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'gui/console.cpp') diff --git a/gui/console.cpp b/gui/console.cpp index 47caadb15..6b38d6137 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -158,39 +158,9 @@ int GUIConsole::RenderSlideout(void) return 0; } -bool GUIConsole::AddLines() -{ - if (mLastCount == gConsole.size()) - return false; // nothing to add - - size_t prevCount = mLastCount; - mLastCount = gConsole.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 < mLastCount; i++) { - string curr_line = gConsole[i]; - string curr_color = gConsoleColor[i]; - for(;;) { - size_t line_char_width = gr_maxExW(curr_line.c_str(), mFont->GetResource(), mRenderW); - if (line_char_width < curr_line.size()) { - rConsole.push_back(curr_line.substr(0, line_char_width)); - rConsoleColor.push_back(curr_color); - curr_line = curr_line.substr(line_char_width); - } else { - rConsole.push_back(curr_line); - rConsoleColor.push_back(curr_color); - break; - } - } - } - return true; -} - int GUIConsole::RenderConsole(void) { - AddLines(); + AddLines(&gConsole, &gConsoleColor, &mLastCount, &rConsole, &rConsoleColor); GUIScrollList::Render(); // if last line is fully visible, keep tracking the last line when new lines are added @@ -241,7 +211,7 @@ int GUIConsole::Update(void) scrollToEnd = true; } - if (AddLines()) { + if (AddLines(&gConsole, &gConsoleColor, &mLastCount, &rConsole, &rConsoleColor)) { // someone added new text // at least the scrollbar must be updated, even if the new lines are currently not visible mUpdate = 1; -- cgit v1.2.3