Browse Source

Replaced the old LookAndFeel method getTooltipSize() with getTooltipBounds(), which can return a position as well as a size.

tags/2021-05-28
jules 10 years ago
parent
commit
e3dfaff0db
4 changed files with 21 additions and 17 deletions
  1. +8
    -3
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  2. +1
    -1
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h
  3. +3
    -10
      modules/juce_gui_basics/windows/juce_TooltipWindow.cpp
  4. +9
    -3
      modules/juce_gui_basics/windows/juce_TooltipWindow.h

+ 8
- 3
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp View File

@@ -1493,12 +1493,17 @@ int LookAndFeel_V2::getSliderPopupPlacement (Slider&)
}
//==============================================================================
void LookAndFeel_V2::getTooltipSize (const String& tipText, int& width, int& height)
Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea)
{
const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
width = (int) (tl.getWidth() + 14.0f);
height = (int) (tl.getHeight() + 6.0f);
const int w = (int) (tl.getWidth() + 14.0f);
const int h = (int) (tl.getHeight() + 6.0f);
return Rectangle<int> (screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 12) : screenPos.x + 24,
screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 6) : screenPos.y + 6,
w, h)
.constrainedWithin (parentArea);
}
void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, int height)


+ 1
- 1
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h View File

@@ -195,7 +195,7 @@ public:
int getSliderPopupPlacement (Slider&) override;
//==============================================================================
void getTooltipSize (const String& tipText, int& width, int& height) override;
Rectangle<int> getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) override;
void drawTooltip (Graphics&, const String& text, int width, int height) override;
//==============================================================================


+ 3
- 10
modules/juce_gui_basics/windows/juce_TooltipWindow.cpp View File

@@ -60,16 +60,9 @@ void TooltipWindow::mouseEnter (const MouseEvent&)
hideTip();
}
void TooltipWindow::updatePosition (const String& tip, Point<int> pos, const Rectangle<int>& parentArea)
void TooltipWindow::updatePosition (const String& tip, Point<int> pos, Rectangle<int> parentArea)
{
int w, h;
getLookAndFeel().getTooltipSize (tip, w, h);
setBounds (Rectangle<int> (pos.x > parentArea.getCentreX() ? pos.x - (w + 12) : pos.x + 24,
pos.y > parentArea.getCentreY() ? pos.y - (h + 6) : pos.y + 6,
w, h)
.constrainedWithin (parentArea));
setBounds (getLookAndFeel().getTooltipBounds (tip, pos, parentArea));
setVisible (true);
}
@@ -112,7 +105,7 @@ String TooltipWindow::getTipFor (Component* const c)
&& Process::isForegroundProcess()
&& ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
{
if (TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c))
if (TooltipClient* const ttc = dynamic_cast<TooltipClient*> (c))
if (! c->isCurrentlyBlockedByAnotherModalComponent())
return ttc->getTooltip();
}


+ 9
- 3
modules/juce_gui_basics/windows/juce_TooltipWindow.h View File

@@ -61,7 +61,7 @@ public:
@param millisecondsBeforeTipAppears the time for which the mouse has to stay still
before a tooltip will be shown
@see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
@see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipBounds
*/
explicit TooltipWindow (Component* parentComponent = nullptr,
int millisecondsBeforeTipAppears = 700);
@@ -104,8 +104,14 @@ public:
{
virtual ~LookAndFeelMethods() {}
virtual void getTooltipSize (const String& tipText, int& width, int& height) = 0;
/** returns the bounds for a tooltip at the given screen coordinate, constrained within the given desktop area. */
virtual Rectangle<int> getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) = 0;
virtual void drawTooltip (Graphics&, const String& text, int width, int height) = 0;
#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
// This method has been replaced by getTooltipBounds()
virtual int getTooltipSize (const String&, int&, int&) { return 0; }
#endif
};
private:
@@ -121,7 +127,7 @@ private:
void paint (Graphics&) override;
void mouseEnter (const MouseEvent&) override;
void timerCallback() override;
void updatePosition (const String&, Point<int>, const Rectangle<int>&);
void updatePosition (const String&, Point<int>, Rectangle<int>);
static String getTipFor (Component*);


Loading…
Cancel
Save