12 typedef struct View View
;
13 typedef struct Cursor Cursor
;
14 typedef struct Selection Selection
;
18 void (*selection
)(void *data
, Filerange
*);
22 int width
; /* display width i.e. number of columns ocupied by this character */
23 size_t len
; /* number of bytes the character displayed in this cell uses, for
24 character which use more than 1 column to display, their lenght
25 is stored in the leftmost cell wheras all following cells
26 occupied by the same character have a length of 0. */
27 char data
[8]; /* utf8 encoded character displayed in this cell might not be the
28 the same as in the underlying text, for example tabs get expanded */
31 bool selected
; /* whether this cell is part of a selected region */
32 bool cursor
; /* whether a cursor is currently locaated 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 */
49 View
*view_new(Text
*, lua_State
*, ViewEvent
*);
50 void view_ui(View
*, UiWin
*);
51 /* change associated text displayed in this window */
52 void view_reload(View
*, Text
*);
53 void view_free(View
*);
55 bool view_resize(View
*, int width
, int height
);
56 int view_height_get(View
*);
57 int view_width_get(View
*);
58 void view_draw(View
*);
59 /* changes how many spaces are used for one tab (must be >0), redraws the window */
60 void view_tabwidth_set(View
*, int tabwidth
);
62 /* cursor movements which also update selection if one is active.
63 * they return new cursor postion */
64 size_t view_line_down(Cursor
*);
65 size_t view_line_up(Cursor
*);
66 size_t view_screenline_down(Cursor
*);
67 size_t view_screenline_up(Cursor
*);
68 size_t view_screenline_begin(Cursor
*);
69 size_t view_screenline_middle(Cursor
*);
70 size_t view_screenline_end(Cursor
*);
71 /* move window content up/down, but keep cursor position unchanged unless it is
72 * on a now invisible line in which case we try to preserve the column position */
73 size_t view_slide_up(View
*, int lines
);
74 size_t view_slide_down(View
*, int lines
);
75 /* scroll window contents up/down by lines, place the cursor on the newly
76 * visible line, try to preserve the column position */
77 size_t view_scroll_up(View
*, int lines
);
78 size_t view_scroll_down(View
*, int lines
);
79 /* place the cursor at the start ot the n-th window line, counting from 1 */
80 size_t view_screenline_goto(View
*, int n
);
82 const Line
*view_lines_get(View
*);
83 /* redraw current cursor line at top/center/bottom of window */
84 void view_redraw_top(View
*);
85 void view_redraw_center(View
*);
86 void view_redraw_bottom(View
*);
87 /* get the currently displayed area in bytes from the start of the file */
88 Filerange
view_viewport_get(View
*);
89 /* move visible viewport n-lines up/down, redraws the view but does not change
90 * cursor position which becomes invalid and should be corrected by calling
91 * view_cursor_to. the return value indicates wether the visible area changed.
93 bool view_viewport_up(View
*view
, int n
);
94 bool view_viewport_down(View
*view
, int n
);
95 /* associate a set of syntax highlighting rules to this window. */
96 bool view_syntax_set(View
*, const char *name
);
97 const char *view_syntax_get(View
*);
99 void view_options_set(View
*, enum UiOption options
);
100 enum UiOption
view_options_get(View
*);
102 /* A view can manage multiple cursors, one of which (the main cursor) is always
103 * placed within the visible viewport. All functions named view_cursor_* operate
104 * on this cursor. Additional cursor can be created and manipulated using the
105 * functions named view_cursors_* */
107 /* get main cursor position in terms of screen coordinates */
108 CursorPos
view_cursor_getpos(View
*);
109 /* get main cursor position in bytes from start of the file */
110 size_t view_cursor_get(View
*);
111 /* moves window viewport in direction until pos is visible. should only be
112 * used for short distances between current cursor position and destination */
113 void view_scroll_to(View
*, size_t pos
);
114 /* move cursor to a given position. changes the viewport to make sure that
115 * position is visible. if the position is in the middle of a line, try to
116 * adjust the viewport in such a way that the whole line is displayed */
117 void view_cursor_to(View
*, size_t pos
);
118 /* create a new cursor */
119 Cursor
*view_cursors_new(View
*);
120 /* get number of active cursors */
121 int view_cursors_count(View
*);
122 /* dispose an existing cursor with its associated selection (if any),
123 * not applicaple for the last existing cursor */
124 void view_cursors_dispose(Cursor
*);
125 /* only keep the main cursor, release all others together with their
126 * selections (if any) */
127 void view_cursors_clear(View
*);
128 /* get the main cursor which is always in the visible viewport */
129 Cursor
*view_cursor(View
*);
130 /* get the first cursor */
131 Cursor
*view_cursors(View
*);
132 Cursor
*view_cursors_prev(Cursor
*);
133 Cursor
*view_cursors_next(Cursor
*);
134 /* get current position of cursor in bytes from the start of the file */
135 size_t view_cursors_pos(Cursor
*);
136 /* place cursor at `pos' which should be in the interval [0, text-size] */
137 void view_cursors_to(Cursor
*, size_t pos
);
138 void view_cursors_scroll_to(Cursor
*, size_t pos
);
139 /* get register associated with this register */
140 Register
*view_cursors_register(Cursor
*);
141 /* start selected area at current cursor position. further cursor movements
142 * will affect the selected region. */
143 void view_cursors_selection_start(Cursor
*);
144 /* detach cursor from selection, further cursor movements will not affect
145 * the selected region. */
146 void view_cursors_selection_stop(Cursor
*);
147 /* clear selection associated with this cursor (if any) */
148 void view_cursors_selection_clear(Cursor
*);
149 /* move cursor position from one end of the selection to the other */
150 void view_cursors_selection_swap(Cursor
*);
151 /* move cursor to the end/boundary of the associated selection */
152 void view_cursors_selection_sync(Cursor
*);
153 /* restore previous used selection of this cursor */
154 void view_cursors_selection_restore(Cursor
*);
155 /* get/set the selected region associated with this cursor */
156 Filerange
view_cursors_selection_get(Cursor
*);
157 void view_cursors_selection_set(Cursor
*, Filerange
*);
159 Selection
*view_selections_new(View
*);
160 void view_selections_free(Selection
*);
161 void view_selections_clear(View
*);
162 void view_selections_swap(Selection
*);
163 Selection
*view_selections(View
*);
164 Selection
*view_selections_prev(Selection
*);
165 Selection
*view_selections_next(Selection
*);
166 Filerange
view_selections_get(Selection
*);
167 void view_selections_set(Selection
*, Filerange
*);