RegisterVariable

This commit is contained in:
Krzosa Karol
2025-12-20 11:37:02 +01:00
parent bb9809b956
commit f637352669
4 changed files with 114 additions and 110 deletions

View File

@@ -102,6 +102,7 @@ using S32 = int32_t;
using S64 = int64_t; using S64 = int64_t;
using Int = S64; using Int = S64;
using UInt = U64; using UInt = U64;
using Float = double;
template <class T> template <class T>
T Min(T a, T b) { T Min(T a, T b) {

View File

@@ -77,6 +77,12 @@ String Intern(InternTable *table, String string) {
// optimize worst offenders (like event text) // optimize worst offenders (like event text)
InternTable GlobalInternTable; InternTable GlobalInternTable;
bool SkipRemainingCommands;
Array<CommandData> CommandFunctions;
Array<LuaFunctionData> LuaFunctions;
Array<FunctionData> TestFunctions;
Array<Variable> Variables;
/////////////////////////////// ///////////////////////////////
// CONFIG // CONFIG
Color GruvboxDark0Hard = {0x1d, 0x20, 0x21, 0xff}; Color GruvboxDark0Hard = {0x1d, 0x20, 0x21, 0xff};
@@ -116,109 +122,34 @@ Color GruvboxFadedBlue = {0x07, 0x66, 0x78, 0xff};
Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff}; Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff};
Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff}; Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff};
Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff}; Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff};
Color ColorText = GruvboxDark0Hard; RegisterVariable(Color, ColorText, GruvboxDark0Hard);
Color ColorLoadTextHighlight = {0x00, 0x00, 0x00, 0x0F}; RegisterVariable(Color, ColorLoadTextHighlight, {0x00, 0x00, 0x00, 0x0F});
Color ColorBackground = GruvboxLight0Hard; RegisterVariable(Color, ColorBackground, GruvboxLight0Hard);
Color ColorInactiveWindow = {0x00, 0x00, 0x00, 0x0F}; RegisterVariable(Color, ColorInactiveWindow, {0x00, 0x00, 0x00, 0x0F});
Color ColorTextLineNumbers = GruvboxDark4; RegisterVariable(Color, ColorTextLineNumbers, GruvboxDark4);
Color ColorLineHighlight = GruvboxLight0Soft; RegisterVariable(Color, ColorLineHighlight, GruvboxLight0Soft);
Color ColorMainCaret = GruvboxDark0Hard; RegisterVariable(Color, ColorMainCaret, GruvboxDark0Hard);
Color ColorSubCaret = GruvboxGray245; RegisterVariable(Color, ColorSubCaret, GruvboxGray245);
Color ColorSelection = GruvboxLight1; RegisterVariable(Color, ColorSelection, GruvboxLight1);
Color ColorWhitespaceDuringSelection = GruvboxLight4; RegisterVariable(Color, ColorWhitespaceDuringSelection, GruvboxLight4);
Color ColorMouseUnderline = GruvboxDark0Hard; RegisterVariable(Color, ColorMouseUnderline, GruvboxDark0Hard);
Color ColorCaretUnderline = GruvboxGray245; RegisterVariable(Color, ColorCaretUnderline, GruvboxGray245);
Color ColorFuzzySearchLineHighlight = GruvboxDark0; RegisterVariable(Color, ColorFuzzySearchLineHighlight, GruvboxDark0);
Color ColorScrollbarBackground = GruvboxLight2; RegisterVariable(Color, ColorScrollbarBackground, GruvboxLight2);
Color ColorScrollbarScroller = GruvboxLight1; RegisterVariable(Color, ColorScrollbarScroller, GruvboxLight1);
Color ColorScrollbarScrollerSelected = GruvboxLight0Hard; RegisterVariable(Color, ColorScrollbarScrollerSelected, GruvboxLight0Hard);
Color ColorTitleBarText = GruvboxDark2; RegisterVariable(Color, ColorTitleBarText, GruvboxDark2);
Color ColorTitleBarBackground = GruvboxLight1; RegisterVariable(Color, ColorTitleBarBackground, GruvboxLight1);
Color ColorTitleBarActiveBackground = {0xfe, 0xfe, 0xfe, 0xfe}; RegisterVariable(Color, ColorTitleBarActiveBackground, {0xfe, 0xfe, 0xfe, 0xfe});
Color ColorTitleBarSelection = GruvboxLight3; RegisterVariable(Color, ColorTitleBarSelection, GruvboxLight3);
Color ColorResizerBackground = GruvboxLight0Hard; RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard);
Color ColorResizerOutline = GruvboxLight3; RegisterVariable(Color, ColorResizerOutline, GruvboxLight3);
Int StyleWaitForEvents = 1; RegisterVariable(Int, StyleWaitForEvents, 1);
Int StyleDrawLineNumbers = 1; RegisterVariable(Int, StyleDrawLineNumbers, 1);
Int StyleDrawScrollbar = 1; RegisterVariable(Int, StyleDrawScrollbar, 1);
Int StyleIndentSize = 4; RegisterVariable(Int, StyleIndentSize, 4);
Int StyleFontSize = 15; RegisterVariable(Int, StyleFontSize, 15);
Int StyleFontFilter = 0; RegisterVariable(Int, StyleFontFilter, 0);
String StyleFont = "/home/krz/text_editor/package/CascadiaMono.ttf"; RegisterVariable(String, StyleFont, "/home/krz/text_editor/package/CascadiaMono.ttf");
String StyleVCVarsall = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"; RegisterVariable(String, StyleVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
double StyleUndoMergeTimeout = 0.3; RegisterVariable(Float, StyleUndoMergeTimeout, 0.3);
void ReloadStyle() {
ColorText = GetColor("Text", ColorText);
ColorLoadTextHighlight = GetColor("LoadTextHighlight", ColorLoadTextHighlight);
ColorBackground = GetColor("Background", ColorBackground);
ColorInactiveWindow = GetColor("InactiveWindow", ColorInactiveWindow);
ColorTextLineNumbers = GetColor("TextLineNumbers", ColorTextLineNumbers);
ColorLineHighlight = GetColor("LineHighlight", ColorLineHighlight);
ColorMainCaret = GetColor("MainCaret", ColorMainCaret);
ColorSubCaret = GetColor("SubCaret", ColorSubCaret);
ColorSelection = GetColor("Selection", ColorSelection);
ColorWhitespaceDuringSelection = GetColor("WhitespaceDuringSelection", ColorWhitespaceDuringSelection);
ColorMouseUnderline = GetColor("MouseUnderline", ColorMouseUnderline);
ColorCaretUnderline = GetColor("CaretUnderline", ColorCaretUnderline);
ColorFuzzySearchLineHighlight = GetColor("FuzzySearchLineHighlight", ColorFuzzySearchLineHighlight);
ColorScrollbarBackground = GetColor("ScrollbarBackground", ColorScrollbarBackground);
ColorScrollbarScroller = GetColor("ScrollbarScroller", ColorScrollbarScroller);
ColorScrollbarScrollerSelected = GetColor("ScrollbarScrollerSelected", ColorScrollbarScrollerSelected);
ColorTitleBarText = GetColor("TitleBarText", ColorTitleBarText);
ColorTitleBarBackground = GetColor("TitleBarBackground", ColorTitleBarBackground);
ColorTitleBarActiveBackground = GetColor("TitleBarActiveBackground", ColorTitleBarActiveBackground);
ColorTitleBarSelection = GetColor("TitleBarSelection", ColorTitleBarSelection);
ColorResizerBackground = GetColor("ResizerBackground", ColorResizerBackground);
ColorResizerOutline = GetColor("ResizerOutline", ColorResizerOutline);
StyleWaitForEvents = GetStyleInt("WaitForEvents", StyleWaitForEvents);
StyleDrawLineNumbers = GetStyleInt("DrawLineNumbers", StyleDrawLineNumbers);
StyleDrawScrollbar = GetStyleInt("DrawScrollbar", StyleDrawScrollbar);
StyleIndentSize = GetStyleInt("IndentSize", StyleIndentSize);
StyleFontSize = GetStyleInt("FontSize", StyleFontSize);
StyleFontFilter = GetStyleInt("FontFilter", StyleFontFilter);
StyleFont = GetStyleString("Font", StyleFont);
StyleVCVarsall = GetStyleString("VCVarsall", StyleVCVarsall);
StyleUndoMergeTimeout = GetStyleFloat("UndoMergeTimeout", StyleUndoMergeTimeout);
}
typedef void Function();
typedef void PFunction(void *param);
typedef int LuaFunction(lua_State *state);
struct FunctionData { String name; Function *function; };
struct LuaFunctionData { String name; LuaFunction *function; };
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
struct PFunctionData { String name; PFunction *function; };
bool SkipRemainingCommands;
Array<CommandData> CommandFunctions;
Array<LuaFunctionData> LuaFunctions;
Array<FunctionData> TestFunctions;
struct Register_Function {
Register_Function(Array<FunctionData> *functions, String name, Function *f) {
int64_t pos = 0;
if (Seek(name, "_", &pos, 0)) {
name = Skip(name, pos + 1);
}
Add(functions, {name, f});
}
};
#define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name)
struct Register_Lua { Register_Lua(LuaFunction *function, String name) { if (StartsWith(name, "Lua_")) name = Skip(name, 4); Add(&LuaFunctions, {name, function}); } };
#define RegisterLua(NAME) Register_Lua RL_##NAME(NAME, #NAME)
struct Register_Command { Register_Command(Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(&CommandFunctions, {name, binding, function}); } };
#define RegisterCommand(name, binding) Register_Command RC__##name(name, #name, binding)
struct Register_Hook { Register_Hook(Array<PFunctionData> *functions, PFunction *function, String name) { if (StartsWith(name, "Hook_")) name = Skip(name, 5); Add(functions, {name, function}); } };
#define RegisterHook(functions, name) Register_Hook RC__##name(functions, (PFunction *)name, #name)
const int DIR_RIGHT = 0;
const int DIR_LEFT = 1;
const int DIR_DOWN = 2;
const int DIR_UP = 3;
const int DIR_COUNT = 4;
const bool CTRL_PRESSED = true;
const bool SHIFT_PRESS = true;

View File

@@ -86,7 +86,6 @@ API String GetFieldString(lua_State *L, String name) {
return result; return result;
} }
void ReloadStyle();
extern String BaseLuaConfig; extern String BaseLuaConfig;
API void LoadLuaBuffer(Buffer *lua_buffer) { API void LoadLuaBuffer(Buffer *lua_buffer) {
@@ -123,7 +122,13 @@ API void ReloadLuaConfigs(bool reload) {
LoadLuaBuffer(LuaConfigBuffer); LoadLuaBuffer(LuaConfigBuffer);
LoadLuaBuffer(LuaProjectBuffer); LoadLuaBuffer(LuaProjectBuffer);
ReloadStyle(); For (Variables) {
if (it.type == VariableType_Color) it.color[0] = GetColor(Skip(it.name, 5), it.color[0]);
else if (it.type == VariableType_Int) it.i[0] = GetStyleInt(Skip(it.name, 5), it.i[0]);
else if (it.type == VariableType_String) it.string[0] = GetStyleString(Skip(it.name, 5), it.string[0]);
else if (it.type == VariableType_Float) it.f[0] = GetStyleFloat(Skip(it.name, 5), it.f[0]);
else Assert(!"Invalid codepath");
}
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(StyleFont, (U32)StyleFontSize);
For(Windows) { For(Windows) {
it->draw_scrollbar = StyleDrawScrollbar; it->draw_scrollbar = StyleDrawScrollbar;
@@ -227,7 +232,6 @@ OnOpenResult CallOnOpen(Allocator allocator, String path, String meta) {
result.working_dir = working_dir; result.working_dir = working_dir;
result.file_path = file_path; result.file_path = file_path;
if (!IsAbsolute(result.file_path)) { if (!IsAbsolute(result.file_path)) {
String GetMainDir();
String dir = GetMainDir(); String dir = GetMainDir();
result.file_path = Format(allocator, "%S/%S", dir, result.file_path); result.file_path = Format(allocator, "%S/%S", dir, result.file_path);
} }

View File

@@ -75,6 +75,7 @@ Scroller ComputeScrollerRect(Window *window);
BSet Open(String path, String meta = ""); BSet Open(String path, String meta = "");
BSet Open(String16 path, String meta = ""); BSet Open(String16 path, String meta = "");
void UpdateScroll(Window *window, bool update_caret_scrolling); void UpdateScroll(Window *window, bool update_caret_scrolling);
String GetMainDir();
void SelectEntireBuffer(View *view); void SelectEntireBuffer(View *view);
void Replace(View *view, String16 string); void Replace(View *view, String16 string);
@@ -121,3 +122,70 @@ Buffer *BufferOpenFile(String path);
#else #else
#define IF_DEBUG(x) #define IF_DEBUG(x)
#endif #endif
typedef void Function();
typedef void PFunction(void *param);
typedef int LuaFunction(lua_State *state);
struct FunctionData { String name; Function *function; };
struct LuaFunctionData { String name; LuaFunction *function; };
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
struct PFunctionData { String name; PFunction *function; };
struct Register_Function {
Register_Function(Array<FunctionData> *functions, String name, Function *f) {
int64_t pos = 0;
if (Seek(name, "_", &pos, 0)) {
name = Skip(name, pos + 1);
}
Add(functions, {name, f});
}
};
#define RegisterFunction(functions, name) Register_Function RF__##name(functions, #name, name)
struct Register_Lua { Register_Lua(Array<LuaFunctionData> *funcs, LuaFunction *function, String name) { if (StartsWith(name, "Lua_")) name = Skip(name, 4); Add(funcs, {name, function}); } };
#define RegisterLua(NAME) Register_Lua RL_##NAME(&LuaFunctions, NAME, #NAME)
struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(fucs, {name, binding, function}); } };
#define RegisterCommand(name, binding) Register_Command RC__##name(&CommandFunctions, name, #name, binding)
struct Register_Hook { Register_Hook(Array<PFunctionData> *functions, PFunction *function, String name) { if (StartsWith(name, "Hook_")) name = Skip(name, 5); Add(functions, {name, function}); } };
#define RegisterHook(functions, name) Register_Hook RC__##name(functions, (PFunction *)name, #name)
const int DIR_RIGHT = 0;
const int DIR_LEFT = 1;
const int DIR_DOWN = 2;
const int DIR_UP = 3;
const int DIR_COUNT = 4;
const bool CTRL_PRESSED = true;
const bool SHIFT_PRESS = true;
enum VariableType {
VariableType_Invalid,
VariableType_Color,
VariableType_String,
VariableType_Int,
VariableType_Float,
};
struct Variable {
VariableType type;
String name;
union {
void *addr;
Color *color;
Int *i;
double *f;
String *string;
};
};
struct Register_Variable {
Register_Variable(Array<Variable> *variables, VariableType type, String name, void *addr) {
Add(variables, {type, name, addr});
}
};
#define RegisterVariable(type, name, ...) \
type name = __VA_ARGS__; \
Register_Variable var_##name(&Variables, VariableType_##type, #name, &name)