Browse Source

Tooltip: Show manually shown tips until a dismissal mouse event occurs

v6.1.6
ed 4 years ago
parent
commit
b4bc2c8710
2 changed files with 26 additions and 34 deletions
  1. +19
    -33
      modules/juce_gui_basics/windows/juce_TooltipWindow.cpp
  2. +7
    -1
      modules/juce_gui_basics/windows/juce_TooltipWindow.h

+ 19
- 33
modules/juce_gui_basics/windows/juce_TooltipWindow.cpp View File

@@ -164,7 +164,7 @@ String TooltipWindow::getTipFor (Component& c)
void TooltipWindow::hideTip()
{
if (! reentrant)
if (isVisible() && ! reentrant)
{
tipShowing = {};
manuallyShownTip = {};
@@ -173,6 +173,8 @@ void TooltipWindow::hideTip()
removeFromDesktop();
setVisible (false);
lastHideTime = Time::getApproximateMillisecondCounter();
#if JUCE_DEBUG
activeTooltipWindows.removeAllInstancesOf (this);
#endif
@@ -194,25 +196,20 @@ std::unique_ptr<AccessibilityHandler> TooltipWindow::createAccessibilityHandler(
void TooltipWindow::timerCallback()
{
auto& desktop = Desktop::getInstance();
auto mouseSource = desktop.getMainMouseSource();
auto now = Time::getApproximateMillisecondCounter();
const auto mouseSource = Desktop::getInstance().getMainMouseSource();
auto* newComp = mouseSource.isTouch() ? nullptr : mouseSource.getComponentUnderMouse();
if (newComp == nullptr || getParentComponent() == nullptr || newComp->getPeer() == getPeer())
if (manuallyShownTip.isNotEmpty())
{
const auto componentChanged = (newComp != lastComponentUnderMouse);
if (dismissalMouseEventOccured || newComp == nullptr)
hideTip();
const auto newTip = [this, &newComp, componentChanged]
{
if (dynamic_cast<TooltipClient*> (newComp) != nullptr)
return getTipFor (*newComp);
return componentChanged ? String() : manuallyShownTip;
}();
return;
}
const auto tipChanged = (newTip != lastTipUnderMouse || componentChanged);
if (newComp == nullptr || getParentComponent() == nullptr || newComp->getPeer() == getPeer())
{
const auto newTip = newComp != nullptr ? getTipFor (*newComp) : String();
lastComponentUnderMouse = newComp;
lastTipUnderMouse = newTip;
@@ -221,19 +218,16 @@ void TooltipWindow::timerCallback()
const auto mouseMovedQuickly = (mousePos.getDistanceFrom (lastMousePos) > 12);
lastMousePos = mousePos;
const auto tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
const auto now = Time::getApproximateMillisecondCounter();
if (tipChanged || dismissalMouseEventOccured || mouseMovedQuickly)
lastCompChangeTime = now;
auto showTip = [this, &mouseSource, &mousePos, &newTip]
const auto showTip = [this, &mouseSource, &mousePos, &newTip]
{
if (mouseSource.getLastMouseDownPosition() == lastMousePos)
return;
const auto isShowingManualTip = (manuallyShownTip.isNotEmpty() && manuallyShownTip == newTip);
displayTipInternal (mousePos.roundToInt(),
newTip,
isShowingManualTip ? ShownManually::yes : ShownManually::no);
if (mouseSource.getLastMouseDownPosition() != lastMousePos)
displayTipInternal (mousePos.roundToInt(), newTip, ShownManually::no);
};
if (isVisible() || now < lastHideTime + 500)
@@ -241,17 +235,9 @@ void TooltipWindow::timerCallback()
// if a tip is currently visible (or has just disappeared), update to a new one
// immediately if needed..
if (newComp == nullptr || dismissalMouseEventOccured || newTip.isEmpty())
{
if (isVisible())
{
lastHideTime = now;
hideTip();
}
}
hideTip();
else if (tipChanged)
{
showTip();
}
}
else
{


+ 7
- 1
modules/juce_gui_basics/windows/juce_TooltipWindow.h View File

@@ -84,7 +84,13 @@ public:
*/
void setMillisecondsBeforeTipAppears (int newTimeMs = 700) noexcept;
/** Can be called to manually force a tip to be shown at a particular location. */
/** Can be called to manually force a tip to be shown at a particular location.
The tip will be shown until hideTip() is called, or a dismissal mouse event
occurs.
@see hideTip
*/
void displayTip (Point<int> screenPosition, const String& text);
/** Can be called to manually hide the tip if it's showing. */


Loading…
Cancel
Save