added partial mouse events for Windows, implemented clipping rect intersection, added auto value to width and height attributes

This commit is contained in:
2017-01-25 21:02:26 +00:00
parent 9a4abe8bde
commit 5ae77ee4ac
3 changed files with 90 additions and 62 deletions

View File

@@ -9,6 +9,16 @@ void App::create()
height = 500;
}
glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b)
{
// convert from [x,y,w,h] to [x1,y1,x2,y1]
a = glm::vec4(a.xy(), a.xy() + a.zw());
b = glm::vec4(b.xy(), b.xy() + b.zw());
auto o = glm::vec4(glm::max(a.xy(), b.xy()), glm::min(a.zw(), b.zw()));
o = glm::vec4(o.xy(), glm::max({ 0, 0 }, o.zw() - o.xy()));
return o;
}
void App::update_layout()
{
YGNodeCalculateLayout(y_root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -21,14 +31,18 @@ void App::update_layout()
auto ctx = reinterpret_cast<glm::vec4*>(YGNodeGetContext(y_current));
if (!ctx)
{
float x = YGNodeLayoutGetLeft(y_current);
float y = YGNodeLayoutGetTop(y_current);
float w = YGNodeLayoutGetWidth(y_current);
float h = YGNodeLayoutGetHeight(y_current);
ctx = new glm::vec4(x, y, w, h);
ctx = new glm::vec4();
YGNodeSetContext(y_current, ctx);
}
if (y_current == y_root)
{
ctx->x = YGNodeLayoutGetLeft(y_current);
ctx->y = YGNodeLayoutGetTop(y_current);
ctx->z = YGNodeLayoutGetWidth(y_current);
ctx->w = YGNodeLayoutGetHeight(y_current);
}
int n = YGNodeGetChildCount(y_current);
for (int i = 0; i < n; i++)
{
@@ -39,14 +53,11 @@ void App::update_layout()
float y = YGNodeLayoutGetTop(y_child);
float w = YGNodeLayoutGetWidth(y_child);
float h = YGNodeLayoutGetHeight(y_child);
float pt = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeTop);
float pr = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeRight);
float pb = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeBottom);
float pl = 0;//YGNodeLayoutGetPadding(y_current, YGEdgeLeft);
ctx_child->x = ctx->x + x + pl;
ctx_child->y = ctx->y + y + pt;
ctx_child->z = w - (pl + pr);
ctx_child->w = h - (pt + pb);
ctx_child->x = ctx->x + x;
ctx_child->y = ctx->y + y;
ctx_child->z = w;
ctx_child->w = h;
*ctx_child = rect_intersection(*ctx_child, *ctx);
YGNodeSetContext(y_child, ctx_child);
y_stack.emplace(y_child);
}
@@ -126,6 +137,9 @@ void App::load_layout()
YGNodeStyleSetPosition(y_node, YGEdgeRight, 0);
YGNodeStyleSetPosition(y_node, YGEdgeBottom, 0);
YGNodeStyleSetPosition(y_node, YGEdgeLeft, 0);
YGNodeStyleSetOverflow(y_node, YGOverflowHidden);
while (attr)
{
const auto ka = att::value(attr->Name());
@@ -133,10 +147,18 @@ void App::load_layout()
switch (ka)
{
case att::kAttribute::Width:
if (strchr(attr->Value(), '%'))
YGNodeStyleSetWidthPercent(y_node, attr->FloatValue());
if (strcmp(attr->Value(), "auto") == 0)
{
YGNodeStyleSetWidth(y_node, YGUndefined);
YGNodeStyleSetWidthPercent(y_node, YGUndefined);
}
else
YGNodeStyleSetWidth(y_node, attr->FloatValue());
{
if (strchr(attr->Value(), '%'))
YGNodeStyleSetWidthPercent(y_node, attr->FloatValue());
else
YGNodeStyleSetWidth(y_node, attr->FloatValue());
}
break;
case att::kAttribute::MinWidth:
if (strchr(attr->Value(), '%'))
@@ -148,10 +170,18 @@ void App::load_layout()
YGNodeStyleSetMaxWidth(y_node, attr->FloatValue());
break;
case att::kAttribute::Height:
if (strchr(attr->Value(), '%'))
YGNodeStyleSetHeightPercent(y_node, attr->FloatValue());
if (strcmp(attr->Value(), "auto") == 0)
{
YGNodeStyleSetHeight(y_node, YGUndefined);
YGNodeStyleSetHeightPercent(y_node, YGUndefined);
}
else
YGNodeStyleSetHeight(y_node, attr->FloatValue());
{
if (strchr(attr->Value(), '%'))
YGNodeStyleSetHeightPercent(y_node, attr->FloatValue());
else
YGNodeStyleSetHeight(y_node, attr->FloatValue());
}
break;
case att::kAttribute::MinHeight:
YGNodeStyleSetMinHeight(y_node, attr->FloatValue());