Fix bounding rect for formspec elements label vertlabel and checkboxes
authorsapier <Sapier at GMX dot net>
Wed, 18 Jun 2014 20:38:29 +0000 (22:38 +0200)
committersapier <Sapier at GMX dot net>
Wed, 18 Jun 2014 20:38:29 +0000 (22:38 +0200)
builtin/mainmenu/tab_credits.lua
builtin/mainmenu/tab_settings.lua
src/guiFormSpecMenu.cpp
src/guiFormSpecMenu.h

index f752d1728736ef320aae7b2c47f9bbee4137bee1..8e5ce4d7b3be4180d9cbee5fade5abb23b9b0abe 100644 (file)
@@ -22,7 +22,7 @@ tab_credits = {
        caption = fgettext("Credits"),
        cbf_formspec = function (tabview, name, tabdata)
                        local logofile = defaulttexturedir .. "logo.png"
-                       return  "vertlabel[0,-0.5;CREDITS]" ..
+                       return  "vertlabel[0,-0.25;CREDITS]" ..
                                "label[0.5,3;Minetest " .. core.get_version() .. "]" ..
                                "label[0.5,3.3;http://minetest.net]" ..
                                "image[0.5,1;" .. core.formspec_escape(logofile) .. "]" ..
index 2d013a5ac312b0ca6edf2fab620fc0d05a685d36..b6ffa86ed66bc2d6b1a7db49fa6ed2962afc520a 100644 (file)
@@ -79,7 +79,7 @@ end
 
 local function formspec(tabview, name, tabdata)
        local tab_string =
-               "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
+               "vertlabel[0,-0.25;" .. fgettext("SETTINGS") .. "]" ..
                "box[0.75,0;3.25,4;#999999]" ..
                "checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
                                .. dump(core.setting_getbool("new_style_leaves")) .. "]"..
@@ -108,7 +108,7 @@ local function formspec(tabview, name, tabdata)
                "checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
                                .. dump(core.setting_getbool("enable_shaders")) .. "]"..
                "button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
-       
+
        local android = false
        if android then
                tab_string = tab_string ..
index c16600733699dba8589d42c7a855ba0a68357499..9e9e59fe42c2914e47d72ace090167b37a2794cd 100644 (file)
@@ -62,6 +62,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                        return;                                                                                                                 \
        }
 
+extern gui::IGUIEnvironment* guienv;
 
 /*
        GUIFormSpecMenu
@@ -85,7 +86,8 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
        m_lock(false),
        m_form_src(fsrc),
        m_text_dst(tdst),
-       m_ext_ptr(ext_ptr)
+       m_ext_ptr(ext_ptr),
+       m_font(guienv->getSkin()->getFont())
 {
        current_keys_pending.key_down = false;
        current_keys_pending.key_up = false;
@@ -388,8 +390,6 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
                pos.X += stof(v_pos[0]) * (float) spacing.X;
                pos.Y += stof(v_pos[1]) * (float) spacing.Y;
 
-               core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
-
                bool fselected = false;
 
                if (selected == "true")
@@ -397,6 +397,11 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
 
                std::wstring wlabel = narrow_to_wide(label.c_str());
 
+               core::rect<s32> rect = core::rect<s32>(
+                               pos.X, pos.Y + ((imgsize.Y/2) - 15),
+                               pos.X + m_font->getDimension(wlabel.c_str()).Width + 25, // text size + size of checkbox
+                               pos.Y + ((imgsize.Y/2) + 15));
+
                FieldSpec spec(
                                narrow_to_wide(name.c_str()),
                                wlabel, //Needed for displaying text on MSVC
@@ -1083,8 +1088,6 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
                pos.X += stof(v_pos[0]) * (float)spacing.X;
                pos.Y += stof(v_pos[1]) * (float)spacing.Y;
 
-               core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
-
                if(data->bp_set != 2)
                        errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
 
@@ -1092,6 +1095,11 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
 
                std::wstring wlabel = narrow_to_wide(text.c_str());
 
+               core::rect<s32> rect = core::rect<s32>(
+                               pos.X, pos.Y+((imgsize.Y/2)-15),
+                               pos.X + m_font->getDimension(wlabel.c_str()).Width,
+                               pos.Y+((imgsize.Y/2)+15));
+
                FieldSpec spec(
                        L"",
                        wlabel,
@@ -1119,7 +1127,13 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
                pos.X += stof(v_pos[0]) * (float)spacing.X;
                pos.Y += stof(v_pos[1]) * (float)spacing.Y;
 
-               core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+15, pos.Y+300);
+               core::rect<s32> rect = core::rect<s32>(
+                               pos.X, pos.Y+((imgsize.Y/2)-15),
+                               pos.X+15, pos.Y +
+                                       (m_font->getKerningHeight() +
+                                       m_font->getDimension(text.c_str()).Height)
+                                       * (text.length()+1));
+               //actually text.length() would be correct but adding +1 avoids to break all mods
 
                if(data->bp_set != 2)
                        errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
index 474f13cb158c6c4dd047fba0dc35cdf04ea31f00..91605bc1606bf511f2e0e2f6d8ceaa30e68bbb12 100644 (file)
@@ -312,9 +312,10 @@ protected:
        video::SColor m_slotbg_h;
        video::SColor m_slotbordercolor;
 private:
-       IFormSource*      m_form_src;
-       TextDest*         m_text_dst;
-       GUIFormSpecMenu** m_ext_ptr;
+       IFormSource      *m_form_src;
+       TextDest         *m_text_dst;
+       GUIFormSpecMenu **m_ext_ptr;
+       gui::IGUIFont    *m_font;
 
        typedef struct {
                v2s32 size;