New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add text alignment to sf::Text
#2713
Open
Hapaxia
wants to merge
4
commits into
SFML:master
Choose a base branch
from
Hapaxia:text-align
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−33
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,6 +63,17 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable | |||||
StrikeThrough = 1 << 3 //!< Strike through characters | ||||||
}; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Enumeration of the text alignment options | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
enum LineAlignment | ||||||
{ | ||||||
Left, //!< Align lines to the left | ||||||
Center, //!< Align lines centrally | ||||||
Right //!< Align lines to the right | ||||||
}; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Construct the text from a string, font and size | ||||||
/// | ||||||
|
@@ -237,6 +248,18 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable | |||||
//////////////////////////////////////////////////////////// | ||||||
void setOutlineThickness(float thickness); | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Set the line alignment for a multi-line text | ||||||
/// | ||||||
/// By default, the line alignment is Left. | ||||||
/// | ||||||
/// \param lineAlignment New line alignment | ||||||
/// | ||||||
/// \see getLineAlignment | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
void setLineAlignment(LineAlignment lineAlignment); | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Get the text's string | ||||||
/// | ||||||
|
@@ -339,6 +362,16 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable | |||||
//////////////////////////////////////////////////////////// | ||||||
float getOutlineThickness() const; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Get the line alignment for a multi-line text | ||||||
/// | ||||||
/// \return Line alignment | ||||||
/// | ||||||
/// \see setLineAlignment | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
LineAlignment getLineAlignment() const; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Return the position of the \a index-th character | ||||||
/// | ||||||
|
@@ -403,6 +436,33 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable | |||||
//////////////////////////////////////////////////////////// | ||||||
void ensureGeometryUpdate() const; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Calculate and update the line offsets | ||||||
/// | ||||||
/// This is required before updating geometry or | ||||||
/// finding the character position as this information | ||||||
/// is needed in both places. | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
void updateLineOffsets() const; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Structure storing spacing information | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
struct Spacing | ||||||
{ | ||||||
float whitespaceWidth{}; | ||||||
float letterSpacing{}; | ||||||
float lineSpacing{}; | ||||||
}; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
/// \brief Calculate various text spacing values | ||||||
/// | ||||||
//////////////////////////////////////////////////////////// | ||||||
Spacing getSpacing() const; | ||||||
|
||||||
//////////////////////////////////////////////////////////// | ||||||
// Member data | ||||||
//////////////////////////////////////////////////////////// | ||||||
|
@@ -415,11 +475,13 @@ class SFML_GRAPHICS_API Text : public Drawable, public Transformable | |||||
Color m_fillColor{Color::White}; //!< Text fill color | ||||||
Color m_outlineColor{Color::Black}; //!< Text outline color | ||||||
float m_outlineThickness{0.f}; //!< Thickness of the text's outline | ||||||
LineAlignment m_lineAlignment{Left}; //!< Line alignment for a multi-line text | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
mutable VertexArray m_vertices{PrimitiveType::Triangles}; //!< Vertex array containing the fill geometry | ||||||
mutable VertexArray m_outlineVertices{PrimitiveType::Triangles}; //!< Vertex array containing the outline geometry | ||||||
mutable FloatRect m_bounds; //!< Bounding rectangle of the text (in local coordinates) | ||||||
mutable bool m_geometryNeedUpdate{}; //!< Does the geometry need to be recomputed? | ||||||
mutable std::uint64_t m_fontTextureId{}; //!< The font texture id | ||||||
mutable std::vector<float> m_lineOffsets; //!< The horizontal offsets of each line of a multi-line text | ||||||
}; | ||||||
|
||||||
} // namespace sf | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.