URI: 
       ttext.h - ltk - Socket-based GUI for X11 (WIP)
  HTML git clone git://lumidify.org/ltk.git (fast, but not encrypted)
  HTML git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       ttext.h (4044B)
       ---
            1 /*
            2  * Copyright (c) 2021-2023 lumidify <nobody@lumidify.org>
            3  *
            4  * Permission to use, copy, modify, and/or distribute this software for any
            5  * purpose with or without fee is hereby granted, provided that the above
            6  * copyright notice and this permission notice appear in all copies.
            7  *
            8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
            9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
           10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
           11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
           12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
           13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
           14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
           15  */
           16 
           17 #ifndef LTK_TEXT_H
           18 #define LTK_TEXT_H
           19 
           20 #include "color.h"
           21 #include "graphics.h"
           22 #include "ltk.h"
           23 
           24 typedef struct ltk_text_line ltk_text_line;
           25 /* typedef struct ltk_text_context ltk_text_context; */
           26 
           27 ltk_text_context *ltk_text_context_create(ltk_renderdata *data, char *default_font);
           28 void ltk_text_context_destroy(ltk_text_context *ctx);
           29 
           30 /* FIXME: allow to give length of text */
           31 /* FIXME: uint16_t as size is kind of ugly (also see window theme) */
           32 ltk_text_line *ltk_text_line_create(ltk_text_context *ctx, uint16_t font_size, char *text, int take_over_text, int width);
           33 void ltk_text_line_set_width(ltk_text_line *tl, int width);
           34 void ltk_text_line_get_size(ltk_text_line *tl, int *w, int *h);
           35 void ltk_text_line_destroy(ltk_text_line *tl);
           36 /* FIXME: length of text */
           37 void ltk_text_line_set_text(ltk_text_line *line, char *text, int take_over_text);
           38 
           39 /* Draw the entire line to a surface. */
           40 /* FIXME: Some widgets rely on this to not fail when negative coordinates are given or
           41    the text goes outside of the surface boundaries - in the stb backend, this is taken
           42    into account and the pango-xft backend doesn't *seem* to have any problems with it,
           43    but I don't know if that's guaranteed. */
           44 void ltk_text_line_draw(ltk_text_line *tl, ltk_surface *s, ltk_color *color, int x, int y);
           45 
           46 /* Draw a line onto a surface at position x,y and clipped to 'clip'.
           47    Note that 'clip' is relative to the origin of the given surface, not 'x' and 'y'. */
           48 void ltk_text_line_draw_clipped(ltk_text_line *tl, ltk_surface *s, ltk_color *color, int x, int y, ltk_rect clip);
           49 
           50 void ltk_text_line_clear_attrs(ltk_text_line *tl);
           51 void ltk_text_line_add_attr_bg(ltk_text_line *tl, size_t start, size_t end, ltk_color *color);
           52 void ltk_text_line_add_attr_fg(ltk_text_line *tl, size_t start, size_t end, ltk_color *color);
           53 
           54 typedef enum {
           55         LTK_TEXT_LTR,
           56         LTK_TEXT_RTL,
           57 } ltk_text_direction;
           58 
           59 /* FIXME: support for strong and weak cursor */
           60 /* FIXME: better interface that doesn't just return ltr on error (e.g. invalid index) */
           61 ltk_text_direction ltk_text_line_get_byte_direction(ltk_text_line *tl, size_t byte);
           62 ltk_text_direction ltk_text_line_get_softline_direction(ltk_text_line *tl, size_t line);
           63 size_t ltk_text_line_get_num_softlines(ltk_text_line *tl);
           64 size_t ltk_text_line_xy_to_pos(ltk_text_line *tl, int x, int y, int snap_nearest);
           65 void ltk_text_line_pos_to_rect(ltk_text_line *tl, size_t pos, int *x_ret, int *y_ret, int *w_ret, int *h_ret);
           66 size_t ltk_text_line_x_softline_to_pos(ltk_text_line *tl, int x, size_t softline, int snap_nearest);
           67 void ltk_text_line_pos_to_x_softline(ltk_text_line *tl, size_t pos, int middle, int *x_ret, size_t *softline_ret);
           68 size_t ltk_text_line_move_cursor_visually(ltk_text_line *tl, size_t pos, int movement, size_t *prev_index_ret);
           69 
           70 /* FIXME: two versions: bigline and normal line with text stored in memory but no bidi etc. */
           71 /* need to set endline separator so it can return when end of line reached! */
           72 /* FIXME: does this even make sense? */
           73 void ltk_text_bline_create(
           74     size_t (*iter_cur)(void *data),
           75     void (*iter_next)(void *data, char **text_ret, size_t *len_ret),
           76     void (*iter_prev)(void *data, size_t maxlen, char **text_ret, size_t *len_ret),
           77     void *data
           78 );
           79 
           80 #endif /* LTK_TEXT_H */