Only break text once rather than on each frame

This commit is contained in:
Alayan 2018-10-14 17:14:45 +02:00
parent 8ec4da69f0
commit ec657a16e3
3 changed files with 22 additions and 12 deletions

View File

@ -34,7 +34,7 @@
</tabs>
<box proportion="1" width="98%" align="center" layout="vertical-row" padding="6">
<list id="list_addons" x="0" y="0" width="100%" height="100%"/>
<list id="list_addons" x="0" y="0" width="100%" height="100%" word_wrap="true"/>
</box>
<bright width="97%" id="tips_label" text="" align="center"/>

View File

@ -556,23 +556,28 @@ void CGUISTKListBox::draw()
if ( i==Selected && hl )
font_color = EGUI_LBC_TEXT_HIGHLIGHT;
std::wstring cell_text = Items[i].m_contents[x].m_text.c_str();
std::vector<std::wstring> cell_text_lines;
if (Items[i].m_word_wrap)
if (!Items[i].m_contents[x].m_broken_text)
{
StringUtils::breakText(cell_text, cell_text_lines, 300, Font);
}
else
{
cell_text_lines.push_back(cell_text);
std::wstring cell_text = Items[i].m_contents[x].m_text.c_str();
std::vector<std::wstring> cell_text_lines;
if (Items[i].m_word_wrap)
StringUtils::breakText(cell_text, cell_text_lines, 300, Font);
else
cell_text_lines.push_back(cell_text);
for (unsigned int j=0; j<cell_text_lines.size(); j++)
{
irr::core::stringw text_line = cell_text_lines[j].c_str();
Items[i].m_contents[x].m_text_lines.push_back(text_line);
}
Items[i].m_contents[x].m_broken_text = true;
}
core::rect<s32> lineRect = textRect;
for (unsigned int i=0; i<cell_text_lines.size(); i++)
for (unsigned int j=0; j<Items[i].m_contents[x].m_text_lines.size(); j++)
{
irr::core::stringw text_line = cell_text_lines[i].c_str();
Font->draw(
text_line,
Items[i].m_contents[x].m_text_lines[j],
lineRect,
hasItemOverrideColor(i, font_color) ? getItemOverrideColor(i, font_color) : getItemDefaultColor(font_color),
Items[i].m_contents[x].m_center, true, &clientClip);

View File

@ -12,6 +12,7 @@
#include "IGUIElement.h"
#include "irrArray.h"
#include <string>
#include <vector>
namespace irr
{
@ -30,6 +31,8 @@ namespace irr
struct ListCell
{
irr::core::stringw m_text;
bool m_broken_text;
std::vector<irr::core::stringw> m_text_lines;
int m_proportion;
s32 m_icon;
bool m_center;
@ -40,6 +43,8 @@ namespace irr
m_proportion = proportion;
m_icon = icon;
m_center = center;
m_broken_text = false;
m_text_lines.clear();
}
};