diff options
Diffstat (limited to 'src/Text.cpp')
-rw-r--r-- | src/Text.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/Text.cpp b/src/Text.cpp index ca59146..a84a824 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1,5 +1,6 @@ #include "../include/Text.hpp" #include "../include/ResourceLoader.hpp" +#include "../include/Utils.hpp" #include "../generated/Emoji.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Window/Clipboard.hpp> @@ -11,9 +12,9 @@ namespace QuickMedia { - const float TAB_WIDTH = 4.0f; - - const sf::Color URL_COLOR(15, 192, 252); + static const float TAB_WIDTH = 4.0f; + static const sf::Color URL_COLOR(15, 192, 252); + static const float WORD_WRAP_MIN_SIZE = 80.0f; size_t StringViewUtf32::find(const StringViewUtf32 &other, size_t offset) const { if(offset >= size) @@ -365,10 +366,10 @@ namespace QuickMedia EmojiRectangle emoji_rec = emoji_get_extents(codePoint); const float font_height_offset = -latin_font_height * 1.2f; - sf::Vector2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - emoji_rec.height * 0.5f); - sf::Vector2f vertexTopRight(glyphPos.x + emoji_rec.width, glyphPos.y + font_height_offset - emoji_rec.height * 0.5f); - sf::Vector2f vertexBottomLeft(glyphPos.x, glyphPos.y + font_height_offset + emoji_rec.height * 0.5f); - sf::Vector2f vertexBottomRight(glyphPos.x + emoji_rec.width, glyphPos.y + font_height_offset + emoji_rec.height * 0.5f); + sf::Vector2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - emoji_rec.height * get_ui_scale() * 0.5f); + sf::Vector2f vertexTopRight(glyphPos.x + emoji_rec.width * get_ui_scale(), glyphPos.y + font_height_offset - emoji_rec.height * get_ui_scale() * 0.5f); + sf::Vector2f vertexBottomLeft(glyphPos.x, glyphPos.y + font_height_offset + emoji_rec.height * get_ui_scale() * 0.5f); + sf::Vector2f vertexBottomRight(glyphPos.x + emoji_rec.width * get_ui_scale(), glyphPos.y + font_height_offset + emoji_rec.height * get_ui_scale() * 0.5f); sf::Vector2f textureTopLeft(emoji_rec.x, emoji_rec.y); sf::Vector2f textureTopRight(emoji_rec.x + emoji_rec.width, emoji_rec.y); @@ -525,7 +526,7 @@ namespace QuickMedia } float vertex_right_side = get_text_quad_right_side(vertex_ref); - if(vertex_right_side > maxWidth) { + if(vertex_right_side > maxWidth && maxWidth > WORD_WRAP_MIN_SIZE) { ++num_lines; // TODO: Ignore line wrap on space if(last_space_index != -1 && last_space_index != i) { @@ -887,10 +888,10 @@ namespace QuickMedia if(!editable) return true; pos.y -= floor(vspace * 2.0f); - const float caret_margin = 2.0f; + const float caret_margin = 2.0f * get_ui_scale(); - sf::RectangleShape caretRect(sf::Vector2f(2.0f, floor(vspace - caret_margin * 2.0f))); - caretRect.setPosition(floor(pos.x + caretPosition.x), floor(pos.y + caretPosition.y + caret_margin + 4.0f)); + sf::RectangleShape caretRect(sf::Vector2f(2.0f * get_ui_scale(), floor(vspace - caret_margin * 2.0f))); + caretRect.setPosition(floor(pos.x + caretPosition.x), floor(pos.y + caretPosition.y + caret_margin + 4.0f * get_ui_scale())); target.draw(caretRect); return true; } |