Add proper line breaking

This commit is contained in:
Benau 2018-05-21 11:19:18 +08:00
parent 4fdd3eee38
commit 34b8a07d80
2 changed files with 20 additions and 12 deletions

View File

@ -13,7 +13,7 @@ namespace gui
//You can add more characters if needed //You can add more characters if needed
//For full list please visit http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/kinsoku.html //For full list please visit http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/kinsoku.html
bool UtfNoStarting (wchar_t c) inline bool UtfNoStarting (wchar_t c)
{ {
switch (c) switch (c)
{ {
@ -66,7 +66,7 @@ bool UtfNoStarting (wchar_t c)
} }
} }
bool UtfNoEnding (wchar_t c) inline bool UtfNoEnding (wchar_t c)
{ {
switch (c) switch (c)
{ {
@ -99,7 +99,7 @@ bool UtfNoEnding (wchar_t c)
//Helper function //Helper function
bool breakable (wchar_t c) inline bool breakable (wchar_t c)
{ {
if ((c > 12287 && c < 40960) || //Common CJK words if ((c > 12287 && c < 40960) || //Common CJK words
(c > 44031 && c < 55204) || //Hangul (c > 44031 && c < 55204) || //Hangul

View File

@ -44,6 +44,8 @@
#include "states_screens/dialogs/network_user_dialog.hpp" #include "states_screens/dialogs/network_user_dialog.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include <utfwrapping.h>
using namespace Online; using namespace Online;
using namespace GUIEngine; using namespace GUIEngine;
@ -155,16 +157,22 @@ void NetworkingLobby::init()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void NetworkingLobby::addMoreServerInfo(core::stringw info) void NetworkingLobby::addMoreServerInfo(core::stringw info)
{ {
assert(m_text_bubble->getDimension().Width > 10); const unsigned box_width = m_text_bubble->getDimension().Width;
while ((int)GUIEngine::getFont()->getDimension(info.c_str()).Width > while (GUIEngine::getFont()->getDimension(info.c_str()).Width > box_width)
m_text_bubble->getDimension().Width - 10)
{ {
int size = (m_text_bubble->getDimension().Width - 10) core::stringw brokentext = info;
/ m_server_info_height; while (brokentext.size() > 0)
assert(size > 0); {
core::stringw new_info = info.subString(0, size); brokentext.erase(brokentext.size() - 1);
m_server_info.push_back(new_info); if (GUIEngine::getFont()->getDimension(brokentext.c_str()).Width <
info = info.subString(new_info.size(), 80); box_width && gui::breakable(brokentext.lastChar()))
break;
}
if (brokentext.size() == 0)
break;
m_server_info.push_back(brokentext);
info =
info.subString(brokentext.size(), info.size() - brokentext.size());
} }
if (info.size() > 0) if (info.size() > 0)
{ {