Skip to content

Commit 65a4630

Browse files
sapiersapier
sapier
authored and
sapier
committedJun 18, 2014
Fix bounding rect for formspec elements label vertlabel and checkboxes
1 parent 2a09b7e commit 65a4630

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed
 

‎builtin/mainmenu/tab_credits.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tab_credits = {
2222
caption = fgettext("Credits"),
2323
cbf_formspec = function (tabview, name, tabdata)
2424
local logofile = defaulttexturedir .. "logo.png"
25-
return "vertlabel[0,-0.5;CREDITS]" ..
25+
return "vertlabel[0,-0.25;CREDITS]" ..
2626
"label[0.5,3;Minetest " .. core.get_version() .. "]" ..
2727
"label[0.5,3.3;http://minetest.net]" ..
2828
"image[0.5,1;" .. core.formspec_escape(logofile) .. "]" ..

‎builtin/mainmenu/tab_settings.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ end
7979

8080
local function formspec(tabview, name, tabdata)
8181
local tab_string =
82-
"vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
82+
"vertlabel[0,-0.25;" .. fgettext("SETTINGS") .. "]" ..
8383
"box[0.75,0;3.25,4;#999999]" ..
8484
"checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
8585
.. dump(core.setting_getbool("new_style_leaves")) .. "]"..
@@ -108,7 +108,7 @@ local function formspec(tabview, name, tabdata)
108108
"checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
109109
.. dump(core.setting_getbool("enable_shaders")) .. "]"..
110110
"button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
111-
111+
112112
local android = false
113113
if android then
114114
tab_string = tab_string ..

‎src/guiFormSpecMenu.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
6262
return; \
6363
}
6464

65+
extern gui::IGUIEnvironment* guienv;
6566

6667
/*
6768
GUIFormSpecMenu
@@ -85,7 +86,8 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
8586
m_lock(false),
8687
m_form_src(fsrc),
8788
m_text_dst(tdst),
88-
m_ext_ptr(ext_ptr)
89+
m_ext_ptr(ext_ptr),
90+
m_font(guienv->getSkin()->getFont())
8991
{
9092
current_keys_pending.key_down = false;
9193
current_keys_pending.key_up = false;
@@ -388,15 +390,18 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
388390
pos.X += stof(v_pos[0]) * (float) spacing.X;
389391
pos.Y += stof(v_pos[1]) * (float) spacing.Y;
390392

391-
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
392-
393393
bool fselected = false;
394394

395395
if (selected == "true")
396396
fselected = true;
397397

398398
std::wstring wlabel = narrow_to_wide(label.c_str());
399399

400+
core::rect<s32> rect = core::rect<s32>(
401+
pos.X, pos.Y + ((imgsize.Y/2) - 15),
402+
pos.X + m_font->getDimension(wlabel.c_str()).Width + 25, // text size + size of checkbox
403+
pos.Y + ((imgsize.Y/2) + 15));
404+
400405
FieldSpec spec(
401406
narrow_to_wide(name.c_str()),
402407
wlabel, //Needed for displaying text on MSVC
@@ -1083,15 +1088,18 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
10831088
pos.X += stof(v_pos[0]) * (float)spacing.X;
10841089
pos.Y += stof(v_pos[1]) * (float)spacing.Y;
10851090

1086-
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
1087-
10881091
if(data->bp_set != 2)
10891092
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
10901093

10911094
text = unescape_string(text);
10921095

10931096
std::wstring wlabel = narrow_to_wide(text.c_str());
10941097

1098+
core::rect<s32> rect = core::rect<s32>(
1099+
pos.X, pos.Y+((imgsize.Y/2)-15),
1100+
pos.X + m_font->getDimension(wlabel.c_str()).Width,
1101+
pos.Y+((imgsize.Y/2)+15));
1102+
10951103
FieldSpec spec(
10961104
L"",
10971105
wlabel,
@@ -1119,7 +1127,13 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
11191127
pos.X += stof(v_pos[0]) * (float)spacing.X;
11201128
pos.Y += stof(v_pos[1]) * (float)spacing.Y;
11211129

1122-
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+15, pos.Y+300);
1130+
core::rect<s32> rect = core::rect<s32>(
1131+
pos.X, pos.Y+((imgsize.Y/2)-15),
1132+
pos.X+15, pos.Y +
1133+
(m_font->getKerningHeight() +
1134+
m_font->getDimension(text.c_str()).Height)
1135+
* (text.length()+1));
1136+
//actually text.length() would be correct but adding +1 avoids to break all mods
11231137

11241138
if(data->bp_set != 2)
11251139
errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;

‎src/guiFormSpecMenu.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ class GUIFormSpecMenu : public GUIModalMenu
312312
video::SColor m_slotbg_h;
313313
video::SColor m_slotbordercolor;
314314
private:
315-
IFormSource* m_form_src;
316-
TextDest* m_text_dst;
317-
GUIFormSpecMenu** m_ext_ptr;
315+
IFormSource *m_form_src;
316+
TextDest *m_text_dst;
317+
GUIFormSpecMenu **m_ext_ptr;
318+
gui::IGUIFont *m_font;
318319

319320
typedef struct {
320321
v2s32 size;

0 commit comments

Comments
 (0)
Please sign in to comment.