From f227e40180b2035f33059749b14287478bab374a Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Tue, 2 Feb 2021 11:55:13 -0800 Subject: Fix list spacing and size (again) (#10869) --- src/gui/guiFormSpecMenu.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/gui/guiFormSpecMenu.cpp') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index e4678bcd1..88ea77812 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include +#include #include #include #include @@ -500,37 +501,34 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) auto style = getDefaultStyleForElement("list", spec.fname); v2f32 slot_scale = style.getVector2f(StyleSpec::SIZE, v2f32(0, 0)); - v2s32 slot_size( - slot_scale.X <= 0 ? imgsize.X : slot_scale.X * imgsize.X, - slot_scale.Y <= 0 ? imgsize.Y : slot_scale.Y * imgsize.Y + v2f32 slot_size( + slot_scale.X <= 0 ? imgsize.X : std::max(slot_scale.X * imgsize.X, 1), + slot_scale.Y <= 0 ? imgsize.Y : std::max(slot_scale.Y * imgsize.Y, 1) ); v2f32 slot_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1)); - if (data->real_coordinates) { - slot_spacing.X = slot_spacing.X < 0 ? imgsize.X * 0.25f : - imgsize.X * slot_spacing.X; - slot_spacing.Y = slot_spacing.Y < 0 ? imgsize.Y * 0.25f : - imgsize.Y * slot_spacing.Y; + v2f32 default_spacing = data->real_coordinates ? + v2f32(imgsize.X * 0.25f, imgsize.Y * 0.25f) : + v2f32(spacing.X - imgsize.X, spacing.Y - imgsize.Y); - slot_spacing.X += slot_size.X; - slot_spacing.Y += slot_size.Y; - } else { - slot_spacing.X = slot_spacing.X < 0 ? spacing.X : - slot_spacing.X * spacing.X; - slot_spacing.Y = slot_spacing.Y < 0 ? spacing.Y : - slot_spacing.Y * spacing.Y; - } + slot_spacing.X = slot_spacing.X < 0 ? default_spacing.X : + imgsize.X * slot_spacing.X; + slot_spacing.Y = slot_spacing.Y < 0 ? default_spacing.Y : + imgsize.Y * slot_spacing.Y; + + slot_spacing += slot_size; v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) : getElementBasePos(&v_pos); core::rect rect = core::rect(pos.X, pos.Y, - pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X, - pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y); + pos.X + (geom.X - 1) * slot_spacing.X + slot_size.X, + pos.Y + (geom.Y - 1) * slot_spacing.Y + slot_size.Y); GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, - spec.fid, rect, m_invmgr, loc, listname, geom, start_i, slot_size, - slot_spacing, this, data->inventorylist_options, m_font); + spec.fid, rect, m_invmgr, loc, listname, geom, start_i, + v2s32(slot_size.X, slot_size.Y), slot_spacing, this, + data->inventorylist_options, m_font); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); -- cgit v1.2.3