From 7b2c98474fcc9db0fc1352b49b5ecffff5acfa4c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 16 Oct 2017 02:39:22 +0200 Subject: [PATCH] Navigator: initial draft of a UI coordinate resolver ...which in turn will drive the design of the LoactionQuery API --- src/gui/interact/gen-node-location-query.hpp | 99 +++++++++++++++++++ src/gui/interact/ui-coord-resolver.hpp | 66 +++++++++++-- src/gui/interact/ui-coord.hpp | 3 +- tests/gui/interact/ui-coord-resolver-test.cpp | 19 +++- 4 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 src/gui/interact/gen-node-location-query.hpp diff --git a/src/gui/interact/gen-node-location-query.hpp b/src/gui/interact/gen-node-location-query.hpp new file mode 100644 index 000000000..bf6b4b1d6 --- /dev/null +++ b/src/gui/interact/gen-node-location-query.hpp @@ -0,0 +1,99 @@ +/* + GEN-NODE-LOCATION-QUERY.hpp - pose UI-coordinate location queries against a GenNode structure + + Copyright (C) Lumiera.org + 2017, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + + +/** @file gen-node-location-query.hpp + ** Implementation of the gui::interact::LocationQuery interface to work on a GenNode tree. + ** The interface allows to pose queries against a concrete structure to verify and reshape some + ** [UI Coordinate specification](\ref UICoord); basically it offers methods to navigate within a + ** tree-like structure. While in the actual implementation, such a query interface would be backed + ** by navigating real UI structures, the implementation given here instead uses a generic tree structure + ** given as `Record`. + ** + ** @todo WIP 10/2017 started in the effort of shaping the LoactionQuery interface, and used + ** to support writing unit tests, to verify the UiCoordResolver. It remains to be seen + ** if this implementation can be used beyond this limited purpose + ** + ** @see UICoordResolver_test + ** @see ui-coord-resolver.hpp + ** @see navigator.hpp + */ + + +#ifndef GUI_INTERACT_GEN_NODE_LOCATION_QUERY_H +#define GUI_INTERACT_GEN_NODE_LOCATION_QUERY_H + +#include "lib/error.hpp" +//#include "lib/symbol.hpp" +#include "gui/interact/ui-coord-resolver.hpp" +#include "lib/diff/gen-node.hpp" +//#include "lib/util.hpp" + +//#include +//#include +//#include +//#include +//#include + + +namespace gui { +namespace interact { + + namespace error = lumiera::error; + +// using std::unique_ptr; +// using std::string; +// using lib::Literal; +// using lib::Symbol; + using lib::diff::Rec; +// using util::unConst; +// using util::isnil; +// using util::min; + + + + + /** + * Query and mutate UICoord specifications in relation to actual UI topology. + * + * @todo initial draft as of 10/2017 + */ + class GenNodeLocationQuery + : public LocationQuery + { + + public: + GenNodeLocationQuery(Rec const& backingStructure) + { } + + + /* === LocationQuery interface === */ + + /** */ + + private: + }; + + + +}}// namespace gui::interact +#endif /*GUI_INTERACT_GEN_NODE_LOCATION_QUERY_H*/ diff --git a/src/gui/interact/ui-coord-resolver.hpp b/src/gui/interact/ui-coord-resolver.hpp index efdae5c43..e3288699b 100644 --- a/src/gui/interact/ui-coord-resolver.hpp +++ b/src/gui/interact/ui-coord-resolver.hpp @@ -46,14 +46,14 @@ #define GUI_INTERACT_UI_COORD_RESOLVER_H #include "lib/error.hpp" -//#include "lib/symbol.hpp" +#include "lib/symbol.hpp" #include "gui/interact/ui-coord.hpp" //#include "lib/util.hpp" //#include //#include //#include -//#include +#include //#include @@ -65,7 +65,7 @@ namespace interact { // using std::unique_ptr; // using std::string; // using lib::Literal; -// using lib::Symbol; + using lib::Symbol; // using util::unConst; // using util::isnil; // using util::min; @@ -73,28 +73,74 @@ namespace interact { + /** + * Interface to discover a backing structure for the purpose of + * path navigation and resolution. + */ + class LocationQuery + { + public: + virtual ~LocationQuery() { } ///< this is an interface + + /** */ + }; + + + + /** * Query and mutate UICoord specifications in relation to actual UI topology. * * @todo initial draft as of 10/2017 */ class UICoordResolver + : public UICoord::Builder { public: - - - - /* === named component access === */ - - /** */ - + UICoordResolver (UICoord const& uic, LocationQuery& queryAPI) + : Builder{uic} + { } /* === query functions === */ + /** */ + bool + isCovered() const + { + UNIMPLEMENTED ("path coverage check"); + } + + /** */ + bool + canCover() const + { + UNIMPLEMENTED ("determine if a mutation is possible to get the path covered"); + } + + + + /* === mutation functions === */ + /** */ + UICoordResolver + cover() + { + UNIMPLEMENTED ("mutate the path to get it covered"); + return std::move (*this); + } + + + /** + */ + UICoordResolver + extend (Literal pathExtension) + { + UNIMPLEMENTED ("mutate the path to extend it while keeping it partially covered"); + return std::move (*this); + } private: diff --git a/src/gui/interact/ui-coord.hpp b/src/gui/interact/ui-coord.hpp index eac41c26d..99db326be 100644 --- a/src/gui/interact/ui-coord.hpp +++ b/src/gui/interact/ui-coord.hpp @@ -463,9 +463,10 @@ namespace interact { { UICoord uic_; - /** builder instances created by UICoord solely */ + /** builder instances created by UICoord */ friend class UICoord; + protected: template explicit Builder (ARGS&& ...args) : uic_{std::forward (args)...} { } diff --git a/tests/gui/interact/ui-coord-resolver-test.cpp b/tests/gui/interact/ui-coord-resolver-test.cpp index 1b598f411..c4e54c4d0 100644 --- a/tests/gui/interact/ui-coord-resolver-test.cpp +++ b/tests/gui/interact/ui-coord-resolver-test.cpp @@ -29,6 +29,7 @@ #include "lib/test/test-helper.hpp" #include "gui/interact/ui-coord.hpp" #include "gui/interact/ui-coord-resolver.hpp" +#include "gui/interact/gen-node-location-query.hpp" #include "lib/diff/gen-node.hpp" #include "lib/format-cout.hpp"/////////////////////////TODO RLY? #include "lib/format-util.hpp" @@ -96,15 +97,29 @@ namespace test { void verify_simpleUsage() { - Rec dummyUiStrcture = MakeRec().scope( + // a Test dummy placeholder for the real UI structure + Rec dummyUiStructure = MakeRec().scope( MakeRec().type("perspective-A") .genNode("window-1"), MakeRec().type("perspective-B") .scope( MakeRec().genNode("panelX") ).genNode("window-2") - ); + ); + // helper to answer "location queries" backed by this structure + GenNodeLocationQuery locationQuery{dummyUiStructure}; + + UICoord uic{"window-1","*","panelX","someView"}; + UICoordResolver resolver{uic, locationQuery}; + + CHECK (not resolver.isCovered()); + CHECK (not resolver.canCover()); + + UICoord uic2 = resolver.cover() + .extend("otherView"); + + CHECK ("UI:window-2[perspective-B]-panelX.otherView" == string(uic2)); }