From dd46f8305e5c430b3af5511e81f621262149380d Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 4 Aug 2008 17:44:18 +0000 Subject: Layout parsing. Work in progress. Looks like a GUI! svn-id: r33616 --- gui/ThemeEval.h | 35 ++++++++++++++++++----------------- gui/ThemeParser.cpp | 8 +++++++- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h index f53dfe2cd1..2c57e2732c 100644 --- a/gui/ThemeEval.h +++ b/gui/ThemeEval.h @@ -79,8 +79,8 @@ public: virtual const char *getName() { return "Global Layout"; } - int16 getParentW() { return parent ? parent->w : g_system->getOverlayWidth(); } - int16 getParentH() { return parent ? parent->w : g_system->getOverlayHeight(); } + int16 getParentW() { return parent ? parent->w - parent->paddingLeft - parent->paddingRight : g_system->getOverlayWidth(); } + int16 getParentH() { return parent ? parent->h - parent->paddingTop - parent->paddingBottom : g_system->getOverlayHeight(); } int16 getParentX() { return parent ? parent->x : 0; } int16 getParentY() { return parent ? parent->y : 0; } @@ -209,18 +209,10 @@ public: const char *getName() { return "Horizontal Layout"; } void reflowLayout() { - int curX, curY, mul; - - if (parsingMode == kLayoutParseLeft2Right) { - curX = paddingLeft; - curY = paddingTop; - mul = 1; - } else { - curX = getParentW() - paddingRight; - curY = paddingTop; - mul = -1; - } - + int curX, curY; + + curX = paddingLeft; + curY = paddingTop; w = paddingLeft + paddingRight; for (uint i = 0; i < children.size(); ++i) { @@ -235,15 +227,24 @@ public: assert(children[i]->h != -1); - children[i]->setX((parsingMode == kLayoutParseRight2Left) ? (curX - children[i]->w) : (curX)); + children[i]->setX(curX); children[i]->setY(curY); if (children[i]->h == -1) children[i]->h = h - paddingTop - paddingBottom; + + if (children[i]->w == -1) + children[i]->w = getParentW() - w - spacing; h = MAX(h, (int16)(children[i]->h + paddingTop + paddingBottom)); - - curX += (children[i]->w + spacing) * mul; + + if (parsingMode == kLayoutParseRight2Left) { + for (int j = i - 1; j >= 0; --j) + children[j]->setX(children[i]->w + spacing); + } else { + curX += (children[i]->w + spacing); + } + w += children[i]->w + spacing; } } diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 530f613fdb..982a2b59ae 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -508,13 +508,19 @@ bool ThemeParser::parserCallback_layout(ParserNode *node) { return parserError("Layouts need a specific type (vertical or horizontal)."); GUI::ThemeLayout::LayoutType type = GUI::ThemeLayout::kLayoutNone; + GUI::ThemeLayout::LayoutParsing parsing = GUI::ThemeLayout::kLayoutParseDefault; if (node->values["type"] == "vertical") type = GUI::ThemeLayout::kLayoutVertical; else if (node->values["type"] == "horizontal") type = GUI::ThemeLayout::kLayoutHorizontal; + + if (node->values.contains("direction")) { + if (node->values["direction"] == "right2left") + parsing = GUI::ThemeLayout::kLayoutParseRight2Left; + } - _theme->themeEval()->addLayout(type, GUI::ThemeLayout::kLayoutParseDefault); + _theme->themeEval()->addLayout(type, parsing); return true; } -- cgit v1.2.3