Skip to content

Commit

Permalink
Supertips: Specify width as 'em' units
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 committed Aug 18, 2024
1 parent 8f5cf7d commit e75acb3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ Elements
* `staticPos` is an optional position of the form `posX,posY` in formspec coordinates.
If specified, the tooltip will always appear at these given formspec coordinates.
If this field is empty, the tooltip will follow the cursor.
* `width` sets the tooltip width (in formspec units).
* `width` sets the tooltip width (in typographical 'em' units of the default font style).
* `name` is the name of the field.
* `text` is the formatted text using `Markup Language` described below.

Expand Down
34 changes: 24 additions & 10 deletions games/devtest/mods/testformspec/formspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,19 @@ mouse control = true]
box[1,3;1,1;#ff000080]
box[2.4,3.4;0.2,0.2;#ffffff80]
supertip[1,3;1,1;2.5,3.5;5;supertip_static;<big>Simple supertip (<i>static</i>)</big>
supertip[1,3;1,1;2.5,3.5;18;supertip_static;<big>Simple supertip (<i>static</i>)</big>
This one should always appear at the tiny white square.]
box[1,5;1,1;#ff000080]
supertip[1,5;1,1;;5;supertip_dynamic;<big>Simple supertip (<i>dynamic</i>)</big>
supertip[1,5;1,1;;18;supertip_dynamic;<big>Simple supertip (<i>dynamic</i>)</big>
This should appear at the cursor.]
button[2.5,5;3,1;st_btn;HOVERME]
supertip[st_btn;;5;supertip_dynamic_btn;<big>Simple supertip (<i>dynamic</i>)</big>
supertip[st_btn;;18;supertip_dynamic_btn;<big>Simple supertip (<i>dynamic</i>)</big>
This should appear at the cursor when hovering the button.]
box[1,7;1,1;#ff000080]
supertip[1,7;1,1;;5;supertip_dynamic_complex;]]..minetest.formspec_escape([[<big>Complex supertip (<i>dynamic</i>)</big>
supertip[1,7;1,1;;18;supertip_dynamic_complex;]]..minetest.formspec_escape([[<big>Complex supertip (<i>dynamic</i>)</big>
<img name=testformspec_node.png float=right width=64 height=64>
<left>Left align</left>
<center>Right align</center>
Expand All @@ -505,33 +505,47 @@ Item:
<item name=testformspec:node>]]).."]"..
[[
box[1,9;1,1;#ff000080]
supertip[1,9;1,1;;5;supertip_stone;]]..minetest.formspec_escape([[<global color=#333 background=#aaa margin=20>
supertip[1,9;1,1;;18;supertip_stone;]]..minetest.formspec_escape([[<global color=#333 background=#aaa margin=20>
<item name=testformspec:node float=left width=64 height=64>
<big><b><center>Formspec Test Node</center></b></big>
The <b>Formspec Test Node</b> is a dummy node to display an item in the <mono>testformspec</mono> mod.
• <b>Max. stack size:</b> 99
• <b>Drops:</b> <i>itself</i> <item name=testformspec:node width=32 height=32>]]).."]"..
[[
box[3,9;1,1;#ff000080]
supertip[3,9;1,1;;5;supertip_bgimg;This supertip has a width of 5em!]
box[4.5,9;1,1;#ff000080]
supertip[4.5,9;1,1;;10;supertip_bgimg;This supertip has a width of 10em!]
box[6,9;1,1;#ff000080]
supertip[6,9;1,1;;20;supertip_bgimg;This supertip has a width of 20em!]
box[7.5,9;1,1;#ff000080]
supertip[7.5,9;1,1;;50;supertip_bgimg;This supertip has a width of 50em!]
box[1,11;1,1;#ff000080]
style[supertip_bgimg;bgimg=testformspec_tooltip_style_bg.png;bgimg_middle=8]
supertip[1,11;1,1;;5;supertip_bgimg;This supertip is styled (bgimg)!]
supertip[1,11;1,1;;8;supertip_bgimg;This supertip is styled (bgimg)!]
box[2.5,11;1,1;#ff000080]
style[supertip_bgcolor;bgcolor=#444488]
supertip[2.5,11;1,1;;5;supertip_bgcolor;This supertip is styled (bgcolor)!]
supertip[2.5,11;1,1;;8;supertip_bgcolor;This supertip is styled (bgcolor)!]
box[4,11;1,1;#ff000080]
style[supertip_bgimgcolor;bgimg=testformspec_tooltip_style_bg.png;bgimg_middle=8;bgcolor=#444488]
supertip[4,11;1,1;;5;supertip_bgimgcolor;This supertip is styled (bgimg + bgcolor)!]
supertip[4,11;1,1;;8;supertip_bgimgcolor;This supertip is styled (bgimg + bgcolor)!]
box[5.5,11;1,1;#ff000080]
style[supertip_noborder;border=false]
supertip[5.5,11;1,1;;5;supertip_noborder;This supertip is styled (no border)!]
supertip[5.5,11;1,1;;8;supertip_noborder;This supertip is styled (no border)!]
box[7,11;1,1;#ff000080]
style[supertip_combined;bgimg=testformspec_tooltip_style_bg.png;bgimg_middle=8;bgcolor=#00000000;border=false]
supertip[7,11;1,1;;5;supertip_combined;This supertip is styled (bgimage, transparent bgcolor, no border)!]
supertip[7,11;1,1;;8;supertip_combined;This supertip is styled (bgimage, transparent bgcolor, no border)!]
]]
}

Expand Down
10 changes: 8 additions & 2 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,10 @@ void GUIFormSpecMenu::parseSuperTip(parserData *data, const std::string &element
MY_CHECKPOS("supertip", 0);
MY_CHECKGEOM("supertip", 1);

s32 width = stof(parts[3]) * spacing.Y;
// Tooltip width is defined in em units of the default font
s32 em = g_fontengine->getFontSize(FM_Standard);
s32 width = stof(parts[3]) * em;

v2s32 pos;
v2s32 geom;
v2s32 stpos;
Expand Down Expand Up @@ -1854,7 +1857,10 @@ void GUIFormSpecMenu::parseSuperTip(parserData *data, const std::string &element
}
}

s32 width = stof(parts[2]) * spacing.Y;
// Tooltip width is defined in em units of the default font
s32 em = g_fontengine->getFontSize(FM_Standard);
s32 width = stof(parts[2]) * em;

v2s32 stpos;

if (!floating) {
Expand Down

0 comments on commit e75acb3

Please sign in to comment.