From d9555701ac05b5ae59246f52b2ff69cb4729e6ac Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 2 Oct 2017 23:06:23 +0200 Subject: [PATCH] UI-Coordinates: implement a partial "sub path" order --- src/gui/interact/ui-coord.hpp | 36 ++++++++++++++++++++++++++-- src/lib/path-array.hpp | 5 ++-- src/lib/symbol-impl.cpp | 1 + src/lib/symbol.hpp | 1 + tests/gui/interact/ui-coord-test.cpp | 3 +++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/gui/interact/ui-coord.hpp b/src/gui/interact/ui-coord.hpp index 7bbab5845..0e7da9725 100644 --- a/src/gui/interact/ui-coord.hpp +++ b/src/gui/interact/ui-coord.hpp @@ -187,6 +187,38 @@ namespace interact { } + /** + * Check if this coordinate spec can be seen as an extension + * of the given parent coordinates and thus reaches further down + * towards specific UI elements in comparison to the parent path + * This constitutes a _partial order_, since some paths might + * just be totally unrelated to each other not comparable. + * @note we tolerate (but not demand) expansion/interpolation + * of the given parent, i.e. parent may be incomplete + * or contain `'*'` placeholders. + * @todo 10/2017 have to verify suitability of this definition + */ + bool + isExtendedBelow (UICoord const& parent) const + { + size_t subSiz = this->size(), + parSiz = parent.size(), + idx = 0; + + if (parSiz >= subSiz) + return false; + + while (idx < parSiz + and ( (*this)[idx]== parent[idx] + or Symbol::ANY == parent[idx] + or isnil (parent[idx]))) + ++idx; + + ENSURE (idx < subSiz); + return idx == parSiz; + } // meaning: this goes further down + + /* === String representation === */ @@ -366,12 +398,12 @@ namespace interact { friend bool operator== (UICoord const& l, UICoord const& r) { - return false;//static_cast (l) == static_cast (r); + return static_cast (l) == static_cast (r); } friend bool operator< (UICoord const& l, UICoord const& r) { - UNIMPLEMENTED ("equality of UI coordinates"); + return l.isExtendedBelow (r); } friend bool operator> (UICoord const& l, UICoord const& r) { return (r < l); } diff --git a/src/lib/path-array.hpp b/src/lib/path-array.hpp index 5e3beedbd..58299cd51 100644 --- a/src/lib/path-array.hpp +++ b/src/lib/path-array.hpp @@ -488,7 +488,6 @@ namespace lib { normalise() { if (size() == 0) return; - static Symbol ANY("*"); const char* fill = Symbol::EMPTY; Literal* end = elms_.end(); @@ -498,7 +497,7 @@ namespace lib { setContent (pos, fill); else if (fill==Symbol::EMPTY) - fill = ANY; + fill = Symbol::ANY; if (tail_) { @@ -510,7 +509,7 @@ namespace lib { setContent (pos, fill); else if (fill==Symbol::EMPTY) - fill = ANY; + fill = Symbol::ANY; } size_t idx = size(); diff --git a/src/lib/symbol-impl.cpp b/src/lib/symbol-impl.cpp index 47c410634..a8c7676b9 100644 --- a/src/lib/symbol-impl.cpp +++ b/src/lib/symbol-impl.cpp @@ -82,6 +82,7 @@ namespace lib { /* == predefined marker Symbols == */ + Symbol Symbol::ANY = "*"; Symbol Symbol::EMPTY = ""; Symbol Symbol::BOTTOM = "⟂"; Symbol Symbol::FAILURE = "↯"; diff --git a/src/lib/symbol.hpp b/src/lib/symbol.hpp index 448256375..f796f50b7 100644 --- a/src/lib/symbol.hpp +++ b/src/lib/symbol.hpp @@ -116,6 +116,7 @@ namespace lib { : public Literal { public: + static Symbol ANY; static Symbol EMPTY; static Symbol BOTTOM; static Symbol FAILURE; diff --git a/tests/gui/interact/ui-coord-test.cpp b/tests/gui/interact/ui-coord-test.cpp index 4f8df3b92..f2e99be4c 100644 --- a/tests/gui/interact/ui-coord-test.cpp +++ b/tests/gui/interact/ui-coord-test.cpp @@ -380,6 +380,9 @@ namespace test { CHECK (not (u1 < u1 )); CHECK (not (u1 < u2 )); CHECK (not (u11 < u2 )); + + // expansion of jokers from parent path is tolerated + CHECK (u11 < u1.view("*").window(NULL)); }