Load GUI from XML

This commit is contained in:
2015-03-10 00:48:25 +01:00
parent 9d7dd452c7
commit 884fd8bb52
21 changed files with 1019 additions and 119 deletions

44
View.cc
View File

@@ -17,7 +17,7 @@ void View::addChild(std::unique_ptr<Widget> child)
layout();
}
Widget& View::getChildByName(std::string name)
Widget& View::getChildByName(std::string const& name)
{
if (name == "")
throw ChildNotFoundException{};
@@ -30,7 +30,7 @@ Widget& View::getChildByName(std::string name)
throw ChildNotFoundException{};
}
Widget const& View::getChildByName(std::string name) const
Widget const& View::getChildByName(std::string const& name) const
{
if (name == "")
throw ChildNotFoundException{};
@@ -43,7 +43,45 @@ Widget const& View::getChildByName(std::string name) const
throw ChildNotFoundException{};
}
std::unique_ptr<Widget> View::removeChild(std::string name)
Widget& View::getPath(std::string const& path)
{
auto slash = path.find('/');
// Last path element
if (slash == std::string::npos)
return getChildByName(path);
auto first = path.substr(0, slash);
auto& child = getChildByName(first);
try {
View& next = dynamic_cast<View&>(child);
return next.getPath(path.substr(slash+1));
} catch(std::bad_cast &ex) {
throw ChildNotFoundException{};
}
}
Widget const& View::getPath(std::string const& path) const
{
auto slash = path.find('/');
// Last path element
if (slash == std::string::npos)
return getChildByName(path);
auto first = path.substr(0, slash);
auto& child = getChildByName(first);
try {
View const& next = dynamic_cast<View const&>(child);
return next.getPath(path.substr(slash+1));
} catch(std::bad_cast &ex) {
throw ChildNotFoundException{};
}
}
std::unique_ptr<Widget> View::removeChild(std::string const& name)
{
if (name == "")
throw ChildNotFoundException{};