mirror of
https://github.com/luanti-org/luanti.git
synced 2026-01-12 04:05:26 +01:00
Make "vertlabel[]" formspec element support core.colorize (#16802)
This commit is contained in:
@@ -949,7 +949,7 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen
|
||||
}
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of item_image without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of item_image without a size[] element" << std::endl;
|
||||
|
||||
FieldSpec spec(
|
||||
"",
|
||||
@@ -1008,7 +1008,7 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element)
|
||||
}
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of button without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of button without a size[] element" << std::endl;
|
||||
|
||||
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
||||
|
||||
@@ -1670,7 +1670,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
|
||||
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of positioned " << type << " without a size[] element" << std::endl;
|
||||
|
||||
if(m_form_src)
|
||||
default_val = m_form_src->resolveText(default_val);
|
||||
@@ -1781,7 +1781,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
|
||||
}
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of label without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of label without a size[] element" << std::endl;
|
||||
|
||||
auto style = getDefaultStyleForElement("label", "");
|
||||
gui::IGUIFont *font = style.getFont();
|
||||
@@ -1882,11 +1882,21 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
|
||||
if (!precheckElement("vertlabel", element, 2, 2, parts))
|
||||
return;
|
||||
|
||||
std::vector<std::string> v_pos = split(parts[0],',');
|
||||
std::wstring text = unescape_translate(
|
||||
unescape_string(utf8_to_wide(parts[1])));
|
||||
std::vector<std::string> v_pos = split(parts[0], ',');
|
||||
|
||||
MY_CHECKPOS("vertlabel",1);
|
||||
// Use EnrichedString so color escapes and formatting are preserved
|
||||
EnrichedString etext(unescape_string(utf8_to_wide(parts[1])));
|
||||
|
||||
// Build vertical text (one character per line)
|
||||
EnrichedString vlabel;
|
||||
const size_t char_count = etext.getString().size();
|
||||
|
||||
for (size_t i = 0; i < char_count; i++) {
|
||||
vlabel += etext.substr(i, 1);
|
||||
vlabel.addCharNoColor(L'\n');
|
||||
}
|
||||
|
||||
MY_CHECKPOS("vertlabel", 1);
|
||||
|
||||
auto style = getDefaultStyleForElement("vertlabel", "", "label");
|
||||
gui::IGUIFont *font = style.getFont();
|
||||
@@ -1902,45 +1912,35 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
|
||||
// Vertlabels are positioned by center, not left.
|
||||
pos.X -= imgsize.X / 2;
|
||||
|
||||
// We use text.length + 1 because without it, the rect
|
||||
// isn't quite tall enough and cuts off the text.
|
||||
rect = core::rect<s32>(pos.X, pos.Y,
|
||||
pos.X + imgsize.X,
|
||||
pos.Y + font_line_height(font) *
|
||||
(text.length() + 1));
|
||||
pos.Y + font_line_height(font) * char_count);
|
||||
|
||||
} else {
|
||||
pos = getElementBasePos(&v_pos);
|
||||
|
||||
// As above, the length must be one longer. The width of
|
||||
// the rect (15 pixels) seems rather arbitrary, but
|
||||
// changing it might break something.
|
||||
// The width of the rect (15 pixels) seems rather
|
||||
// arbitrary, but changing it might break something.
|
||||
rect = core::rect<s32>(
|
||||
pos.X, pos.Y+((imgsize.Y/2) - m_btn_height),
|
||||
pos.X+15, pos.Y +
|
||||
font_line_height(font) *
|
||||
(text.length() + 1) +
|
||||
((imgsize.Y/2) - m_btn_height));
|
||||
pos.X, pos.Y + ((imgsize.Y / 2) - m_btn_height),
|
||||
pos.X + 15, pos.Y +
|
||||
font_line_height(font) * (char_count + 1) +
|
||||
((imgsize.Y / 2) - m_btn_height));
|
||||
}
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of label without a size[] element"<<std::endl;
|
||||
|
||||
std::wstring label;
|
||||
|
||||
for (wchar_t i : text) {
|
||||
label += i;
|
||||
label += L"\n";
|
||||
}
|
||||
warningstream << "invalid use of label without a size[] element" << std::endl;
|
||||
|
||||
FieldSpec spec(
|
||||
"",
|
||||
label,
|
||||
L"",
|
||||
L"",
|
||||
258 + m_fields.size()
|
||||
);
|
||||
gui::IGUIStaticText *e = gui::StaticText::add(Environment, spec.flabel.c_str(),
|
||||
|
||||
gui::IGUIStaticText *e = gui::StaticText::add(Environment, vlabel,
|
||||
rect, false, false, data->current_parent, spec.fid);
|
||||
|
||||
e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
|
||||
|
||||
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
||||
@@ -1997,7 +1997,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem
|
||||
pos.Y+geom.Y);
|
||||
|
||||
if (!data->explicit_size)
|
||||
warningstream<<"invalid use of image_button without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of image_button without a size[] element" << std::endl;
|
||||
|
||||
image_name = unescape_string(image_name);
|
||||
pressed_image_name = unescape_string(pressed_image_name);
|
||||
@@ -2194,7 +2194,7 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &
|
||||
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
||||
|
||||
if(!data->explicit_size)
|
||||
warningstream<<"invalid use of item_image_button without a size[] element"<<std::endl;
|
||||
warningstream << "invalid use of item_image_button without a size[] element" << std::endl;
|
||||
|
||||
IItemDefManager *idef = m_client->idef();
|
||||
ItemStack item;
|
||||
|
||||
Reference in New Issue
Block a user