Multiple rows of buttons but I can only click the buttons in the last row?

gui

#1

Update with some info:
I’ve now logged the mouse position when entering any button. The mouseEnter event is only triggered when my mouse enters a button on the bottom row. How can there be buttons which I can see but can not interact with?

I have a window with 2 rows of buttons, sort of like a step sequencer. Each button should be clickable and in the past they were. I’m now in the process of refactoring much of my code to make ownership more explicit. Most things are back to working however, only one row/track of buttons can be toggled. No matter how many rows (I’ve tried 1-5), it seems that only the last row’s buttons can be toggled. If I set the onClick method to print some debug info, it only prints when clicking the last row’s buttons so I’m fairly certain the problem goes slightly further than a simple business and front end logic mismatch. I’ll share some relevant code snippets here and link to the github repo in case anyone wants additional code.
My github: https://github.com/BennetLeff/Ample/tree/master/Source

SequencerTrack::SequencerTrack()
{
auto count = 0;
for (auto& button : sequencer_buttons_)
{
	button = std::make_unique<SequencerButton>();

	/*
	 *  When a button is clicked it should toggle its on/off state and change color.
	 */
	button->onClick = [&button] {
		button->is_on_ = !button->is_on_;
		button->toggle_color();
	};

	addAndMakeVisible(button.get());
	count += 1;
}
}


void SequencerButton::toggle_color()
{
MessageManagerLock mm_lock;
if (is_on_)
	setColour(TextButton::buttonColourId, on_colour_);
else
	setColour(TextButton::buttonColourId, off_colour_);
}

#include <algorithm>
#include <memory>
#include <thread>

#include "JuceHeader.h"
#include "Sequencer.h"
#include "SequencerTrack.h"

Sequencer::Sequencer(const size_t number_of_steps, const double tempo)
	: tempo_(tempo), step_index_(0),
	sleep_amount_(tempo_ > 0 ? 60.0 / tempo_ : 0),
	Thread("Sequencer Thread")
{
    const MessageManagerLock mm_lock_(this);

    auto count = 0;
    for (auto& track : sequencer_tracks_)
    {
        track = std::make_unique<SequencerTrack>();
        addAndMakeVisible(track.get());
        track->setBounds(0, count * 10, getParentWidth(), getParentHeight());
        count += 1;
    }

	startThread();
}

Sequencer::~Sequencer()
{
	stopThread(500);
}

uint32_t Sequencer::current_step()
{
    return step_index_;
}

void Sequencer::step()
{
	step_index_ = (step_index_ + 1) % NUM_SEQUENCER_STEPS;
}

void Sequencer::stop()
{
	stopThread(500);
}

void Sequencer::resized()
{
	auto count = 0;
	for (auto& track : sequencer_tracks_)
	{
		track->position_triggers(count * 60);
		count += 1;
	}
}

void Sequencer::run()
{
	while (!threadShouldExit())
	{
		play();
		step();
		sleep(static_cast<int>(sleep_amount_ * 1000));
	}
}

void Sequencer::play()
{	
	/*
	 * Send message that sequencer step is updated. This should update Listeners including
	 *  - Each associated SequencerTrack: to update the step colours
	 */
	for (auto& seq_track : sequencer_tracks_)
    {
	    seq_track->update(current_step());
    }

}