fixed layout parser adding stack based recursion, code needs being cleaned up but layout works quite well now, added code draw while resizing
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace att
|
||||
{
|
||||
enum class kAttribute : uint8_t { Width, Height, Divisions, InnerRadius, OuterRadius };
|
||||
enum class kAttribute : uint8_t {
|
||||
Width, MinWidth, MaxWidth,
|
||||
Height, MinHeight, MaxHeight,
|
||||
Divisions, InnerRadius, OuterRadius,
|
||||
Grow, Shrink, FlexDir, FlexWrap
|
||||
};
|
||||
|
||||
struct AttributeBase
|
||||
{
|
||||
@@ -14,11 +19,10 @@ namespace att
|
||||
template<kAttribute T, typename V>
|
||||
struct Attribute : public AttributeBase
|
||||
{
|
||||
using type = V;
|
||||
static const kAttribute static_id = T;
|
||||
V value;
|
||||
Attribute() : value{ 0 }, { id = static_id; }
|
||||
Attribute(type v) : value(v) { id = static_id; }
|
||||
Attribute() : value{0} { id = static_id; }
|
||||
Attribute(V v) : value(v) { id = static_id; }
|
||||
};
|
||||
|
||||
struct typemap
|
||||
@@ -29,10 +33,18 @@ namespace att
|
||||
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 },
|
||||
{ "inner-radius", kAttribute::InnerRadius },
|
||||
{ "outer-radius", kAttribute::OuterRadius },
|
||||
{ "grow", kAttribute::Grow },
|
||||
{ "shrink", kAttribute::Shrink },
|
||||
{ "dir", kAttribute::FlexDir },
|
||||
{ "wrap", kAttribute::FlexWrap },
|
||||
};
|
||||
constexpr int map_size = sizeof(map) / sizeof(typemap) - 1;
|
||||
constexpr bool same(const char* a, const char* b)
|
||||
@@ -51,18 +63,26 @@ namespace att
|
||||
|
||||
//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]; }
|
||||
// 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);
|
||||
|
||||
#undef DECLARE_ATTRIBUTE
|
||||
}
|
||||
@@ -76,6 +96,8 @@ protected:
|
||||
GLvoid* ioff[2];
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||
public:
|
||||
YGNodeRef y_node;
|
||||
float x, y;
|
||||
att::AttrubutesMap attribs;
|
||||
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
||||
void draw_fill() const;
|
||||
@@ -126,12 +148,20 @@ public:
|
||||
create_impl(w.value, h.value, div, idx.get(), vertices.get());
|
||||
return create_buffers(idx.get(), vertices.get(), sizeof(idx), sizeof(vertices));
|
||||
}
|
||||
template<typename T>
|
||||
T get_attribute(T def_val)
|
||||
{
|
||||
auto ret = attribs.find(def_val.id);
|
||||
if (ret == attribs.end())
|
||||
return def_val;
|
||||
return *reinterpret_cast<T*>(ret->second.get());
|
||||
}
|
||||
bool create_attrib() override
|
||||
{
|
||||
const att::Width* w = reinterpret_cast<att::Width*>(attribs[att::kAttribute::Width].get());
|
||||
const att::Height* h = reinterpret_cast<att::Height*>(attribs[att::kAttribute::Height].get());
|
||||
const att::Divisions* div = reinterpret_cast<att::Divisions*>(attribs[att::kAttribute::Height].get());
|
||||
return create(*div, *w, *h);
|
||||
const auto w = get_attribute(att::Width(0));
|
||||
const auto h = get_attribute(att::Height(0));
|
||||
const auto d = get_attribute(att::Divisions(1));
|
||||
return create(d, w, h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user