Skip to content

Commit 1892ff3

Browse files
authoredJan 22, 2020
StaticText/EnrichedString: Styling support (#9187)
* StaticText/EnrichedString: Styling support * Fix tooltip fg/bgcolor * Fix default color for substr(), add unittests
1 parent fab3f5f commit 1892ff3

File tree

9 files changed

+222
-203
lines changed

9 files changed

+222
-203
lines changed
 

Diff for: ‎games/minimal/mods/test/formspec.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local color = minetest.colorize
2+
13
local clip_fs = [[
24
style_type[label;noclip=%c]
35
style_type[button;noclip=%c]
@@ -31,8 +33,8 @@ local style_fs = [[
3133
bgcolor_pressed=purple]
3234
button[0,0;2.5,0.8;one_btn1;Button]
3335
34-
style[one_btn2;border=false;textcolor=cyan]
35-
button[0,1.05;2.5,0.8;one_btn2;Text Button]
36+
style[one_btn2;border=false;textcolor=cyan] ]]..
37+
"button[0,1.05;2.5,0.8;one_btn2;Text " .. color("#FF0", "Yellow") .. [[]
3638
3739
style[one_btn3;bgimg=bubble.png;bgimg_hovered=default_apple.png;
3840
bgimg_pressed=heart.png]
@@ -144,16 +146,18 @@ local pages = {
144146
list[current_player;main;6,8;3,2;1]
145147
button[9,0;2.5,1;name;]
146148
button[9,1;2.5,1;name;]
147-
button[9,2;2.5,1;name;]
148-
label[9,0;This is a label.\nLine\nLine\nLine\nEnd]
149-
button[9,3;1,1;name;]
149+
button[9,2;2.5,1;name;] ]]..
150+
"label[9,0.5;This is a label.\nLine\nLine\nLine\nEnd]"..
151+
[[button[9,3;1,1;name;]
150152
vertlabel[9,4;VERT]
151153
label[10,3;HORIZ]
152154
tabheader[6.5,0;6,0.65;name;Tab 1,Tab 2,Tab 3,Secrets;1;false;false]
153155
]],
154156

155157
"size[12,12]real_coordinates[true]" ..
156-
"label[0.375,0.375;Styled]" ..
158+
("label[0.375,0.375;Styled - %s %s]"):format(
159+
color("#F00", "red text"),
160+
color("#77FF00CC", "green text")) ..
157161
"label[6.375,0.375;Unstyled]" ..
158162
"box[0,0.75;12,0.1;#999]" ..
159163
"box[6,0.85;0.1,11.15;#999]" ..

Diff for: ‎src/client/gameui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
155155

156156
m_guitext2->setVisible(m_flags.show_debug);
157157

158-
setStaticText(m_guitext_info, translate_string(m_infotext).c_str());
158+
setStaticText(m_guitext_info, m_infotext.c_str());
159159
m_guitext_info->setVisible(m_flags.show_hud && g_menumgr.menuCount() == 0);
160160

161161
static const float statustext_time_max = 1.5f;
@@ -169,7 +169,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
169169
}
170170
}
171171

172-
setStaticText(m_guitext_status, translate_string(m_statustext).c_str());
172+
setStaticText(m_guitext_status, m_statustext.c_str());
173173
m_guitext_status->setVisible(!m_statustext.empty());
174174

175175
if (!m_statustext.empty()) {

Diff for: ‎src/gui/guiButton.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent,
5353
core::clamp<u32>(Colors[i].getGreen() * COLOR_PRESSED_MOD, 0, 255),
5454
core::clamp<u32>(Colors[i].getBlue() * COLOR_PRESSED_MOD, 0, 255));
5555
}
56-
5756
StaticText = gui::StaticText::add(Environment, Text.c_str(), core::rect<s32>(0,0,rectangle.getWidth(),rectangle.getHeight()), false, false, this, id);
5857
StaticText->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
5958
// END PATCH

Diff for: ‎src/gui/guiFormSpecMenu.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -3417,19 +3417,16 @@ void GUIFormSpecMenu::drawMenu()
34173417
void GUIFormSpecMenu::showTooltip(const std::wstring &text,
34183418
const irr::video::SColor &color, const irr::video::SColor &bgcolor)
34193419
{
3420-
const std::wstring ntext = translate_string(text);
3421-
m_tooltip_element->setOverrideColor(color);
3422-
m_tooltip_element->setBackgroundColor(bgcolor);
3423-
setStaticText(m_tooltip_element, ntext.c_str());
3420+
EnrichedString ntext(text);
3421+
ntext.setDefaultColor(color);
3422+
ntext.setBackground(bgcolor);
3423+
3424+
setStaticText(m_tooltip_element, ntext);
34243425

34253426
// Tooltip size and offset
34263427
s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
3427-
#if (IRRLICHT_VERSION_MAJOR <= 1 && IRRLICHT_VERSION_MINOR <= 8 && IRRLICHT_VERSION_REVISION < 2) || USE_FREETYPE == 1
3428-
std::vector<std::wstring> text_rows = str_split(ntext, L'\n');
3429-
s32 tooltip_height = m_tooltip_element->getTextHeight() * text_rows.size() + 5;
3430-
#else
34313428
s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
3432-
#endif
3429+
34333430
v2u32 screenSize = Environment->getVideoDriver()->getScreenSize();
34343431
int tooltip_offset_x = m_btn_height;
34353432
int tooltip_offset_y = m_btn_height;

0 commit comments

Comments
 (0)