Skip to content

Conversation

@CrazyladMT
Copy link
Contributor

@CrazyladMT CrazyladMT commented Jan 2, 2026

Fixes #14426

This PR adds support for core.colorize in the vertlabel[] formspec element by using EnrichedString to preserve newlines and color escapes.

There are also some minor code style fixes applied throughout guiFormSpecMenu.cpp, as shown in the commit.

To do

This PR is Ready for Review.

How to test

  1. make a mod with the following code:
core.register_on_joinplayer(function(player)
   local name = player:get_player_name()

   local fs = table.concat({
       "formspec_version[6]",
       "size[8,8]",
       "vertlabel[1,0;",
           core.colorize("#FF0000", " Red\ntext"),
       "]",
   })

   core.show_formspec(name, "test:vertlabel", fs)
end)
  1. enable the mod and join any world
  2. observe that vertlabel[] now colorizes text

@sfan5 sfan5 added Bugfix 🐛 PRs that fix a bug Formspec labels Jan 3, 2026
@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jan 3, 2026
@sfan5 sfan5 removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jan 3, 2026
@sfan5 sfan5 self-requested a review January 4, 2026 00:16
@sfan5
Copy link
Member

sfan5 commented Jan 7, 2026

my changes:

diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp
index 3bcc955b4..787d6c006 100644
--- a/src/gui/guiFormSpecMenu.cpp
+++ b/src/gui/guiFormSpecMenu.cpp
@@ -1887,13 +1887,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
 	// Use EnrichedString so color escapes and formatting are preserved
 	EnrichedString etext(unescape_string(utf8_to_wide(parts[1])));
 
-	// Build vertical enriched text (one character per line)
+	// Build vertical text (one character per line)
 	EnrichedString vlabel;
 	const size_t char_count = etext.getString().size();
-	const size_t line_count = char_count + 1;  // account for dummy line
-
-	// Dummy first line to avoid clipping
-	vlabel.addCharNoColor(L'\n');
+	const size_t line_count = char_count;
 
 	for (size_t i = 0; i < char_count; i++) {
 		vlabel += etext.substr(i, 1);
@@ -1916,12 +1913,9 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
 		// Vertlabels are positioned by center, not left.
 		pos.X -= imgsize.X / 2;
 
-		// We use the character count + 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) *
-			(etext.getString().size() + 1));
+			pos.Y + font_line_height(font) * char_count);
 
 	} else {
 		pos = getElementBasePos(&v_pos);

here's the results (vertlabel and label at exactly the same place):
grafik

this looks much more correct to me than introducing some random offset

@sfan5 sfan5 removed their request for review January 7, 2026 15:46
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@CrazyladMT
Copy link
Contributor Author

this looks much more correct to me than introducing some random offset

Thanks for the help. I agree, it does look correct now. I must have been confused about the difference between real coordinates and the old formspec system.

Using "real_coordinates[true]" with "vertlabel[0.15,0;" .. core.colorize("#FF0000", " Red\ntext") .. "]",:

Screenshot From 2026-01-07 13-42-38
This looks correct.
However, with "real_coordinates[false]":

Screenshot From 2026-01-07 13-44-08

Apparently this offset existed even before my changes, unless I am missing something.
I do find it strange that inputting 0 as the Y value for the vertlabel formspec element makes the label... not be at Y = 0. I'm not exactly sure how to fix this. Is this the desired behavior?

@sfan5
Copy link
Member

sfan5 commented Jan 7, 2026

Is this the desired behavior?

with real_coordinates disabled: sure.

@sfan5 sfan5 added this to the 5.15.0 milestone Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formspec: vertlabel element does not properly handle minetest.colorize or newlines

2 participants