mouseOverAction and UserView

mouseOverAction does not seem to fire for UserViews. Is that by design or a bug?

For example:

(
var win = View()
.layout_(HLayout().spacing_(1).margins_(1))
.minWidth_(300)
.minHeight_(200);

var w1 = UserView()
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_({arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
})
.mouseOverAction_({
“w1”.postln;
// this never posts
});

var w2 = UserView()
.mouseUpAction_({
“w2”.postln;
})
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_({arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
});

win.layout.add(w1);
win.layout.add(w2);

win.front;
)

To answer my own question…

From the documentation for mouseOverAction:
“The object is evaluated only when Window: -acceptsMouseOver of the containing Window (or -acceptsMouseOver of the top View) is true.”

I guess this is true for all views not just UserViews.

The mouseOverAction must be allowed in the View instance.
Please refer to http://doc.sccode.org/Classes/View.html
and find .acceptsMouseOver

(
var win = View()
.acceptsMouseOver_(true)
.layout_(HLayout().spacing_(1).margins_(1))
.minWidth_(300)
.minHeight_(200);

var w1 = UserView()
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_{ arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
}
.mouseOverAction_{ arg view, x, y;
	"w1".postln;
};

var w2 = UserView()
.mouseUpAction_{ arg view, x, y, modifiers, buttonNumber;
	"w2".postln;
}
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_({arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
});

win.layout.add(w1);
win.layout.add(w2);

win.front;
)

You may need the position of mouse pointer and others as follows:

(
var win = View()
.acceptsMouseOver_(true)
.layout_(HLayout().spacing_(1).margins_(1))
.minWidth_(300)
.minHeight_(200);

var w1 = UserView()
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_{ arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
}
.mouseOverAction_{ arg view, x, y;
	[view, "w1", x, y].postln;
};

var w2 = UserView()
.mouseUpAction_{ arg view, x, y, modifiers, buttonNumber;
	[view, "w2", x, y, modifiers, buttonNumber].postln;
}
.maxWidth_(100)
.maxHeight_(100)
.drawFunc_({arg view;
Pen.fillRect(Rect(0, 0, 100, 100));
});

win.layout.add(w1);
win.layout.add(w2);

win.front;
)

One more thing:
the quotation marks in your code are not the quotation marks used in sclang.

“w2”.postln; // this is your code, and this is not correctly accepted by sclang.
"w2".postln; // this is accepted correctly by sclang.
1 Like

Thanks. I did find that documentation. I really wasn’t expecting something like that to be the case. I think the quotes were formatted by this forum software somehow since I just cut and pasted from the SC IDE.

Let’s see if formatting it as preformatted text resolves the problem:

this is preformatted text "w2"

1 Like

Thank you!
a blank line between the two text types is required!