Skip to content

Remove useless scale from text HUD element documentation#17151

Merged
sfan5 merged 3 commits into
luanti-org:masterfrom
Wuzzy2:doc_remove_text_scale
May 15, 2026
Merged

Remove useless scale from text HUD element documentation#17151
sfan5 merged 3 commits into
luanti-org:masterfrom
Wuzzy2:doc_remove_text_scale

Conversation

@Wuzzy2
Copy link
Copy Markdown
Contributor

@Wuzzy2 Wuzzy2 commented May 6, 2026

Fixes #17029.

The scale field is removed from the documentation for text HUD elements because this field appears to do absolutely nothing after various tests.

Even after considering @SmallJoker’s comments in #17029, I still have not managed to find any HUD definition where scale changes anything. So I assume it really does nothing, as I suspected.

If the intention of scale was to clip text out of a bounding box, it is not working as promised, so the documentation should not claim it anymore.

This documentation can always be added back later if some functional bounding box feature is added.

NEW CHANGE: Additionally, an useless size variable in hud.cpp was removed.

To do

This PR is ready for review.

How to test

Read the changed files.

Test if HUD text still works.

@cx384 cx384 added @ Script API @ Documentation Improvements or additions to documentation Bugfix 🐛 PRs that fix a bug labels May 6, 2026
Copy link
Copy Markdown
Member

@cx384 cx384 left a comment

Choose a reason for hiding this comment

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

Even after considering @SmallJoker’s comments in #17029, I still have not managed to find any HUD definition where scale changes anything. So I assume it really does nothing, as I suspected.

Indeed, scale does not change anything, because for the draw call hcenter and vcenter is false. So only the UpperLeftCorner of the position is relevant which does not get changed by scale.

Please also remove it in the cpp code to avoid confusion e.g. apply this:
0001-Remove-text-hud-scale-in-hud.cpp.patch

@Zughy Zughy added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label May 6, 2026
@Wuzzy2
Copy link
Copy Markdown
Contributor Author

Wuzzy2 commented May 6, 2026

Wait a minute … I just realized something when looking at the code.

size is a core::rect and is used here:

ttfont->draw(line, size + pos + offset + offs + line_offset);

and here:

textfont->draw(line.c_str(), size + pos + offset + offs + line_offset, color);

According to the Irrlicht documentation, when you add a core::position2d to a core::rect, it means:

move right by given numbers

https://irrlicht.sourceforge.io/docu/classirr_1_1core_1_1rect.html#a699b98aff4bf8b7d92cef6d3c940354f

I interpret that the rectangle origin position is shifted by pos. Since this position (of size) is always (0,0), this is a no-op. This explains why the scale setting does nothing.

I will therefore remove size entirely, as it's essentially dead code.

@Wuzzy2
Copy link
Copy Markdown
Contributor Author

Wuzzy2 commented May 6, 2026

  • Removed size from hud.cpp
  • Added an explicit warning that scale should not be used in lua_api.md because probably lots of existing code will still have the scale (current documentation explicitly recommends {x = 100, y = 100}) and it was in the documentation for a very long time

Please test the PR because it now contains a code change. (works on my machine)

By the way: The draw function in Irrlicht includes an explicit clip parameter that we could use later to implement actual clipping. https://irrlicht.sourceforge.io/docu/classirr_1_1gui_1_1_i_g_u_i_font.html#af5627e546c474f31260fe671c24f9a33

Probably too late/risky for 5.16.0 tho.

Copy link
Copy Markdown
Member

@cx384 cx384 left a comment

Choose a reason for hiding this comment

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

I interpret that the rectangle origin position is shifted by pos. Since this position (of size) is always (0,0), this is a no-op. This explains why the scale setting does nothing.

No, it gets added to both UpperLeftCorner and LowerRightCorner see:

rect<T> &operator+=(const position2d<T> &pos)
{
UpperLeftCorner += pos;
LowerRightCorner += pos;
return *this;
}

I will therefore remove size entirely, as it's essentially dead code.

Yes, as I wrote before, only the UpperLeftCorner is relevant in our draw calls, but this is only because hcenter and vcenter is false. See

if (hcenter || vcenter)

luanti/irr/src/CGUIFont.cpp

Lines 319 to 323 in bb7fcd3

if (hcenter)
offset.X += (position.getWidth() - textDimension.Width) >> 1;
if (vcenter)
offset.Y += (position.getHeight() - textDimension.Height) >> 1;
if (hcenter) {

Comment thread src/client/hud.cpp
Comment thread src/client/hud.cpp Outdated
@Wuzzy2 Wuzzy2 force-pushed the doc_remove_text_scale branch from 4e862a7 to 745c035 Compare May 14, 2026 15:29
@Wuzzy2
Copy link
Copy Markdown
Contributor Author

Wuzzy2 commented May 14, 2026

I’ve updated this PR by just re-applying the original suggested patch again.

@cx384 cx384 added One approval ✅ ◻️ and removed Action / change needed Code still needs changes (PR) / more information requested (Issues) labels May 14, 2026
Comment thread doc/lua_api.md Outdated
Comment thread doc/lua_api.md Outdated
Copy link
Copy Markdown
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

only some typos

@Wuzzy2 Wuzzy2 force-pushed the doc_remove_text_scale branch from 745c035 to a4fab8c Compare May 15, 2026 11:08
@Wuzzy2
Copy link
Copy Markdown
Contributor Author

Wuzzy2 commented May 15, 2026

Done.

@sfan5 sfan5 merged commit fc4c549 into luanti-org:master May 15, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix 🐛 PRs that fix a bug @ Documentation Improvements or additions to documentation @ Script API >= Two approvals ✅ ✅

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HUD text scale argument does nothing

5 participants