From 1079d51c7ea10ca2e80ddce728a70588662f6fb7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 1 Oct 2017 21:37:04 +0200 Subject: [PATCH] UI-Coordinates: implement named component access --- src/gui/interact/ui-coord.hpp | 45 ++++++++++++----------------------- src/lib/path-array.hpp | 2 ++ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/gui/interact/ui-coord.hpp b/src/gui/interact/ui-coord.hpp index f417176ca..2584f92c7 100644 --- a/src/gui/interact/ui-coord.hpp +++ b/src/gui/interact/ui-coord.hpp @@ -67,6 +67,7 @@ namespace interact { // using std::unique_ptr; using std::string; using lib::Literal; + using lib::Symbol; using util::unConst; using util::isnil; using util::min; @@ -97,10 +98,10 @@ namespace interact { class UICoord : public lib::PathArray { - using PArr = lib::PathArray; + using PathAry = lib::PathArray; public: - using PArr::PathArray; + using PathAry::PathArray; /* === Builder API === */ @@ -167,35 +168,12 @@ namespace interact { /* === named component access === */ - Literal - getWindow() const - { - UNIMPLEMENTED ("UI coordinate component access"); - } + Literal getWindow() const { return accesComponent (UIC_WINDOW);} + Literal getPersp() const { return accesComponent (UIC_PERSP); } + Literal getPanel() const { return accesComponent (UIC_PANEL); } + Literal getView() const { return accesComponent (UIC_VIEW); } + Literal getTab() const { return accesComponent (UIC_TAB); } - Literal - getPersp() const - { - UNIMPLEMENTED ("UI coordinate component access"); - } - - Literal - getPanel() const - { - UNIMPLEMENTED ("UI coordinate component access"); - } - - Literal - getView() const - { - UNIMPLEMENTED ("UI coordinate component access"); - } - - Literal - getTab() const - { - UNIMPLEMENTED ("UI coordinate component access"); - } /* === String representation === */ @@ -286,6 +264,13 @@ namespace interact { private: + Literal + accesComponent (UIPathElm idx) const + { + Literal* elm = unConst(this)->getPosition(UIC_WINDOW); + return (elm and *elm)? *elm : Symbol::EMPTY; + } + public: friend bool diff --git a/src/lib/path-array.hpp b/src/lib/path-array.hpp index b4e268b65..8b5556c38 100644 --- a/src/lib/path-array.hpp +++ b/src/lib/path-array.hpp @@ -423,6 +423,8 @@ namespace lib { /** * @internal access content element by index * @return pointer to storage, `null` if out of bounds + * @warning in case of size() < chunk_size the pointed-to storage + * might hold an invalid (NULL) Literal. */ Literal* getPosition (size_t idx)