How to implement onDoubleClick() ?

Hello!

My first swing at developing onDoubleClick isn’t working out. Here’s what I have so far:

struct TrackLabelDisplay : TransparentWidget
{
  Scalar110 *module;
  unsigned int track_number = 0;

  TrackLabelDisplay(unsigned int track_number)
  {
    box.size = Vec(100, 25);
  }

  void onDoubleClick(const event::DoubleClick &e) override
  {
    DEBUG("Double Clicky");
  }

  ... 

Double clicking isn’t outputting the debugging message. Later in the code, I’m drawing a pink box where the component is located so I can clearly see where it is:

image

nvgBeginPath(vg);
nvgRect(vg, 0, 0, box.size.x, box.size.y);
nvgFillColor(vg, nvgRGBA(120, 20, 20, 100));
nvgFill(vg);

So I’m pretty certain that I’m clicking within the bounding box.

I must be overlooking something! Any ideas?

The documentation says:

/** Occurs when the left mouse button is pressed a second time on the same Widget within a time duration.
Must consume the Button event (on left button press) to receive this event.
*/
struct DoubleClickEvent : BaseEvent {};
virtual void onDoubleClick(const DoubleClickEvent& e) {}

So I think you also a “e.consume(this);” inside “onButton” like this (from ParamWidget)

void ParamWidget::onButton(const ButtonEvent& e) {
	OpaqueWidget::onButton(e);

	// Touch parameter
	if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT && (e.mods & RACK_MOD_MASK) == 0) {
		if (module) {
			APP->scene->rack->touchedParam = this;
		}
		e.consume(this);
	}

	// Right click to open context menu
	if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT && (e.mods & RACK_MOD_MASK) == 0) {
		destroyTooltip();
		createContextMenu();
		e.consume(this);
	}
}

Ah, thanks a ton Andrew!! Here’s what I had to do:

  void onDoubleClick(const event::DoubleClick &e) override
  {
    DEBUG("Double Clicky");
  }

  void onButton(const event::Button &e) override
  {
    TransparentWidget::onButton(e);
    e.consume(this);
  }
1 Like