From eb7282e0d40fbec4dc8266f322b7a8ccac3fbcd9 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 19 Jan 2017 19:12:12 +0000 Subject: [PATCH] testing yoga and tinyxml2 to read some attributes from file --- data/layout.xml | 3 ++- engine/app.cpp | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/data/layout.xml b/data/layout.xml index 1d49482..8603411 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -1,4 +1,5 @@ - + + diff --git a/engine/app.cpp b/engine/app.cpp index 2fc3d8f..54e9d7b 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -53,10 +53,32 @@ void App::init() " frag = col;" "}"; + auto y_root = YGNodeNew(); tinyxml2::XMLDocument xml; auto ret = xml.LoadFile("data\\layout.xml"); auto root = xml.RootElement(); -// root-> + auto child = root->FirstChildElement(); + while (child) + { + printf("Element %s: ", child->Name()); + auto attr = child->FirstAttribute(); + auto y_node = YGNodeNew(); + YGNodeInsertChild(y_root, y_node, 0); + while (attr) + { + printf("%s=%s ", attr->Name(), attr->Value()); + if (strcmp("width", attr->Name()) == 0) + { + if (strchr(attr->Value(), '%')) + YGNodeStyleSetWidthPercent(y_node, attr->FloatValue()); + else + YGNodeStyleSetWidth(y_node, attr->FloatValue()); + } + attr = attr->Next(); + } + printf("\n"); + child = child->NextSiblingElement(); + } shader.create(shader_v, shader_f); shader_color.create(shader_color_v, shader_color_f);