Skip to content

Commit 1f935de

Browse files
authored
Merge pull request #234 from tne-lab/clean-refresh-editors
Clean up EditorViewport::refreshEditors
2 parents 1667fc4 + 4df80e4 commit 1f935de

1 file changed

Lines changed: 20 additions & 61 deletions

File tree

Source/UI/EditorViewport.cpp

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,10 @@ void EditorViewport::refreshEditors()
383383
{
384384

385385
int lastBound = borderSize+tabSize;
386-
int totalWidth = 0;
387386

388387
//std::cout << insertionPoint << std::endl;
389388

390-
bool tooLong;
389+
bool pastRightEdge = false;
391390

392391
for (int n = 0; n < signalChainArray.size(); n++)
393392
{
@@ -397,96 +396,56 @@ void EditorViewport::refreshEditors()
397396
}
398397
}
399398

400-
for (int n = 0; n < editorArray.size(); n++)
399+
int rightEdge = getWidth() - tabSize;
400+
int numEditors = editorArray.size();
401+
402+
for (int n = 0; n < numEditors; n++)
401403
{
402404

403405
// std::cout << "Refreshing editor number" << n << std::endl;
404406

405-
int componentWidth = editorArray[n]->desiredWidth;
407+
GenericEditor* editor = editorArray[n];
408+
int componentWidth = editor->desiredWidth;
409+
410+
pastRightEdge = pastRightEdge || lastBound + componentWidth >= rightEdge;
406411

407-
if (lastBound + componentWidth < getWidth() - tabSize && n >= leftmostEditor)
412+
if (!pastRightEdge && n >= leftmostEditor)
408413
{
409414

410-
if (n == 0)
415+
if (n == 0 && !editor->getProcessor()->isSource())
411416
{
412-
if (!editorArray[n]->getEnabledState())
413-
{
414-
GenericProcessor* p = (GenericProcessor*) editorArray[n]->getProcessor();
415-
if (!p->isSource())
416-
lastBound += borderSize*10;
417-
// signalChainNeedsSource = true;
418-
}
419-
else
420-
{
421-
// signalChainNeedsSource = false;
422-
}
417+
// leave room to drop a source node
418+
lastBound += borderSize * 10;
423419
}
424420

425421
if (somethingIsBeingDraggedOver && n == insertionPoint)
426422
{
427-
if (indexOfMovingComponent > -1)
428-
{
429-
if (n != indexOfMovingComponent && n != indexOfMovingComponent+1)
430-
{
431-
if (n == 0)
432-
lastBound += borderSize*3;
433-
else
434-
lastBound += borderSize*2;
435-
}
436-
}
437-
else
423+
if (indexOfMovingComponent == -1 // adding new processor
424+
|| (n != indexOfMovingComponent && n != indexOfMovingComponent + 1))
438425
{
439426
if (n == 0)
440427
lastBound += borderSize*3;
441428
else
442429
lastBound += borderSize*2;
443430
}
444-
445431
}
446432

447-
editorArray[n]->setVisible(true);
433+
editor->setVisible(true);
448434
// std::cout << "setting visible." << std::endl;
449-
editorArray[n]->setBounds(lastBound, borderSize, componentWidth, getHeight()-borderSize*2);
435+
editor->setBounds(lastBound, borderSize, componentWidth, getHeight()-borderSize*2);
450436
lastBound += (componentWidth + borderSize);
451-
452-
tooLong = false;
453-
454-
totalWidth = lastBound;
455-
456437
}
457438
else
458439
{
459-
editorArray[n]->setVisible(false);
460-
461-
totalWidth += componentWidth + borderSize;
462-
440+
editor->setVisible(false);
463441
// std::cout << "setting invisible." << std::endl;
464-
465-
if (lastBound + componentWidth > getWidth()-tabSize)
466-
tooLong = true;
467-
468442
}
469443
}
470444

471-
// BUG: variable is used without being initialized
472-
if (tooLong && editorArray.size() > 0)
473-
rightButton->setActive(true);
474-
else
475-
rightButton->setActive(false);
476-
477-
if (leftmostEditor == 0 || editorArray.size() == 0)
478-
leftButton->setActive(false);
479-
else
480-
leftButton->setActive(true);
445+
rightButton->setActive(pastRightEdge);
446+
leftButton->setActive(leftmostEditor != 0 && editorArray.size() != 0);
481447

482448
// std::cout << totalWidth << " " << getWidth() - tabSize << std::endl;
483-
484-
// if (totalWidth < getWidth()-tabSize && leftButton->isActive)
485-
// {
486-
// leftmostEditor -= 1;
487-
// refreshEditors();
488-
// }
489-
490449
}
491450

492451
void EditorViewport::moveSelection(const KeyPress& key)

0 commit comments

Comments
 (0)