Hello,
I’m currently trying to delete a group of components set at specific positions in a parent component, then re draw a group of new components of the same type at different positions.
My approach is to first remove all the child components by iterating through the list and calling removeChildComponent() on each component.
Then i call clear on the list and while debugging i see that the list size is now 0.
m_gui_notes.clear()
I expected this to remove all existing components from the view but it doesn’t, so ive also tried the calls:
removeAllChildren()
deleteAllChildren()
On the first time entering the function initialiseNotes() it draws the notes in the correct position (GuiNotes) which for now are simply just juce::components with a set colour.
Then on the second time, there is now something to delete in m_gui_notes and it does the process i described above.
Then i would expect all the original GuiNote components to be removed from the UI. But instead they’re not and it draws the new lot of components on top of the previous components.
std::list<GuiNote*> m_gui_notes;
void
PianoRoll::initialiseNotes()
{
for (auto& gui_note: m_gui_notes)
{
removeChildComponent(gui_note);
delete gui_note;
}
removeAllChildren();
deleteAllChildren();
m_gui_notes.clear();
std::list<GuiNote*>::iterator gui_note_iterator = m_gui_notes.begin();
for (std::size_t index = 0; index < m_current_sequence.size(); index++)
{
m_gui_notes.push_back(new GuiNote);
gui_note_iterator++;
int x_pos = static_cast<int>(m_current_sequence[index].note_on)/4;
int width = (static_cast<int>(m_current_sequence[index].note_off)/4) - x_pos;
int y_pos = (grid_line_height*number_of_midi_note_values) -
(grid_line_height * m_current_sequence[index].note_value);
(*gui_note_iterator)->setBounds(x_pos + keyboard_width, y_pos ,width, grid_line_height);
addAndMakeVisible((*gui_note_iterator));
}
}
I feel like i’m missing something obvious or don’t quite understand how the lifecycle of components work in JUCE.
Any help would be greatly appreciated!