// vtext: A text visualization widget // // This is a trivial widget, just displays line-by-line with or without line // wrapping. #pragma once #include #include #include /* Wrapping modes */ typedef enum { VTEXT_WRAP_NONE, VTEXT_WRAP_CHAR, VTEXT_WRAP_WORD, } vtext_wrap; /* vtext: Text visualization widget */ typedef struct { jwidget widget; /* Current data block and size */ char const *data; int size; /* Word wrapping mode */ vtext_wrap wrap; /* Current scroll offset, in bytes */ int scroll; /* Current horizontal offset, in pixels */ int horiz_scroll; /* Number of virtual lines (depends on wrapping mode) */ int virtual_lines; /* Maximum scroll */ int max_scroll; /* Virtual line offsets */ uint32_t *vline_offsets; /* Number of visible lines */ int8_t visible_lines; /* Additional spacing between lines, in pixels */ int8_t line_spacing; /* Rendering font */ font_t const *font; } vtext; /* Type IDs */ extern uint16_t VTEXT_CHANGED; /* vtext_create: Create a new text visualizer */ vtext *vtext_create(jwidget *parent); /* Set a new data source. The viewer does not own the data. */ void vtext_set_source(vtext *t, char const *data, int size); /* Scroll to a given (top) virtual line position. */ bool vtext_scroll_to(vtext *t, int top_vline); /* Search a string and go to the next occurrence. */ bool vtext_scroll_to_substring(vtext *t, char const *substring); /* Trivial properties */ void vtext_set_font(vtext *e, font_t const *font); void vtext_set_line_spacing(vtext *e, int line_spacing); void vtext_set_word_wrapping(vtext *e, vtext_wrap word_wrapping);