How do you make a floating text that follows the mouse pointer on GUI?

Hi there,

How do you make a floating text that follows the mouse pointer in GUI?
I have achieved this by combining various mouse actions as follows (the application of the value on the y-axis is deliberately removed):
https://sccode.org/1-5hC
Could you share your ways?

(
    var win = Window()
    .front;
    var v = win.view;
    var text = StaticText(v, Rect(-100, -100, 100, 20))
    .string_("Hello World!");
    v.acceptsMouseOver_(true)
    .mouseOverAction_{|self, x, y|
        text.bounds_(Rect(x, y, 100, 20));
    };
)
1 Like

@mjsyts
Thank you very much!

To compare with what I had done, here is the summary of my version regarding mouseOverAction_:

(
var w, text;
w = Window();
w.front.acceptsMouseOver_(true);
text = StaticText(w, Rect(-100, -100, 100, 20))
.string_("Hello World!");
w.view.mouseOverAction_{ |self, x, y|
	text.bounds_(Rect(x, y, 100, 20))
}
)

acceptsMouseOver_ is accepted by both of Window and View, while mouseOverAction_ is only accepted by View.
Except for the placement of acceptsMouseOver_, we have the same idea! Glad to know and relieved!

1 Like