Home » U++ Library support » U++ Core » How do I implement mouse hover in Ctrl based class (How do I implement mouse hover in Ctrl based class)
Re: How do I implement mouse hover in Ctrl based class [message #57374 is a reply to message #57373] |
Fri, 23 July 2021 19:19 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
Hello awksed,
The example below simulates a similar situation in a crude way.What you need to do is set the tip when a target mouse position/area is hovered.
Tip can do this for you. But if you need more control over the popup window, you can also use a Popup window (but it can complicate things...)
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct RectArea : Moveable<RectArea> {
Rect r;
String text;
};
struct MyApp : TopWindow {
Vector<RectArea> ra;
MyApp()
{
Sizeable().Zoomable().CenterScreen().SetRect(0,0, 1024, 800);
for(int i = 0; i < 50; i++) {
RectArea& r = ra.Add();
r.r = RectC(20 * i, 20 * i, 20, 20);
r.text << "\1[* Index: ]" << i << " &[* Random number: ]" << Random();
}
}
void Paint(Draw& w) override
{
w.DrawRect(GetSize(), Black());
for(const RectArea& r : ra)
w.DrawRect(r.r, Red());
}
void MouseMove(Point pt, dword keyflags) override
{
// Dont forget to call the parent ctrl's MouseMove, if it is utilized!
if(HasFocus() && ra.GetCount()) {
for(const RectArea& r : ra)
if(r.r.Contains(pt)) {
Tip(r.text);
return;
}
Tip(nullptr);
}
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
Now, this example is using rectangles and precalculation of areas. But the idea is the same: Do the checking in MouseMove and set or reset the Tip(), depending on the conditions, and don't forget to call the parent ctrl's MouseMove.
(In principle, this is how I display the hyperlink URLs in tips, in our TerminalCtrl)
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 23 July 2021 19:32] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue May 14 06:32:00 CEST 2024
Total time taken to generate the page: 0.02420 seconds
|