aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/graphics/text.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-31 12:50:05 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-02 02:23:54 +0100
commit111f0ba3f4a4f14d39c8e3f7c00f13e852f47a51 (patch)
treefc7317e332c7a56df7738a62110ad76d4fc8511c /include/mgl/graphics/text.h
parent8a316a12481282cb2ab966c4cbc770656c258383 (diff)
Start on syntax highlighting, output correct key button event
Diffstat (limited to 'include/mgl/graphics/text.h')
-rw-r--r--include/mgl/graphics/text.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h
index 2c2eeaf..9169ab0 100644
--- a/include/mgl/graphics/text.h
+++ b/include/mgl/graphics/text.h
@@ -1,28 +1,47 @@
#ifndef MGL_TEXT_H
#define MGL_TEXT_H
+/*
+ TODO: Do not render text outside the window and start from the visible part.
+ Support 64-bit text length on 32-bit systems, and use mmap to optimize loading very large files,
+ and munmap the text parts that are not visible on the screen.
+*/
+
#include "../system/vec.h"
#include "color.h"
+#include <stddef.h>
+#include <stdbool.h>
typedef struct mgl_font mgl_font;
typedef struct mgl_context mgl_context;
typedef struct {
+ /* Optional */
+ void (*before_syntax_highlight)(void *userdata);
+ /* Return true if the text format should be changed. Optional */
+ bool (*syntax_highlight)(void *userdata, const char *str, size_t size, mgl_color *color);
+ void *userdata;
+} mgl_text_options;
+
+typedef struct {
mgl_font *font; /* nullable */
const char *text; /* nullable */
+ size_t text_size;
mgl_color color;
mgl_vec2f position;
+ mgl_text_options options;
} mgl_text;
/*
Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used.
|font| and |text| may be NULL.
+ |load_options| can be NULL, in which case the default options are used.
*/
-int mgl_text_init(mgl_text *self, mgl_font *font, const char *text, float x, float y);
+int mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size, mgl_text_options *options);
void mgl_text_deinit(mgl_text *self);
/* Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used. |text| may be NULL. */
-void mgl_text_set_string(mgl_text *self, const char *str);
+void mgl_text_set_string(mgl_text *self, const char *str, size_t str_size);
/* |font| may be NULL */
void mgl_text_set_font(mgl_text *self, mgl_font *font);
void mgl_text_set_position(mgl_text *self, mgl_vec2f position);