diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index ae73bc07da..f6fbaf4ca4 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -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"<explicit_size) - warningstream<<"invalid use of button without a size[] element"<& core::rect rect = core::rect(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); if(!data->explicit_size) - warningstream<<"invalid use of positioned "<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"< v_pos = split(parts[0],','); - std::wstring text = unescape_translate( - unescape_string(utf8_to_wide(parts[1]))); + std::vector 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(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( - 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"<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"< rect = core::rect(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"<idef(); ItemStack item;