aboutsummaryrefslogtreecommitdiff
path: root/include/Text.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/Text.hpp')
-rw-r--r--include/Text.hpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/include/Text.hpp b/include/Text.hpp
index 1533380..73dd565 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -21,17 +21,26 @@ namespace mgl {
namespace QuickMedia
{
+ static constexpr size_t FONT_ARRAY_SIZE = 6;
+
+ enum FormattedTextFlag : uint8_t {
+ FORMATTED_TEXT_FLAG_NONE = 0,
+ //FORMATTED_TEXT_FLAG_BOLD = 1 << 0,
+ FORMATTED_TEXT_FLAG_MONOSPACE = 1 << 1,
+ FORMATTED_TEXT_FLAG_COLOR = 1 << 2
+ };
+
struct TextElement
{
enum class Type {
TEXT,
+ FORMAT_START,
+ FORMAT_END,
IMAGE
};
enum class TextType {
- LATIN,
- CJK,
- SYMBOL,
+ TEXT,
EMOJI
};
@@ -39,7 +48,7 @@ namespace QuickMedia
void create_text(std::string_view text) {
this->text = text;
- text_type = TextType::LATIN;
+ text_type = TextType::TEXT;
type = Type::TEXT;
}
@@ -50,10 +59,14 @@ namespace QuickMedia
this->size = size;
type = Type::IMAGE;
}
+
+ // TODO: Remove some fields
// TODO: union grouped
std::string_view text;
- TextType text_type = TextType::LATIN;
+ TextType text_type = TextType::TEXT;
+ mgl::Color color = mgl::Color(255, 255, 255, 255);
+ uint8_t text_flags = FORMATTED_TEXT_FLAG_NONE; // FormattedTextFlag
// TODO: Remove these
std::string url;
@@ -78,17 +91,17 @@ namespace QuickMedia
{
public:
Text(std::string str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls = false);
- Text(const Text &other);
- Text& operator=(const Text&);
void setString(std::string str);
const std::string& getString() const;
void appendText(const std::string &str);
// size = {0, 0} = keep original image size
- void append_image(const std::string &url, bool local, mgl::vec2i size);
static std::string formatted_image(const std::string &url, bool local, mgl::vec2i size);
- static std::string formatted_text(const std::string &text, mgl::Color color, bool bold);
+ // text_flags is bit-or of FormattedTextFlag
+ static std::string formatted_text(const std::string &text, mgl::Color color, uint8_t text_flags);
void insert_text_at_caret_position(const std::string &str);
+
+ static std::string to_printable_string(const std::string &str);
void set_position(float x, float y);
void set_position(const mgl::vec2f &position);
@@ -104,7 +117,7 @@ namespace QuickMedia
int getCaretIndex() const;
int getNumLines() const;
- void set_color(mgl::Color color);
+ void set_color(mgl::Color color, bool force_color = false);
void setLineSpacing(float lineSpacing);
void setCharacterSpacing(float characterSpacing);
void setEditable(bool editable);
@@ -151,7 +164,8 @@ namespace QuickMedia
int getPreviousLineClosestPosition(int startIndex) const;
int getNextLineClosestPosition(int startIndex) const;
- void split_text_by_type(std::vector<TextElement> &text_elements, const std::string &str);
+ static void split_text_by_type(std::vector<TextElement> &text_elements, std::string_view str, float vspace);
+ void split_text_by_type();
float font_get_real_height(mgl::Font *font);
float get_text_quad_left_side(const VertexRef &vertex_ref) const;
@@ -164,14 +178,15 @@ namespace QuickMedia
uint32_t get_vertex_codepoint(int index) const;
size_t get_string_index_from_caret_index(size_t caret_index) const;
private:
- std::string str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text
+ std::string str; // TODO: Remove this for non-editable text???
bool bold_font;
unsigned int characterSize;
- std::array<std::vector<mgl::Vertex>, 5> vertices;
- std::array<mgl::VertexBuffer, 5> vertex_buffers;
+ std::array<std::vector<mgl::Vertex>, FONT_ARRAY_SIZE> vertices;
+ std::array<mgl::VertexBuffer, FONT_ARRAY_SIZE> vertex_buffers;
float maxWidth;
mgl::vec2f position;
mgl::Color color;
+ bool force_color;
bool dirty;
bool dirtyText;
bool dirtyCaret;