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 <rw@rubenwardy.com>
This commit is contained in:
Vincent Robinson
2021-01-23 12:46:19 -08:00
committed by GitHub
parent 4c76239818
commit 009e39e73b
4 changed files with 78 additions and 22 deletions

View File

@@ -55,6 +55,8 @@ public:
BORDERCOLORS,
BORDERWIDTHS,
SOUND,
SPACING,
SIZE,
NUM_PROPERTIES,
NONE
};
@@ -119,6 +121,10 @@ public:
return BORDERWIDTHS;
} else if (name == "sound") {
return SOUND;
} else if (name == "spacing") {
return SPACING;
} else if (name == "size") {
return SIZE;
} else {
return NONE;
}
@@ -259,27 +265,40 @@ public:
return rect;
}
irr::core::vector2d<s32> getVector2i(Property prop, irr::core::vector2d<s32> def) const
v2f32 getVector2f(Property prop, v2f32 def) const
{
const auto &val = properties[prop];
if (val.empty())
return def;
irr::core::vector2d<s32> vec;
if (!parseVector2i(val, &vec))
v2f32 vec;
if (!parseVector2f(val, &vec))
return def;
return vec;
}
irr::core::vector2d<s32> getVector2i(Property prop) const
v2s32 getVector2i(Property prop, v2s32 def) const
{
const auto &val = properties[prop];
if (val.empty())
return def;
v2f32 vec;
if (!parseVector2f(val, &vec))
return def;
return v2s32(vec.X, vec.Y);
}
v2s32 getVector2i(Property prop) const
{
const auto &val = properties[prop];
FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
irr::core::vector2d<s32> vec;
parseVector2i(val, &vec);
return vec;
v2f32 vec;
parseVector2f(val, &vec);
return v2s32(vec.X, vec.Y);
}
gui::IGUIFont *getFont() const
@@ -432,22 +451,20 @@ private:
return true;
}
bool parseVector2i(const std::string &value, irr::core::vector2d<s32> *parsed_vec) const
bool parseVector2f(const std::string &value, v2f32 *parsed_vec) const
{
irr::core::vector2d<s32> vec;
v2f32 vec;
std::vector<std::string> v_vector = split(value, ',');
if (v_vector.size() == 1) {
s32 x = stoi(v_vector[0]);
f32 x = stof(v_vector[0]);
vec.X = x;
vec.Y = x;
} else if (v_vector.size() == 2) {
s32 x = stoi(v_vector[0]);
s32 y = stoi(v_vector[1]);
vec.X = x;
vec.Y = y;
vec.X = stof(v_vector[0]);
vec.Y = stof(v_vector[1]);
} else {
warningstream << "Invalid vector2d string format: \"" << value
warningstream << "Invalid 2d vector string format: \"" << value
<< "\"" << std::endl;
return false;
}