[Solved] Bug with max_formspec_size?

Post Reply
isaiah658
Member
Posts: 207
Joined: Sun Jan 24, 2016 14:58
Contact:

[Solved] Bug with max_formspec_size?

by isaiah658 » Post

I was investigating how I could make use of minetest.get_player_window_information, but I'm running into something that I think is a bug. The max_formspec_size y value always returns exactly 15 even after changing the game window size. It's always a whole number, no decimal places. The x value does change and has decimal places. I normally run Minetest via an appimage, so I downloaded the flatpak version just to test and it's the same result. Also tried Minetest 5.7 and 5.8.

Is anyone else able to reproduce this? If this is a bug, could someone who has a Github account report it?
Last edited by isaiah658 on Tue Aug 06, 2024 01:21, edited 1 time in total.

User avatar
v-rob
Developer
Posts: 991
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob

Re: Bug with max_formspec_size?

by v-rob » Post

This is not a bug. Formspec coordinates are automatically scaled according to the window size. Roughly speaking, the coordinate size is the width or height of the window (whichever is smaller) divided by 15 on desktop or 10 on mobile. If you resize the window such that the width is smaller than the height, you should see that the X value stays at 15 while the Y value changes.

There area a few other calculations taken into account, such as the padding of the formspec, but that's the general gist.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

isaiah658
Member
Posts: 207
Joined: Sun Jan 24, 2016 14:58
Contact:

Re: Bug with max_formspec_size?

by isaiah658 » Post

Thank you! That seems to be correct. I was able to get values over 15 for y.

I think my confusion was because I was trying to use these values for a formspec that is a fixed size. My mod has a few formspecs that need precise placement for fonts and sizing for fonts. I've been using fixed sized formspecs along with scaling the font size. Players have control over the size of the formspec. My plan is to utilize the new screen info to automatically scale the formspec to an appropriate size and eliminate the need for the player to choose the size.

User avatar
v-rob
Developer
Posts: 991
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob

Re: [Solved] Bug with max_formspec_size?

by v-rob » Post

Fixed size formspecs have a much simpler calculation: it's simply floor(0.5555 * dpi * gui_scaling). In Lua, this should be:

Code: Select all

local win = minetest.get_player_window_information(player)
local coord_size = math.floor(0.5555 * 96 * win.real_gui_scaling)
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

isaiah658
Member
Posts: 207
Joined: Sun Jan 24, 2016 14:58
Contact:

Re: [Solved] Bug with max_formspec_size?

by isaiah658 » Post

v-rob wrote:
Sat Aug 10, 2024 04:37
Fixed size formspecs have a much simpler calculation: it's simply floor(0.5555 * dpi * gui_scaling). In Lua, this should be:

Code: Select all

local win = minetest.get_player_window_information(player)
local coord_size = math.floor(0.5555 * 96 * win.real_gui_scaling)
Awesome! I'm was able to convert between the two sizes to emulate how a normal formspec resizes. There's just one more issue that maybe you would know. I might be wrong, but it appears that fixed size formspecs have a minimum padding of 800 x 600. Whenever the window size is smaller than either of those, the formspec no longer perfectly centered. Is there any way to disable this or perhaps counter the effects of this using the position formspec element? It's probably not that big of a deal as I haven't had anyone complain about it. It's about the only difference I noticed between a normal formspec.

User avatar
v-rob
Developer
Posts: 991
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob

Re: [Solved] Bug with max_formspec_size?

by v-rob » Post

isaiah658 wrote:
Sat Aug 10, 2024 16:15
I might be wrong, but it appears that fixed size formspecs have a minimum padding of 800 x 600. Whenever the window size is smaller than either of those, the formspec no longer perfectly centered. Is there any way to disable this or perhaps counter the effects of this using the position formspec element?
Unfortunately, this behavior is by design. I have absolutely zero idea why they do this, but if the window size is less than 800 x 600, fixed size formspecs pretend that the window is 800 x 600 rather than whatever the actual size is. You might be able to counteract the effects of this by reverse-calculating the correct position to pass to position[].

Formspecs are so bad.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests