2023-07-19 15:09:41 +00:00
|
|
|
/* date = July 11th 2023 0:34 pm */
|
|
|
|
|
|
|
|
#ifndef VN_WORKSPACE_TEXT_EDITOR_H
|
|
|
|
#define VN_WORKSPACE_TEXT_EDITOR_H
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: Mutable String Types
|
|
|
|
|
|
|
|
struct mutable_string
|
|
|
|
{
|
2023-10-29 10:00:34 +00:00
|
|
|
arena *Arena;
|
2023-07-19 15:09:41 +00:00
|
|
|
string String;
|
|
|
|
};
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: History & Undo Types
|
|
|
|
|
|
|
|
struct history_entry
|
2023-07-19 15:09:41 +00:00
|
|
|
{
|
|
|
|
range1_s64 Range;
|
|
|
|
string ReplaceString;
|
2023-07-24 13:50:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct history_node
|
|
|
|
{
|
2023-07-19 15:09:41 +00:00
|
|
|
history_node *Next;
|
2023-07-24 13:50:57 +00:00
|
|
|
history_node *Prev;
|
|
|
|
history_entry Forward;
|
|
|
|
history_entry Backward;
|
2023-07-19 15:09:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct history_list
|
|
|
|
{
|
2023-07-24 13:50:57 +00:00
|
|
|
history_node *At;
|
|
|
|
history_node Sentinel;
|
2023-07-19 15:09:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: Workspace Text Editor Types
|
|
|
|
|
|
|
|
struct workspace_text_data
|
|
|
|
{
|
|
|
|
token_array Tokens;
|
|
|
|
range1_s64_array Lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct workspace_view_text_editor
|
|
|
|
{
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: processed text
|
2023-10-29 10:00:34 +00:00
|
|
|
arena *ProcessingArena;
|
2023-07-19 15:09:41 +00:00
|
|
|
token_array Tokens;
|
|
|
|
range1_s64_array Lines;
|
2023-08-22 03:19:51 +00:00
|
|
|
compiled_scene Compiled;
|
2023-07-19 15:09:41 +00:00
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: text being edited
|
2023-08-06 10:35:09 +00:00
|
|
|
string FileName;
|
|
|
|
string FilePath;
|
2023-07-19 15:09:41 +00:00
|
|
|
mutable_string Text;
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: text editing
|
2023-07-19 15:09:41 +00:00
|
|
|
text_edit_state EditState;
|
|
|
|
text_point LastTextPoint;
|
|
|
|
|
2023-08-06 10:35:09 +00:00
|
|
|
// sixten: text rendering
|
|
|
|
r32 FontSize;
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: history
|
2023-10-29 10:00:34 +00:00
|
|
|
arena *HistoryArena;
|
2023-07-24 13:50:57 +00:00
|
|
|
history_list History;
|
2023-08-22 03:19:51 +00:00
|
|
|
history_node *SavePoint;
|
2023-07-24 13:50:57 +00:00
|
|
|
|
|
|
|
// sixten: ui building & rendering
|
2023-07-19 15:09:41 +00:00
|
|
|
ui_box *ContainerBox;
|
|
|
|
v2 TextDim;
|
|
|
|
v2 Offset;
|
2023-08-06 10:35:09 +00:00
|
|
|
b32 DropdownActive;
|
|
|
|
v2 DropdownP;
|
|
|
|
r32 DropdownTransition;
|
2023-07-19 15:09:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: Mutable String Functions
|
|
|
|
|
|
|
|
static mutable_string MutableStringAllocate(u64 Size);
|
|
|
|
static void MutableStringRelease(mutable_string *String);
|
|
|
|
static void MutableStringReplaceRange(mutable_string *String, string ReplaceString, range1_s64 Range);
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: History & Undo Functions
|
|
|
|
|
2023-10-29 10:00:34 +00:00
|
|
|
static history_entry HistoryEntry(arena *Arena, string ReplaceString, range1_s64 Range);
|
|
|
|
static void AppendToHistory(arena *Arena, history_list *List, history_entry Forward, history_entry Backward);
|
2023-07-24 13:50:57 +00:00
|
|
|
|
2023-07-19 15:09:41 +00:00
|
|
|
////////////////////////////////
|
2023-08-22 03:19:51 +00:00
|
|
|
//~ sixten: Workspace Text Editing Functions
|
2023-07-19 15:09:41 +00:00
|
|
|
|
2023-10-29 10:00:34 +00:00
|
|
|
static workspace_text_data W_TextDataFromString(arena *Arena, string Text);
|
2023-08-22 03:19:51 +00:00
|
|
|
static void W_TextEditorApplyChanges(workspace_view_text_editor *Editor);
|
|
|
|
static void W_SaveTextEditorToFile(workspace_view_text_editor *Editor);
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
//~ sixten: Workspace Text Editor Builder Functions
|
|
|
|
|
|
|
|
static UI_CUSTOM_DRAW_CALLBACK(W_TextEditorDrawCallback);
|
2023-12-07 15:50:57 +00:00
|
|
|
|
2023-08-22 03:19:51 +00:00
|
|
|
static b32 W_ProcessTextEditorEvent(workspace_view_text_editor *Editor, platform_event *Event);
|
|
|
|
static void W_BuildTextEditorInfoBar(workspace_view_text_editor *Editor);
|
|
|
|
static void W_BuildTextEditor(workspace_view *View);
|
2023-07-19 15:09:41 +00:00
|
|
|
|
|
|
|
#endif //VN_WORKSPACE_TEXT_EDITOR_H
|