Browse Source

Altered BubbleMessageComponent to take an AttributedString rather than a plain String, for more control over its layout.

tags/2021-05-28
jules 13 years ago
parent
commit
cb169b251d
3 changed files with 16 additions and 16 deletions
  1. +6
    -2
      extras/JuceDemo/Source/demos/WidgetsDemo.cpp
  2. +7
    -11
      modules/juce_gui_extra/misc/juce_BubbleMessageComponent.cpp
  3. +3
    -3
      modules/juce_gui_extra/misc/juce_BubbleMessageComponent.h

+ 6
- 2
extras/JuceDemo/Source/demos/WidgetsDemo.cpp View File

@@ -935,8 +935,12 @@ public:
addChildComponent (bmc);
}
bmc->showAt (button, "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing at a component or somewhere on the screen.\n\nThe message bubbles will disappear after a timeout period, or when the mouse is clicked.",
2000, true, true);
AttributedString text ("This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing "
"at a component or somewhere on the screen.\n\n"
"The message bubbles will disappear after a timeout period, or when the mouse is clicked.");
text.setJustification (Justification::centred);
bmc->showAt (button, text, 2000, true, true);
}
static const Colour getRandomBrightColour()


+ 7
- 11
modules/juce_gui_extra/misc/juce_BubbleMessageComponent.cpp View File

@@ -35,7 +35,7 @@ BubbleMessageComponent::~BubbleMessageComponent()
}
void BubbleMessageComponent::showAt (int x, int y,
const String& text,
const AttributedString& text,
const int numMillisecondsBeforeRemoving,
const bool removeWhenMouseClicked,
const bool deleteSelfAfterUse)
@@ -46,7 +46,7 @@ void BubbleMessageComponent::showAt (int x, int y,
}
void BubbleMessageComponent::showAt (Component* const component,
const String& text,
const AttributedString& text,
const int numMillisecondsBeforeRemoving,
const bool removeWhenMouseClicked,
const bool deleteSelfAfterUse)
@@ -56,13 +56,9 @@ void BubbleMessageComponent::showAt (Component* const component,
init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
}
void BubbleMessageComponent::createLayout (const String& text)
void BubbleMessageComponent::createLayout (const AttributedString& text)
{
AttributedString attString;
attString.append (text, Font (14.0f));
attString.setJustification (Justification::centred);
textLayout.createLayoutWithBalancedLineLengths (attString, 256);
textLayout.createLayoutWithBalancedLineLengths (text, 256);
}
void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
@@ -90,15 +86,15 @@ void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
void BubbleMessageComponent::getContentSize (int& w, int& h)
{
w = (int) (textLayout.getWidth() + 16.0f);
h = (int) (textLayout.getHeight() + 16.0f);
w = 16 + (int) textLayout.getWidth();
h = 16 + (int) textLayout.getHeight();
}
void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
{
g.setColour (findColour (TooltipWindow::textColourId));
textLayout.draw (g, Rectangle<float> (0.0f, 0.0f, (float) w, (float) h));
textLayout.draw (g, Rectangle<float> ((float) w, (float) h));
}
void BubbleMessageComponent::timerCallback()


+ 3
- 3
modules/juce_gui_extra/misc/juce_BubbleMessageComponent.h View File

@@ -77,7 +77,7 @@ public:
it becomes invisible
*/
void showAt (int x, int y,
const String& message,
const AttributedString& message,
int numMillisecondsBeforeRemoving,
bool removeWhenMouseClicked = true,
bool deleteSelfAfterUse = false);
@@ -100,7 +100,7 @@ public:
it becomes invisible
*/
void showAt (Component* component,
const String& message,
const AttributedString& message,
int numMillisecondsBeforeRemoving,
bool removeWhenMouseClicked = true,
bool deleteSelfAfterUse = false);
@@ -121,7 +121,7 @@ private:
int64 expiryTime;
bool deleteAfterUse;
void createLayout (const String&);
void createLayout (const AttributedString&);
void init (int numMillisecondsBeforeRemoving,
bool removeWhenMouseClicked,
bool deleteSelfAfterUse);


Loading…
Cancel
Save