7 typedef struct View View
;
8 typedef struct Cursor Cursor
;
9 typedef struct Selection Selection
;
17 void (*draw
)(void *data
);
21 int width
; /* display width i.e. number of columns occupied by this character */
22 size_t len
; /* number of bytes the character displayed in this cell uses, for
23 characters which use more than 1 column to display, their length
24 is stored in the leftmost cell whereas all following cells
25 occupied by the same character have a length of 0. */
26 char data
[16]; /* utf8 encoded character displayed in this cell (might be more than
27 one Unicode codepoint. might also not be the same as in the
28 underlying text, for example tabs get expanded */
29 enum UiStyle style
; /* style id used to display this cell */
30 bool selected
; /* whether this cell is part of a selected region */
31 bool cursor
; /* whether a cursor is currently located on the cell */
32 bool cursor_primary
;/* whether it is the primary cursor located on the cell */
35 typedef struct Line Line
;
36 struct Line
{ /* a line on the screen, *not* in the file */
37 Line
*prev
, *next
; /* pointer to neighbouring screen lines */
38 size_t len
; /* line length in terms of bytes */
39 size_t lineno
; /* line number from start of file */
40 int width
; /* zero based position of last used column cell */
41 Cell cells
[]; /* win->width cells storing information about the displayed characters */
44 View
*view_new(Text
*, ViewEvent
*);
45 void view_ui(View
*, UiWin
*);
46 /* change associated text displayed in this window */
47 void view_reload(View
*, Text
*);
48 void view_free(View
*);
50 bool view_resize(View
*, int width
, int height
);
51 int view_height_get(View
*);
52 int view_width_get(View
*);
53 void view_draw(View
*);
54 void view_update(View
*);
55 /* changes how many spaces are used for one tab (must be >0), redraws the window */
56 void view_tabwidth_set(View
*, int tabwidth
);
58 /* cursor movements which also update selection if one is active.
59 * they return new cursor postion */
60 size_t view_line_down(Cursor
*);
61 size_t view_line_up(Cursor
*);
62 size_t view_screenline_down(Cursor
*);
63 size_t view_screenline_up(Cursor
*);
64 size_t view_screenline_begin(Cursor
*);
65 size_t view_screenline_middle(Cursor
*);
66 size_t view_screenline_end(Cursor
*);
68 /* move window content up/down, but keep cursor position unchanged unless it is
69 * on a now invisible line in which case we try to preserve the column position */
70 size_t view_slide_up(View
*, int lines
);
71 size_t view_slide_down(View
*, int lines
);
72 /* scroll window contents up/down by lines, place the cursor on the newly
73 * visible line, try to preserve the column position */
74 size_t view_scroll_up(View
*, int lines
);
75 size_t view_scroll_down(View
*, int lines
);
76 size_t view_scroll_page_up(View
*);
77 size_t view_scroll_page_down(View
*);
78 size_t view_scroll_halfpage_up(View
*);
79 size_t view_scroll_halfpage_down(View
*);
80 /* place the cursor at the start ot the n-th window line, counting from 1 */
81 size_t view_screenline_goto(View
*, int n
);
83 const Line
*view_lines_get(View
*);
84 const Line
*view_line_get(View
*);
85 /* redraw current cursor line at top/center/bottom of window */
86 void view_redraw_top(View
*);
87 void view_redraw_center(View
*);
88 void view_redraw_bottom(View
*);
89 /* get the currently displayed area in bytes from the start of the file */
90 Filerange
view_viewport_get(View
*);
91 /* move visible viewport n-lines up/down, redraws the view but does not change
92 * cursor position which becomes invalid and should be corrected by calling
93 * view_cursor_to. the return value indicates wether the visible area changed.
95 bool view_viewport_up(View
*view
, int n
);
96 bool view_viewport_down(View
*view
, int n
);
98 void view_options_set(View
*, enum UiOption options
);
99 enum UiOption
view_options_get(View
*);
100 void view_colorcolumn_set(View
*, int col
);
101 int view_colorcolumn_get(View
*);
103 /* A view can manage multiple cursors, one of which (the main cursor) is always
104 * placed within the visible viewport. All functions named view_cursor_* operate
105 * on this cursor. Additional cursor can be created and manipulated using the
106 * functions named view_cursors_* */
108 /* get main cursor position in bytes from start of the file */
109 size_t view_cursor_get(View
*);
110 /* get selection associated with primary cursor */
111 Filerange
view_selection_get(View
*);
112 /* moves window viewport in direction until pos is visible. should only be
113 * used for short distances between current cursor position and destination */
114 void view_scroll_to(View
*, size_t pos
);
115 /* move cursor to a given position. changes the viewport to make sure that
116 * position is visible. if the position is in the middle of a line, try to
117 * adjust the viewport in such a way that the whole line is displayed */
118 void view_cursor_to(View
*, size_t pos
);
119 /* create a new cursor at given position, fails if there already
120 * exists a cursor at the same position */
121 Cursor
*view_cursors_new(View
*, size_t pos
);
122 /* create a new cursor even if there already is one located at the
123 * same position, this should only be used if the one of the two
124 * cursors will later be disposed */
125 Cursor
*view_cursors_new_force(View
*, size_t pos
);
126 /* get number of active cursors */
127 int view_cursors_count(View
*);
128 /* get index/relative order at time of creation of a cursor [0,count-1] */
129 int view_cursors_number(Cursor
*);
130 /* exist there more than 1 cursor */
131 bool view_cursors_multiple(View
*);
132 /* dispose an existing cursor with its associated selection (if any),
133 * not applicaple for the last existing cursor */
134 bool view_cursors_dispose(Cursor
*);
135 /* only keep the main cursor, release all others together with their
136 * selections (if any) */
137 void view_cursors_clear(View
*);
138 /* get the first cursor */
139 Cursor
*view_cursors(View
*);
140 /* get other cursors, no ordering is guaranteed */
141 Cursor
*view_cursors_prev(Cursor
*);
142 Cursor
*view_cursors_next(Cursor
*);
143 /* get the primary cursor which is always in the visible viewport */
144 Cursor
*view_cursors_primary_get(View
*);
145 void view_cursors_primary_set(Cursor
*);
146 /* get current position of cursor in bytes from the start of the file */
147 size_t view_cursors_pos(Cursor
*);
148 /* get 1-based line number of cursor location */
149 size_t view_cursors_line(Cursor
*);
150 /* get 1-based column (number of graphemes on line) cursor postion */
151 size_t view_cursors_col(Cursor
*);
152 /* get/set zero based index of cell on which cursor currently resides,
153 * -1 if cursor is currently not visible */
154 int view_cursors_cell_get(Cursor
*);
155 int view_cursors_cell_set(Cursor
*, int cell
);
156 /* place cursor at `pos' which should be in the interval [0, text-size] */
157 void view_cursors_to(Cursor
*, size_t pos
);
158 void view_cursors_scroll_to(Cursor
*, size_t pos
);
159 /* place cursor on given (line, column) pair, both values are 1-based */
160 void view_cursors_place(Cursor
*, size_t line
, size_t col
);
161 /* get register associated with this register */
162 Register
*view_cursors_register(Cursor
*);
163 /* start selected area at current cursor position. further cursor movements
164 * will affect the selected region. */
165 void view_cursors_selection_start(Cursor
*);
166 /* detach cursor from selection, further cursor movements will not affect
167 * the selected region. */
168 void view_cursors_selection_stop(Cursor
*);
169 /* clear selection associated with this cursor (if any) */
170 void view_cursors_selection_clear(Cursor
*);
171 /* move cursor position from one end of the selection to the other */
172 void view_cursors_selection_swap(Cursor
*);
173 /* move cursor to the end/boundary of the associated selection */
174 void view_cursors_selection_sync(Cursor
*);
175 /* restore previous used selection of this cursor */
176 void view_cursors_selection_restore(Cursor
*);
177 /* get/set the selected region associated with this cursor */
178 Filerange
view_cursors_selection_get(Cursor
*);
179 void view_cursors_selection_set(Cursor
*, const Filerange
*);
181 Selection
*view_selections_new(View
*);
182 void view_selections_free(Selection
*);
183 void view_selections_clear(View
*);
184 void view_selections_swap(Selection
*);
185 Selection
*view_selections(View
*);
186 Selection
*view_selections_prev(Selection
*);
187 Selection
*view_selections_next(Selection
*);
188 Filerange
view_selections_get(Selection
*);
189 void view_selections_set(Selection
*, const Filerange
*);
190 Text
*view_text(View
*);
192 /* get number of columns, that is maximal number of cursors on a line */
193 int view_cursors_column_count(View
*);
194 /* get first cursor in zero based column */
195 Cursor
*view_cursors_column(View
*, int column
);
196 /* get next cursor (i.e. on another line) in zero based column */
197 Cursor
*view_cursors_column_next(Cursor
*, int column
);
199 bool view_style_define(View
*, enum UiStyle
, const char *style
);
200 void view_style(View
*, enum UiStyle
, size_t start
, size_t end
);