complete refactoring and cleanup old layout loading code
This commit is contained in:
@@ -1,99 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace att
|
||||
{
|
||||
enum class kAttribute : uint8_t {
|
||||
Width, MinWidth, MaxWidth,
|
||||
Height, MinHeight, MaxHeight,
|
||||
Divisions, InnerRadius, OuterRadius,
|
||||
Grow, Shrink, FlexDir, FlexWrap,
|
||||
Padding, Margin,
|
||||
Color
|
||||
};
|
||||
|
||||
struct AttributeBase
|
||||
{
|
||||
kAttribute id;
|
||||
};
|
||||
|
||||
typedef std::map<att::kAttribute, std::unique_ptr<att::AttributeBase>> AttrubutesMap;
|
||||
|
||||
template<kAttribute T, typename V>
|
||||
struct Attribute : public AttributeBase
|
||||
{
|
||||
static const kAttribute static_id = T;
|
||||
V value;
|
||||
Attribute() : value{0} { id = static_id; }
|
||||
Attribute(V v) : value(v) { id = static_id; }
|
||||
};
|
||||
|
||||
struct typemap
|
||||
{
|
||||
const char* name;
|
||||
kAttribute value;
|
||||
};
|
||||
static constexpr typemap map[] =
|
||||
{
|
||||
{ "width", kAttribute::Width },
|
||||
{ "min-width", kAttribute::MinWidth },
|
||||
{ "max-width", kAttribute::MaxWidth },
|
||||
{ "height", kAttribute::Height },
|
||||
{ "min-height", kAttribute::MinHeight },
|
||||
{ "max-height", kAttribute::MaxHeight },
|
||||
{ "divisions", kAttribute::Divisions },
|
||||
{ "inner-radius", kAttribute::InnerRadius },
|
||||
{ "outer-radius", kAttribute::OuterRadius },
|
||||
{ "grow", kAttribute::Grow },
|
||||
{ "shrink", kAttribute::Shrink },
|
||||
{ "dir", kAttribute::FlexDir },
|
||||
{ "wrap", kAttribute::FlexWrap },
|
||||
{ "pad", kAttribute::Padding },
|
||||
{ "margin", kAttribute::Margin },
|
||||
{ "color", kAttribute::Color },
|
||||
};
|
||||
constexpr int map_size = sizeof(map) / sizeof(typemap) - 1;
|
||||
constexpr bool same(const char* a, const char* b)
|
||||
{
|
||||
return (*a && *b) ? (*a == *b && same(a + 1, b + 1)) : !(*a || *b);
|
||||
}
|
||||
constexpr const kAttribute value(char const *name, int i = 0)
|
||||
{
|
||||
return ((i >= map_size) || same(map[i].name, name)) ?
|
||||
map[i].value : value(name, i + 1);
|
||||
}
|
||||
constexpr const char* string(const kAttribute value, int i = 0)
|
||||
{
|
||||
return (map[i].value == value) ? map[i].name : string(value, i + 1);
|
||||
}
|
||||
|
||||
//constexpr const char* string(kAttribute a) { return names[(int)a]; }
|
||||
|
||||
// template<kAttribute T, typename V>
|
||||
// constexpr const char* string(const Attribute<T, V> a) { return names[(int)a.id]; }
|
||||
|
||||
#define DECLARE_ATTRIBUTE(N,T) \
|
||||
struct N : public Attribute<kAttribute::N,T> \
|
||||
{ using Attribute<kAttribute::N,T>::Attribute; };
|
||||
|
||||
DECLARE_ATTRIBUTE(Width, float);
|
||||
DECLARE_ATTRIBUTE(MinWidth, float);
|
||||
DECLARE_ATTRIBUTE(MaxWidth, float);
|
||||
DECLARE_ATTRIBUTE(Height, float);
|
||||
DECLARE_ATTRIBUTE(MinHeight, float);
|
||||
DECLARE_ATTRIBUTE(MaxHeight, float);
|
||||
DECLARE_ATTRIBUTE(Divisions, int);
|
||||
DECLARE_ATTRIBUTE(InnerRadius, float);
|
||||
DECLARE_ATTRIBUTE(OuterRadius, float);
|
||||
DECLARE_ATTRIBUTE(Grow, float);
|
||||
DECLARE_ATTRIBUTE(Shrink, float);
|
||||
DECLARE_ATTRIBUTE(FlexDir, int);
|
||||
DECLARE_ATTRIBUTE(FlexWrap, int);
|
||||
DECLARE_ATTRIBUTE(Padding, glm::vec4);
|
||||
DECLARE_ATTRIBUTE(Margin, glm::vec4);
|
||||
DECLARE_ATTRIBUTE(Color, glm::vec4);
|
||||
|
||||
#undef DECLARE_ATTRIBUTE
|
||||
}
|
||||
#include "layout.h"
|
||||
|
||||
class Shape
|
||||
{
|
||||
@@ -104,8 +10,6 @@ protected:
|
||||
GLvoid* ioff[2]{ 0 };
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||
public:
|
||||
YGNodeRef y_node;
|
||||
glm::vec4 color;
|
||||
att::AttrubutesMap attribs;
|
||||
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
||||
void draw_fill() const;
|
||||
|
||||
Reference in New Issue
Block a user