Files
text_editor/src/text_editor/text_editor.h

108 lines
2.4 KiB
C

// clang-format off
struct BufferID { Int id; };
struct ViewID { Int id; };
struct WindowID { Int id; };
union Range { struct { Int min; Int max; }; Int e[2]; };
struct Caret { union { Range range; Int pos[2]; }; Int ifront;};
struct XY { Int col; Int line; };
// clang-format on
struct Edit {
Range range;
String16 string;
};
// @idea: maybe redo tree?
struct HistoryEntry {
Array<Edit> edits;
Array<Caret> carets;
};
// @todo: gap buffer to improve speed of inserting on big files with only one cursor?
struct Buffer {
BufferID id;
String name;
union {
U16 *data;
wchar_t *str;
};
Int len;
Int cap;
Array<Int> line_starts;
Array<HistoryEntry> undo_stack;
Array<HistoryEntry> redo_stack;
int debug_edit_phase;
bool no_history;
};
struct View {
ViewID id;
BufferID active_buffer;
Vec2I scroll;
Int caret_change_id; // @debug
Array<Caret> carets;
// window | view
Range selection_anchor;
Caret main_caret_on_begin_frame;
};
struct Window {
WindowID id;
ViewID active_view;
Array<ViewID> views;
Rect2I total_rect;
Rect2I scrollbar_rect;
Rect2I line_numbers_rect;
Rect2I document_rect;
double mouse_scroller_offset;
int z;
struct {
bool mouse_selecting_scrollbar : 1;
bool mouse_selecting : 1;
bool draw_scrollbar : 1;
bool draw_line_numbers : 1;
bool visible : 1;
bool fuzzy_search : 1;
bool execute_line : 1;
bool invisible_when_inactive : 1;
bool dont_save_in_active_window_history : 1;
bool deactivate_on_escape : 1;
};
};
struct Scroller {
Rect2 rect;
double begin;
double end;
Int line_count;
};
float MenuFontSize;
Font MenuFont;
Font MainFont;
Int FontSize;
Int FontSpacing;
Int FontLineSpacing;
Int FontCharSpacing;
Int FrameID;
String WorkingDir;
String16 EvalString(Allocator allocator, String16 string16);
Rect2I GetVisibleCells(Window &window);
void AfterEdit(View *view, Array<Edit> edits);
Scroller ComputeScrollerRect(Window &window);
void Command_EvalLua(View *view, String16 string);
void MergeCarets(View *view, Range *mouse_selection_anchor = NULL);
inline BufferID AllocBufferID();