Browse Source

Added a method for concatenating AttributedStrings.

tags/2021-05-28
jules 13 years ago
parent
commit
583dcca1e5
2 changed files with 24 additions and 0 deletions
  1. +16
    -0
      modules/juce_graphics/fonts/juce_AttributedString.cpp
  2. +8
    -0
      modules/juce_graphics/fonts/juce_AttributedString.h

+ 16
- 0
modules/juce_graphics/fonts/juce_AttributedString.cpp View File

@@ -40,6 +40,13 @@ AttributedString::Attribute::Attribute (const Attribute& other)
{ {
} }
AttributedString::Attribute::Attribute (const Attribute& other, const int offset)
: range (other.range + offset),
font (other.font.createCopy()),
colour (other.colour.createCopy())
{
}
AttributedString::Attribute::~Attribute() {} AttributedString::Attribute::~Attribute() {}
//============================================================================== //==============================================================================
@@ -149,6 +156,15 @@ void AttributedString::append (const String& textToAppend, const Font& font, con
setColour (Range<int> (oldLength, oldLength + newLength), colour); setColour (Range<int> (oldLength, oldLength + newLength), colour);
} }
void AttributedString::append (const AttributedString& other)
{
const int originalLength = text.length();
text += other.text;
for (int i = 0; i < other.attributes.size(); ++i)
attributes.add (new Attribute (*other.attributes.getUnchecked(i), originalLength));
}
void AttributedString::clear() void AttributedString::clear()
{ {
text = String::empty; text = String::empty;


+ 8
- 0
modules/juce_graphics/fonts/juce_AttributedString.h View File

@@ -75,6 +75,12 @@ public:
/** Appends some text, with a specified font and colour. */ /** Appends some text, with a specified font and colour. */
void append (const String& textToAppend, const Font& font, const Colour& colour); void append (const String& textToAppend, const Font& font, const Colour& colour);
/** Appends another AttributedString to this one.
Note that this will only append the text, fonts, and colours - it won't copy any
other properties such as justification, line-spacing, etc from the other object.
*/
void append (const AttributedString& other);
/** Resets the string, clearing all text and attributes. /** Resets the string, clearing all text and attributes.
Note that this won't affect global settings like the justification type, Note that this won't affect global settings like the justification type,
word-wrap mode, etc. word-wrap mode, etc.
@@ -171,6 +177,8 @@ public:
ScopedPointer<Font> font; ScopedPointer<Font> font;
ScopedPointer<Colour> colour; ScopedPointer<Colour> colour;
friend class AttributedString;
Attribute (const Attribute&, int);
Attribute& operator= (const Attribute&); Attribute& operator= (const Attribute&);
JUCE_LEAK_DETECTOR (Attribute); JUCE_LEAK_DETECTOR (Attribute);


Loading…
Cancel
Save