From 009e39e73b9aa003c369fe6bc88f366fdc91610e Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Sat, 23 Jan 2021 12:46:19 -0800 Subject: FormSpec: Add list spacing, slot size, and noclip (#10083) * Add list spacing, slot size, and noclip * Simplify StyleSpec * Add test cases Co-authored-by: rubenwardy --- src/gui/guiFormSpecMenu.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/gui/guiFormSpecMenu.cpp') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 4415bdd3a..7b37de6f8 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -497,20 +497,40 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) 3 ); - v2f32 slot_spacing = data->real_coordinates ? - v2f32(imgsize.X * 1.25f, imgsize.Y * 1.25f) : spacing; + auto style = getDefaultStyleForElement("list", spec.fname); - v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) - : getElementBasePos(&v_pos); + 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_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1)); + if (data->real_coordinates) { + slot_spacing.X = slot_spacing.X < 0 ? imgsize.X * 1.25f : + slot_spacing.X * imgsize.X + imgsize.X; + slot_spacing.Y = slot_spacing.Y < 0 ? imgsize.Y * 1.25f : + slot_spacing.Y * imgsize.Y + imgsize.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; + } + + 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); GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, - spec.fid, rect, m_invmgr, loc, listname, geom, start_i, imgsize, + spec.fid, rect, m_invmgr, loc, listname, geom, start_i, slot_size, slot_spacing, this, data->inventorylist_options, m_font); + e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); + m_inventorylists.push_back(e); m_fields.push_back(spec); return; -- cgit v1.2.3