Could isMouseOver() be fixed or do I just need to keep working around?

I’m sure this is a common problem:

  • Component is painted differently according to isMouseOver()
  • Component uses setRepaintsOnMouseActivity(true) to make sure it updates on mouseEnter and mouseExit
  • Component shows a menu on mouseDown
  • Component retains the “over” paint state after clicking on a menu item or clicking on another part of the UI, will not repaint until mouseEnter/mouseExit occurs again

I’m always having to implement something like:

void MyComp::paint(juce::Graphics& g)
{
  g.fillAll(mouseOver ? overColour : normalColour);
}

void MyComp::setMouseOver(bool shouldBeOver)
{
  mouseOver = shouldBeOver;
  repaint();
}

void MyComp::mouseEnter(const juce::MouseEvent& ev)
{
  setMouseOver(true);
}

void MyComp::mouseExit(const juce::MouseEvent& ev)
{
  setMouseOver(false);
}

void MyComp::mouseDown(const juce::MouseEvent& ev)
{
  // show menu code
  // in the menu callback call setMouseOver(false);
}

Could this be “fixed” in JUCE, or is this just something that is so obvious a problem that it must have been thought about before but is unable to be solved?

Even just having a way to control the mouse over state manually would be useful, but afaict that doesn’t appear to be possible.

1 Like

MouseEnter/mouseExit calls should now be properly balanced.

Please try out this change and let us know if you encounter any new problems.

1 Like