added partial mouse events for Windows, implemented clipping rect intersection, added auto value to width and height attributes
This commit is contained in:
@@ -1,45 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<layout>
|
||||
<flex dir="col" wrap="0" width="100%" height="100%" pad="10">
|
||||
<!-- toolbar -->
|
||||
<plane height="50" width="100%" pad="5" dir="row" color=".2">
|
||||
<plane width="50" margin="0 5 0 0" color=".1"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".2"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".3"></plane>
|
||||
<separator width="10" />
|
||||
<plane width="50" margin="0 5 0 0" color=".1"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".2"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".3"></plane>
|
||||
<separator width="10" />
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
<flex dir="col" wrap="0" width="100%" height="100%" pad="5">
|
||||
<!-- toolbar -->
|
||||
<plane height="50" width="100%" pad="5" dir="row" color=".2">
|
||||
<plane width="50" margin="0 5 0 0" color=".1"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".2"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".3"></plane>
|
||||
<separator width="10" />
|
||||
<plane width="50" margin="0 5 0 0" color=".1"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".2"></plane>
|
||||
<plane width="50" margin="0 5 0 0" color=".3"></plane>
|
||||
<separator width="10" />
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
<plane width="50" margin="0 5 0 0"></plane>
|
||||
</plane>
|
||||
<!-- central row -->
|
||||
<plane grow="1" dir="row" wrap="1" height="0">
|
||||
<!-- side bar -->
|
||||
<plane width="200" height="100%" dir="col" color=".2">
|
||||
<plane pad="15" margin="2 2 10 2" color=".3" width="100%" height="auto">
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
</plane>
|
||||
<!-- central row -->
|
||||
<plane grow="1" dir="row" wrap="1" height="0">
|
||||
<!-- side bar -->
|
||||
<plane width="200" height="100%" wrap="1" dir="col">
|
||||
<plane pad="5" margin="2 2 10 2" color=".9" width="100%" height="10">
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
</plane>
|
||||
<plane width="100%" height="1" grow="1" color=".4"/>
|
||||
</plane>
|
||||
<!-- content panel -->
|
||||
<plane width="1" grow="1" height="100%" pad="30" wrap="1">
|
||||
<plane color=".2"></plane>
|
||||
</plane>
|
||||
<plane pad="15" margin="2 2 10 2" color=".3" width="100%" height="auto">
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
<plane height="30" color=".4" />
|
||||
</plane>
|
||||
<!-- status bar -->
|
||||
<plane height="30" width="100%" />
|
||||
<!--<plane height="100%" width="50%" wrap="1" dir="col">
|
||||
<plane height="150" width="100%" />
|
||||
<plane height="50%" width="50%">
|
||||
<plane height="30" width="45" />
|
||||
<plane height="30" width="45" />
|
||||
</plane>
|
||||
</plane>-->
|
||||
</flex>
|
||||
</plane>
|
||||
<!-- content panel -->
|
||||
<plane width="1" grow="1" height="100%" pad="30" wrap="1">
|
||||
<plane color=".2"></plane>
|
||||
</plane>
|
||||
</plane>
|
||||
<!-- status bar -->
|
||||
<plane height="30" width="100%" />
|
||||
</flex>
|
||||
</layout>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -460,13 +460,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
keys[wp] = false;
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
//current->pointerMove(LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_move(LOWORD(lp), HIWORD(lp));
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
//current->pointerDown(LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_down(0, LOWORD(lp), HIWORD(lp));
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
//current->pointerUp(LOWORD(lp), HIWORD(lp));
|
||||
App::I.mouse_up(0, LOWORD(lp), HIWORD(lp));
|
||||
break;
|
||||
}
|
||||
return DefWindowProc(hWnd, msg, wp, lp);
|
||||
|
||||
Reference in New Issue
Block a user