JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AttributedString.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
46class JUCE_API AttributedString
47{
48public:
50 AttributedString() = default;
51
53 explicit AttributedString (const String& newString) { setText (newString); }
54
55 AttributedString (const AttributedString&) = default;
56 AttributedString& operator= (const AttributedString&) = default;
57 AttributedString (AttributedString&&) noexcept = default;
58 AttributedString& operator= (AttributedString&&) noexcept = default;
59
60 //==============================================================================
62 const String& getText() const noexcept { return text; }
63
68 void setText (const String& newText);
69
71 void append (const String& textToAppend);
73 void append (const String& textToAppend, const Font& font);
75 void append (const String& textToAppend, Colour colour);
77 void append (const String& textToAppend, const Font& font, Colour colour);
78
83 void append (const AttributedString& other);
84
89 void clear();
90
91 //==============================================================================
96 void draw (Graphics& g, const Rectangle<float>& area) const;
97
98 //==============================================================================
102 Justification getJustification() const noexcept { return justification; }
103
107 void setJustification (Justification newJustification) noexcept;
108
109 //==============================================================================
119
121 WordWrap getWordWrap() const noexcept { return wordWrap; }
122
124 void setWordWrap (WordWrap newWordWrap) noexcept;
125
126 //==============================================================================
131 {
132 natural,
133 leftToRight,
134 rightToLeft,
135 };
136
138 ReadingDirection getReadingDirection() const noexcept { return readingDirection; }
139
141 void setReadingDirection (ReadingDirection newReadingDirection) noexcept;
142
143 //==============================================================================
145 float getLineSpacing() const noexcept { return lineSpacing; }
146
148 void setLineSpacing (float newLineSpacing) noexcept;
149
150 //==============================================================================
152 class JUCE_API Attribute
153 {
154 public:
155 Attribute() = default;
156
157 Attribute (const Attribute&) = default;
158 Attribute& operator= (const Attribute&) = default;
159 Attribute (Attribute&&) noexcept = default;
160 Attribute& operator= (Attribute&&) noexcept = default;
161
163 Attribute (Range<int> range, const Font& font, Colour colour) noexcept;
164
167
170
172 Colour colour { 0xff000000 };
173
174 private:
176 };
177
179 int getNumAttributes() const noexcept { return attributes.size(); }
180
184 const Attribute& getAttribute (int index) const noexcept { return attributes.getReference (index); }
185
186 //==============================================================================
188 void setColour (Range<int> range, Colour colour);
189
191 void setColour (Colour colour);
192
194 void setFont (Range<int> range, const Font& font);
195
197 void setFont (const Font& font);
198
199private:
200 String text;
201 float lineSpacing = 0.0f;
202 Justification justification = Justification::left;
203 WordWrap wordWrap = AttributedString::byWord;
204 ReadingDirection readingDirection = AttributedString::natural;
205 Array<Attribute> attributes;
206
208};
209
210} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
An attribute that has been applied to a range of characters in an AttributedString.
Font font
The font for this range of characters.
Range< int > range
The range of characters to which this attribute will be applied.
A text string with a set of colour/font settings that are associated with sub-ranges of the text.
WordWrap getWordWrap() const noexcept
Returns the word-wrapping behaviour.
AttributedString()=default
Creates an empty attributed string.
AttributedString(const String &newString)
Creates an attributed string with the given text.
float getLineSpacing() const noexcept
Returns the extra line-spacing distance.
const Attribute & getAttribute(int index) const noexcept
Returns one of the string's attributes.
ReadingDirection
Types of reading direction that can be used.
int getNumAttributes() const noexcept
Returns the number of attributes that have been added to this string.
WordWrap
Types of word-wrap behaviour.
@ none
No word-wrapping: lines extend indefinitely.
@ byWord
Lines are wrapped on a word boundary.
@ byChar
Lines are wrapped on a character boundary.
ReadingDirection getReadingDirection() const noexcept
Returns the reading direction for the text.
Justification getJustification() const noexcept
Returns the justification that should be used for laying-out the text.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition juce_Range.h:40
Manages a rectangle and allows geometric operations to be performed on it.
The JUCE String class!
Definition juce_String.h:53
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
JUCE Namespace.