ui: only single class expand button next to class name

This change reduces the size of collapsed classes in the GraphView by removing the condensed view of the class access
nodes and using a single button next to the class name for collapsing and expanding instead.
This commit is contained in:
Eberhard Graether
2015-04-28 20:08:05 +02:00
parent a0340d9438
commit 791189c3c3
16 changed files with 296 additions and 208 deletions
@@ -53,7 +53,7 @@ void GraphController::handleMessage(MessageFinishedParsing* message)
void GraphController::handleMessage(MessageGraphNodeExpand* message)
{
DummyNode* node = findDummyNodeAccessRecursive(m_dummyNodes, message->tokenId, message->access);
DummyNode* node = findDummyNodeRecursive(m_dummyNodes, message->tokenId);
if (node)
{
if (node->autoExpanded)
@@ -144,16 +144,22 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node)
// there is a global root node with id 0 afaik, so here we actually want the one node below this global root
Node* parent = node;
while(parent != NULL && parent->getParentNode() != NULL)
while (parent != NULL && parent->getParentNode() != NULL)
{
parent = parent->getParentNode();
}
if(parent != NULL)
if (parent != NULL)
{
result.topLevelAncestorId = parent->getId();
}
DummyNode* oldNode = findDummyNodeRecursive(m_dummyNodes, node->getId());
if (oldNode)
{
result.expanded = oldNode->expanded;
}
node->forEachChildNode(
[node, &result, this](Node* child)
{
@@ -196,12 +202,6 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node)
accessNode.accessType = accessType;
result.subNodes.push_back(accessNode);
parent = &result.subNodes.back();
DummyNode* oldParent = findDummyNodeAccessRecursive(m_dummyNodes, node->getId(), accessType);
if (oldParent)
{
parent->expanded = oldParent->expanded;
}
}
}
@@ -240,17 +240,9 @@ void GraphController::autoExpandActiveNode(const std::vector<Id>& activeTokenIds
node = findDummyNodeRecursive(m_dummyNodes, activeTokenIds[0]);
}
if (!node)
if (node && node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT))
{
return;
}
if (node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT))
{
for (DummyNode& subNode : node->subNodes)
{
subNode.autoExpanded = true;
}
node->autoExpanded = true;
}
}
@@ -328,9 +320,10 @@ void GraphController::setActiveAndVisibility(const std::vector<Id>& activeTokenI
void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds) const
{
node.visible = false;
node.childVisible = false;
node.active = false;
if (node.data)
if (node.isGraphNode())
{
node.active = find(activeTokenIds.begin(), activeTokenIds.end(), node.data->getId()) != activeTokenIds.end();
}
@@ -343,34 +336,35 @@ void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector<
bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const
{
bool childVisible = false;
for (DummyNode& subNode : node.subNodes)
{
if (setNodeVisibilityRecursiveBottomUp(subNode, aggregated | node.aggregated))
{
childVisible = true;
node.childVisible = true;
}
}
if (node.active || node.connected || childVisible || (!aggregated && node.aggregated))
if (node.active || node.connected || node.childVisible || (!aggregated && node.aggregated))
{
setNodeVisibilityRecursiveTopDown(node);
setNodeVisibilityRecursiveTopDown(node, false);
}
return node.visible;
}
void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node) const
void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const
{
node.visible = true;
for (DummyNode& subNode : node.subNodes)
if ((node.isGraphNode() && node.isExpanded()) ||
(node.isAccessNode() && parentExpanded) ||
(node.isGraphNode() && node.data->isType(Node::NODE_ENUM)) ||
(node.isGraphNode() && node.active && node.data->isType(Node::NODE_NAMESPACE | Node::NODE_UNDEFINED)))
{
if (subNode.accessType != TokenComponentAccess::ACCESS_NONE || node.isExpanded() ||
(node.data && node.data->isType(Node::NODE_ENUM)) ||
(node.active && node.data && node.data->isType(Node::NODE_NAMESPACE | Node::NODE_UNDEFINED)))
for (DummyNode& subNode : node.subNodes)
{
setNodeVisibilityRecursiveTopDown(subNode);
node.childVisible = true;
setNodeVisibilityRecursiveTopDown(subNode, node.isExpanded());
}
}
}
@@ -387,23 +381,17 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
{
GraphViewStyle::NodeMargins margins;
if (node.data)
if (node.isGraphNode())
{
margins = GraphViewStyle::getMarginsForNodeType(node.data->getType(), node.subNodes.size() > 0);
margins = GraphViewStyle::getMarginsForNodeType(node.data->getType(), node.childVisible);
}
else
else if (node.isAccessNode())
{
node.invisibleSubNodeCount = 0;
for (const DummyNode& subNode : node.subNodes)
{
if (!subNode.visible)
{
node.invisibleSubNodeCount++;
}
}
margins = GraphViewStyle::getMarginsOfAccessNode(
node.isExpanded(), node.subNodes.size(), node.invisibleSubNodeCount);
margins = GraphViewStyle::getMarginsOfAccessNode();
}
else if (node.isExpandToggleNode())
{
margins = GraphViewStyle::getMarginsOfExpandToggleNode();
}
int y = 0;
@@ -411,12 +399,19 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
int width = margins.minWidth;
int height = 0;
if (node.data)
if (node.isGraphNode())
{
width = margins.charWidth * node.data->getName().size();
if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT) && node.subNodes.size())
{
addExpandToggleNode(node);
}
}
bool layoutHorizontal = true;
// Horizontal layouting is currently not used, but left in place for experimentation.
bool layoutHorizontal = false;
for (DummyNode& subNode : node.subNodes)
{
if (!subNode.visible)
@@ -426,15 +421,15 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
layoutNestingRecursive(subNode);
if (subNode.data || subNode.isExpanded() || subNode.invisibleSubNodeCount != subNode.subNodes.size())
if (subNode.isExpandToggleNode())
{
layoutHorizontal = false;
width += margins.spacingX + subNode.size.x;
}
}
for (DummyNode& subNode : node.subNodes)
{
if (!subNode.visible)
if (!subNode.visible || subNode.isExpandToggleNode())
{
continue;
}
@@ -476,13 +471,52 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
node.size.x = margins.left + width + margins.right;
node.size.y = margins.top + y + height + margins.bottom;
for (DummyNode& subNode : node.subNodes)
{
if (subNode.isExpandToggleNode())
{
subNode.position.x = margins.left + width - subNode.size.x;
subNode.position.y = 6;
}
}
}
void GraphController::addExpandToggleNode(DummyNode& node) const
{
DummyNode expandNode;
expandNode.visible = true;
expandNode.expanded = node.expanded;
expandNode.autoExpanded = node.autoExpanded;
for (size_t i = 0; i < node.subNodes.size(); i++)
{
DummyNode& subNode = node.subNodes[i];
if (subNode.isExpandToggleNode())
{
node.subNodes.erase(node.subNodes.begin() + i);
i--;
continue;
}
for (DummyNode& subSubNode : subNode.subNodes)
{
if (!subSubNode.visible)
{
expandNode.invisibleSubNodeCount++;
}
}
}
node.subNodes.push_back(expandNode);
}
DummyNode* GraphController::findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId)
{
for (DummyNode& node : nodes)
{
if (node.data && node.data->getId() == tokenId)
if (node.isGraphNode() && node.data->getId() == tokenId)
{
return &node;
}
@@ -505,7 +539,7 @@ DummyNode* GraphController::findDummyNodeAccessRecursive(
{
for (DummyNode& subNode : node->subNodes)
{
if (subNode.accessType == type)
if (subNode.isAccessNode() && subNode.accessType == type)
{
return &subNode;
}
@@ -12,6 +12,7 @@
#include "component/controller/Controller.h"
#include "component/controller/GraphLayouter.h"
#include "component/view/GraphView.h"
#include "data/graph/token_component/TokenComponentAccess.h"
struct DummyNode;
struct DummyEdge;
@@ -48,10 +49,11 @@ private:
void setActiveAndVisibility(const std::vector<Id>& activeTokenIds);
void setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds) const;
bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const;
void setNodeVisibilityRecursiveTopDown(DummyNode& node) const;
void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const;
void layoutNesting();
void layoutNestingRecursive(DummyNode& node) const;
void addExpandToggleNode(DummyNode& node) const;
DummyNode* findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId);
DummyNode* findDummyNodeAccessRecursive(std::vector<DummyNode>& nodes, Id parentId, TokenComponentAccess::AccessType type);
+37 -32
View File
@@ -102,7 +102,7 @@ size_t GraphViewStyle::getFontSizeOfAccessNode()
return 11;
}
size_t GraphViewStyle::getFontSizeOfNumber()
size_t GraphViewStyle::getFontSizeOfExpandToggleNode()
{
return 9;
}
@@ -117,7 +117,7 @@ std::string GraphViewStyle::getFontNameOfAccessNode()
return "Myriad Pro";
}
std::string GraphViewStyle::getFontNameOfNumber()
std::string GraphViewStyle::getFontNameOfExpandToggleNode()
{
return "Myriad Pro";
}
@@ -125,7 +125,8 @@ std::string GraphViewStyle::getFontNameOfNumber()
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType type, bool hasChildren)
{
NodeMargins margins;
margins.spacingX = margins.spacingY = 8;
margins.spacingX = 12;
margins.spacingY = 8;
switch (type)
{
@@ -145,14 +146,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
case Node::NODE_FILE:
if (hasChildren)
{
margins.left = margins.right = 15;
margins.top = 30;
margins.left = margins.right = 10;
margins.top = 33;
margins.bottom = 10;
}
else
{
margins.left = margins.right = 8;
margins.top = margins.bottom = 13;
margins.top = margins.bottom = 17;
}
break;
@@ -177,37 +178,26 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
return margins;
}
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(
bool expanded, size_t subNodeCount, size_t invisibleSubNodeCount
){
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode()
{
NodeMargins margins;
margins.spacingX = margins.spacingY = 8;
margins.left = margins.right = 10;
margins.top = 40;
margins.bottom = 10;
if (invisibleSubNodeCount == subNodeCount)
{
margins.minWidth = 20;
margins.bottom = 10;
}
else
{
margins.minWidth = 82;
margins.minWidth = 82;
if (expanded)
{
margins.bottom = 15;
}
else if (invisibleSubNodeCount)
{
margins.bottom = 23;
}
else
{
margins.bottom = 10;
}
}
return margins;
}
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfExpandToggleNode()
{
NodeMargins margins;
margins.left = margins.right = margins.top = margins.bottom = 11;
margins.minWidth = 0;
return margins;
}
@@ -279,14 +269,14 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
if (hasChildren)
{
style.cornerRadius = 20;
style.textOffset.x = 15;
style.textOffset.x = 10;
style.textOffset.y = 8;
}
else
{
style.cornerRadius = 10;
style.textOffset.x = 8;
style.textOffset.y = 4;
style.textOffset.y = 8;
}
break;
@@ -337,6 +327,21 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfAccessNode()
return style;
}
GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode()
{
NodeStyle style;
style.color = "#FFFFFF";
style.borderColor = "#00000000";
style.cornerRadius = 12;
style.fontName = getFontNameOfExpandToggleNode();
style.fontSize = getFontSizeOfExpandToggleNode();
return style;
}
GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused)
{
EdgeStyle style;
+5 -3
View File
@@ -81,17 +81,19 @@ public:
static size_t getFontSizeForNodeType(Node::NodeType type);
static size_t getFontSizeOfAccessNode();
static size_t getFontSizeOfNumber();
static size_t getFontSizeOfExpandToggleNode();
static std::string getFontNameForNodeType(Node::NodeType type);
static std::string getFontNameOfAccessNode();
static std::string getFontNameOfNumber();
static std::string getFontNameOfExpandToggleNode();
static NodeMargins getMarginsForNodeType(Node::NodeType type, bool hasChildren);
static NodeMargins getMarginsOfAccessNode(bool expanded, size_t subNodeCount, size_t invisibleSubNodeCount);
static NodeMargins getMarginsOfAccessNode();
static NodeMargins getMarginsOfExpandToggleNode();
static NodeStyle getStyleForNodeType(Node::NodeType type, bool isActive, bool isFocused, bool hasChildren);
static NodeStyle getStyleOfAccessNode();
static NodeStyle getStyleOfExpandToggleNode();
static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused);
@@ -50,45 +50,65 @@ struct DummyNode
{
public:
DummyNode()
: data(nullptr)
, accessType(TokenComponentAccess::ACCESS_NONE)
: visible(false)
, childVisible(false)
, topLevelAncestorId(0)
, tokenId(0)
, data(nullptr)
, active(false)
, connected(false)
, aggregated(false)
, expanded(false)
, autoExpanded(false)
, accessType(TokenComponentAccess::ACCESS_NONE)
, invisibleSubNodeCount(0)
, visible(false)
, topLevelAncestorId(0)
, tokenId(0)
{
}
bool isGraphNode() const
{
return data != nullptr;
}
bool isAccessNode() const
{
return accessType != TokenComponentAccess::ACCESS_NONE;
}
bool isExpandToggleNode() const
{
return !data && !isAccessNode();
}
bool isExpanded() const
{
return expanded || autoExpanded;
}
const Node* data;
TokenComponentAccess::AccessType accessType;
Vec2i position;
Vec2i size;
bool active;
bool connected;
bool aggregated;
bool expanded;
bool autoExpanded;
size_t invisibleSubNodeCount;
bool visible;
bool childVisible;
Id topLevelAncestorId;
Id tokenId;
std::vector<DummyNode> subNodes;
// GraphNode
const Node* data;
bool active;
bool connected;
bool aggregated;
bool expanded;
bool autoExpanded;
// AccessNode
TokenComponentAccess::AccessType accessType;
// ExpandToggleNode
size_t invisibleSubNodeCount;
};
#endif // GRAPH_NODE_H