Skip to content

Commit 5396b6b

Browse files
committed
Refactor GraphViewer node width handling
1 parent 46e9bd5 commit 5396b6b

File tree

2 files changed

+60
-43
lines changed

2 files changed

+60
-43
lines changed

Source/UI/GraphViewer.cpp

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,19 @@ void GraphViewer::updateNodes (GenericProcessor* processor_, Array<GenericProces
140140

141141
for (auto processor : rootProcessors)
142142
{
143-
int horzShift = -1;
143+
int horzShift = X_BORDER_SIZE; // Start at left border
144144
level = jmax (rootProcessors.indexOf (processor), level + 1);
145145

146146
while ((processor != nullptr) || (splitters.size() > 0))
147147
{
148148
if (processor != nullptr)
149149
{
150-
horzShift++;
150+
// Calculate horzShift from the right edge of the previous node at this level
151+
if (nodesByLevel[level].size() > 0)
152+
{
153+
GraphNode* prevNode = nodesByLevel[level].getLast();
154+
horzShift = prevNode->getRight() + X_BORDER_SIZE;
155+
}
151156

152157
if (processor->isMerger())
153158
{
@@ -158,17 +163,17 @@ void GraphViewer::updateNodes (GenericProcessor* processor_, Array<GenericProces
158163
if (nodeA != nullptr)
159164
{
160165
level = nodeA->getLevel();
161-
int horzShiftA = nodeA->getHorzShift();
162-
int horzShiftB = 0;
166+
int nodeRightA = nodeA->getHorzShift() + nodeA->getWidth();
167+
int nodeRightB = 0;
163168

164169
if (merger->getSourceNode (1) != nullptr)
165170
{
166171
GraphNode* nodeB = getNodeForEditor (merger->getSourceNode (1)->getEditor());
167172
if (nodeB != nullptr)
168-
horzShiftB = nodeB->getHorzShift();
173+
nodeRightB = nodeB->getHorzShift() + nodeB->getWidth();
169174
}
170175

171-
horzShift = jmax (horzShiftA, horzShiftB) + 1;
176+
horzShift = jmax (nodeRightA, nodeRightB) + X_BORDER_SIZE;
172177
}
173178
}
174179
else if (merger->getSourceNode (0) == nullptr && merger->getSourceNode (1) != nullptr)
@@ -184,10 +189,11 @@ void GraphViewer::updateNodes (GenericProcessor* processor_, Array<GenericProces
184189
{
185190
addNode (processor->getEditor(), level, horzShift);
186191
}
187-
else // Node exists, updated necessary info
192+
else
188193
{
189194
GraphNode* node = getNodeForEditor (processor->getEditor());
190195
node->stillNeeded = true;
196+
node->updateWidth();
191197
node->setLevel (level);
192198
node->setHorzShift (horzShift);
193199
node->updateStreamInfo();
@@ -213,7 +219,7 @@ void GraphViewer::updateNodes (GenericProcessor* processor_, Array<GenericProces
213219
processor = splitter->getDestNode (1); // then come back to chain 1
214220

215221
GraphNode* gn = getNodeForEditor (splitter->getEditor());
216-
horzShift = gn->getHorzShift();
222+
horzShift = gn->getRight() + X_BORDER_SIZE;
217223

218224
auto destA = splitter->getDestNode (0);
219225
bool hasDownstreamSplitter = false;
@@ -260,16 +266,8 @@ void GraphViewer::addNode (GenericEditor* editor, int level, int offset)
260266
addAndMakeVisible (gn, 0);
261267
availableNodes.add (gn);
262268

263-
int thisNodeWidth = NODE_WIDTH;
264-
265-
if (gn->getName().length() > 18)
266-
{
267-
thisNodeWidth += (gn->getName().length() - 18) * 10;
268-
}
269-
270269
gn->setLevel (level);
271270
gn->setHorzShift (offset);
272-
gn->setWidth (thisNodeWidth);
273271
gn->updateBoundaries();
274272
}
275273

@@ -549,7 +547,7 @@ DataStreamInfo::DataStreamInfo (DataStream* stream_, GenericEditor* editor, Grap
549547

550548
addAndMakeVisible (parameterPanel.get());
551549
parameterPanel->addMouseListener (this, true);
552-
parameterPanel->setBounds (0, 60, NODE_WIDTH, 20);
550+
parameterPanel->setBounds (0, 60, node->getWidth(), 20);
553551

554552
heightInPixels += 20;
555553
}
@@ -603,15 +601,15 @@ void DataStreamInfo::buttonClicked (Button* button)
603601
heightInPixels = editorHeight + 80;
604602
node->updateBoundaries();
605603
node->setDataStreamPanelSize (this, heightInPixels);
606-
parameterPanel->setSize (NODE_WIDTH, editorHeight + 20);
604+
parameterPanel->setSize (node->getWidth(), editorHeight + 20);
607605
parameterPanel->expandPanelFully (streamParameterEditorComponent.get(), false);
608606
}
609607
else
610608
{
611609
heightInPixels = 80;
612610
node->updateBoundaries();
613611
node->setDataStreamPanelSize (this, heightInPixels);
614-
parameterPanel->setSize (NODE_WIDTH, 20);
612+
parameterPanel->setSize (node->getWidth(), 20);
615613
parameterPanel->setPanelSize (streamParameterEditorComponent.get(), 0, false);
616614
}
617615

@@ -636,21 +634,33 @@ void DataStreamInfo::restorePanels()
636634
{
637635
headerButton->setToggleState (node->streamInfoVisible[stream->getKey()], dontSendNotification);
638636

639-
if (parameterButton != nullptr && node->streamParamsVisible[stream->getKey()])
640-
{
641-
parameterButton->setToggleState (node->streamParamsVisible[stream->getKey()], sendNotification);
642-
}
643-
else
637+
if (parameterButton != nullptr)
644638
{
645-
node->updateBoundaries();
639+
bool paramsVisible = node->streamParamsVisible[stream->getKey()];
640+
parameterButton->setToggleState (paramsVisible, dontSendNotification);
646641

647-
if (node->streamInfoVisible[stream->getKey()])
648-
node->setDataStreamPanelSize (this, heightInPixels);
642+
if (paramsVisible)
643+
{
644+
heightInPixels = editorHeight + 80;
645+
parameterPanel->setSize (node->getWidth(), editorHeight + 20);
646+
parameterPanel->expandPanelFully (streamParameterEditorComponent.get(), false);
647+
}
649648
else
650-
node->setDataStreamPanelSize (this, 0);
651-
652-
node->updateGraphView();
649+
{
650+
heightInPixels = 80;
651+
parameterPanel->setSize (node->getWidth(), 20);
652+
parameterPanel->setPanelSize (streamParameterEditorComponent.get(), 0, false);
653+
}
653654
}
655+
656+
node->updateBoundaries();
657+
658+
if (headerButton->getToggleState())
659+
node->setDataStreamPanelSize (this, heightInPixels);
660+
else
661+
node->setDataStreamPanelSize (this, 0);
662+
663+
node->updateGraphView();
654664
}
655665

656666
ProcessorParameterComponent::ProcessorParameterComponent (GenericProcessor* p)
@@ -763,6 +773,13 @@ GraphNode::GraphNode (GenericEditor* ed, GraphViewer* g)
763773
vertShift = 0;
764774
processorInfoVisible = false;
765775

776+
updateWidth();
777+
778+
setBounds (getHorzShift(),
779+
Y_BORDER_SIZE + getLevel() * NODE_HEIGHT,
780+
nodeWidth,
781+
40);
782+
766783
infoPanel = std::make_unique<ConcertinaPanel>();
767784

768785
if (! processor->isMerger() && ! processor->isSplitter() && ! processor->isEmpty())
@@ -801,11 +818,6 @@ GraphNode::GraphNode (GenericEditor* ed, GraphViewer* g)
801818
infoPanel->addMouseListener (this, true);
802819
}
803820

804-
setBounds (X_BORDER_SIZE + getHorzShift() * NODE_WIDTH,
805-
Y_BORDER_SIZE + getLevel() * NODE_HEIGHT,
806-
nodeWidth,
807-
40);
808-
809821
previousHeight = 0;
810822
verticalOffset = 0;
811823

@@ -842,9 +854,14 @@ void GraphNode::setHorzShift (int shift)
842854
horzShift = shift;
843855
}
844856

845-
void GraphNode::setWidth (int width)
857+
void GraphNode::updateWidth()
846858
{
847-
nodeWidth = width;
859+
nodeWidth = NODE_WIDTH;
860+
861+
if (getName().length() > 18)
862+
{
863+
nodeWidth += (getName().length() - 18) * 10;
864+
}
848865
}
849866

850867
void GraphNode::mouseEnter (const MouseEvent& m)
@@ -1026,16 +1043,16 @@ void GraphNode::updateBoundaries()
10261043
panelHeight += 20;
10271044
}
10281045

1029-
infoPanel->setBounds (0, 0, NODE_WIDTH, panelHeight);
1046+
infoPanel->setBounds (0, 0, nodeWidth, panelHeight);
10301047

10311048
int nodeY = gv->getLevelStartY (getLevel());
10321049
if (nodeY == 0)
1033-
setBounds (X_BORDER_SIZE + getHorzShift() * (NODE_WIDTH + X_BORDER_SIZE),
1050+
setBounds (getHorzShift(), // Use pixel x position directly
10341051
Y_BORDER_SIZE + getLevel() * (NODE_HEIGHT + 35),
10351052
nodeWidth,
10361053
panelHeight);
10371054
else
1038-
setBounds (X_BORDER_SIZE + getHorzShift() * (NODE_WIDTH + X_BORDER_SIZE),
1055+
setBounds (getHorzShift(),
10391056
nodeY,
10401057
nodeWidth,
10411058
panelHeight);
@@ -1212,9 +1229,9 @@ void GraphNode::paint (Graphics& g)
12121229
if (processorInfoVisible)
12131230
g.fillRect (0, 19, getWidth(), 1);
12141231

1215-
g.setColour (findColour (ThemeColours::defaultText));
1232+
g.setColour (findColour (ThemeColours::defaultText));
12161233
g.drawText (String (nodeId), 1, 1, 23, 20, Justification::centred, true);
1217-
g.setColour (Colours::white);
1234+
g.setColour (Colours::white);
12181235
g.setFont (FontOptions ("CP Mono", "Plain", 15.0f));
12191236
g.drawText (getName().toUpperCase(), 30, 1, getWidth() - 30, 20, Justification::left, true);
12201237
}

Source/UI/GraphViewer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class GraphNode : public Component,
227227
void setLevel (int newLevel);
228228

229229
/** Sets the width of node in graph display */
230-
void setWidth (int newWidth);
230+
void updateWidth();
231231

232232
/** Sets the horizontal shift (x-position of node in graph display) */
233233
void setHorzShift (int newHorizontalShift);

0 commit comments

Comments
 (0)