Since FMX doesn't have a hint for mouse movements I've tried rigging up a custom hint for an image component that is created at run time. The OnMouseMove method pointer was assigned, but for some reason there is no popup. I set a TLabel as the DetailControl and the Placement target as the Toolbar (which is at the top of the form) to test. I wrote a custom hint collection that is a component used to collect strings and coordinates with relevant data.
This is the code:
procedure TFormTimeGraph.GraphImgMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
// search the hint collection for coordinates to see if hint should be shown
for I := 0 to Hints.HintSet.Count - 1 do
if (X >= Hints.HintSet.HintItem.LowX) and (X <= Hints.HintSet.HintItem.HighX) and
(Y >= Hints.HintSet.HintItem.LowY) and (Y <= Hints.HintSet.HintItem.HighY) then
Hint := Hints.HintSet.Hint;
PopHint.Position.X := X;
PopHint.Position.Y := Y;
PopHint.HeaderText := 'Location:';
HintLabel.Text := Hint;
Break; // allows hint to be shown
else // no hint found so empty previous hint strings
//Hint := '';
The redundant "Hint" field is used to show the hint in the statusbar and that works as expected. Why doesn't the Popup show at all? I tried commenting out the X,Y of PopHint.Position to see if that would make a difference, but it doesn't.
Well I solved the above problem by using BringToFront, and I set the PlacementTarget at runtime...
PopHint.PlacementTarget := GraphImg;
So that it would show up where the mouse was in the TImage. However I had to use Placement := MouseCenter otherwise the control would flicker constantly. It seems that the OnMouseMove is called constantly causing the flickering unless the mouse was directly over the Popup control which shut down the OnMouseMove of the TImage until the cursor was away from the Popup control. Having it off to the side where the Arrow is doesn't work, so I set ArrowHeight := 0;
Any thoughts on a way to control the height of the Popup automatically? Of course I could find the number of lines in the text, but am wondering if there is an easier way.
There's another problem with Placement = MouseCenter; the user can't click on the Image to call up other data because the Popup is in the way, so I can't really use this option. I'd prefer not to use a right click and OnMouseDown to do this as this wouldn't be a user friendly as the VCL version.
Please understand that the popup isn't designed to behave as a hint. The Placement MouseCenter behaves correctly, The popup is show with it's center as the mouse location. Afterwards, you cannot interact with the control that lies behind it, since the popup itself is active at that moment.
Toggling the visibility of the popup in the mouse move is most likely the cause for flickering. A hint stays visible during the interval and hides automatically. They only way to support this is to create a new component that implement this kind of behavior.
I solved the problem by only calling Show if the Popup wasn't already showing by using this code in the OnMouseMove event:
if not FPopupShowing then
FPopupShowing := True;
FPopupShowing is a local variable of the form. It is set to false when X, Y are no longer within the ranged of any hint collection objects. This disables the flickering.