Font size adjustment, toying with command windows and lua
This commit is contained in:
@@ -204,6 +204,19 @@ Range EncloseWord(Buffer &buffer, Int pos) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void ReloadFont(Int font_size) {
|
||||
if (MainFont.glyphs) {
|
||||
UnloadFont(MainFont);
|
||||
MainFont = {};
|
||||
}
|
||||
|
||||
FontSize = font_size;
|
||||
FontSpacing = 1;
|
||||
FontLineSpacing = FontSize;
|
||||
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
|
||||
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
|
||||
}
|
||||
|
||||
void HandleGlobalCommands() {
|
||||
Window *command_window = GetWindow(CommandWindowID);
|
||||
if (!IsActive(command_window)) {
|
||||
@@ -218,6 +231,15 @@ void HandleGlobalCommands() {
|
||||
command_window->visible = !command_window->visible;
|
||||
}
|
||||
|
||||
if (CtrlPress(KEY_MINUS)) {
|
||||
Int font_size = Clamp(FontSize - 1, (Int)4, (Int)100);
|
||||
ReloadFont(font_size);
|
||||
}
|
||||
if (CtrlPress(KEY_EQUAL)) {
|
||||
Int font_size = Clamp(FontSize + 1, (Int)4, (Int)100);
|
||||
ReloadFont(font_size);
|
||||
}
|
||||
|
||||
if (CtrlPress(KEY_ONE)) {
|
||||
SetActiveWindow({0});
|
||||
} else if (CtrlPress(KEY_TWO)) {
|
||||
|
||||
@@ -112,6 +112,18 @@ void Command_CreateCursorVertical(View *_view, int direction) {
|
||||
MergeCarets(*buffer, &view.carets);
|
||||
}
|
||||
|
||||
void Command_SelectRange(View *view, Range range) {
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
view->carets.len = 1;
|
||||
view->carets[0] = MakeCaret(range.min, range.max);
|
||||
}
|
||||
|
||||
void Command_SelectEntireBuffer(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
view->carets.len = 1;
|
||||
view->carets[0] = MakeCaret(0, buffer->len);
|
||||
}
|
||||
|
||||
int64_t FuzzyCloserWordBegin = 5;
|
||||
int64_t FuzzyConsecutiveMultiplier = 3;
|
||||
int64_t FuzzyRate(String16 string, String16 with) {
|
||||
@@ -266,8 +278,7 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
|
||||
bool dont_update_scroll = false;
|
||||
if (CtrlPress(KEY_A)) {
|
||||
view.carets.len = 1;
|
||||
view.carets[0] = MakeCaret(0, buffer->len);
|
||||
Command_SelectEntireBuffer(&view);
|
||||
dont_update_scroll = true;
|
||||
}
|
||||
|
||||
@@ -358,7 +369,11 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
String16 s = GetString(*buffer, l);
|
||||
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
|
||||
}
|
||||
ReplaceText(buffer, {0, buffer->len}, GetString(*temp_buffer));
|
||||
|
||||
Caret caret = view.carets[0];
|
||||
Command_SelectEntireBuffer(&view);
|
||||
Command_Replace(&view, GetString(*temp_buffer));
|
||||
view.carets[0] = caret;
|
||||
}
|
||||
|
||||
if (window->execute_line) {
|
||||
@@ -366,12 +381,36 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
Int line = PosToLine(*buffer, GetFront(view.carets[0]));
|
||||
Range range = GetLineRange(*buffer, line);
|
||||
String16 string = GetString(*buffer, range);
|
||||
EvalString(string);
|
||||
String16 eval_result = EvalString(string);
|
||||
|
||||
if (Ctrl()) {
|
||||
Command_SelectEntireBuffer(&view);
|
||||
Command_Replace(&view, eval_result);
|
||||
Command_SelectRange(&view, {});
|
||||
Command_Replace(&view, L"\n");
|
||||
Command_SelectRange(&view, {});
|
||||
} else {
|
||||
|
||||
if (window->id.id == CommandWindowID.id) {
|
||||
Window *command_window = GetWindow(CommandWindowID);
|
||||
command_window->visible = !command_window->visible;
|
||||
ActiveWindow = LastActiveWindow;
|
||||
}
|
||||
|
||||
{
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Command_Replace(view, eval_result);
|
||||
}
|
||||
|
||||
Int end_of_buffer = 0;
|
||||
Range range = GetLineRange(*buffer, 0, &end_of_buffer);
|
||||
range.max -= 1;
|
||||
range.max += end_of_buffer;
|
||||
Command_SelectRange(&view, range);
|
||||
Command_Replace(&view, {});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Press(KEY_ENTER)) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
lua_State *LuaState = NULL;
|
||||
String16 LuaCommandResult = {};
|
||||
|
||||
int LuaOpenFile(lua_State *L) {
|
||||
const char *text = luaL_checkstring(L, 1);
|
||||
@@ -8,50 +9,18 @@ int LuaOpenFile(lua_State *L) {
|
||||
return 0; // number of results
|
||||
}
|
||||
|
||||
// struct ResolvedSet {
|
||||
// Window *window;
|
||||
// View *view;
|
||||
// Buffer *buffer;
|
||||
// };
|
||||
|
||||
// ResolvedSet GetActiveWindow() {
|
||||
// if (ActiveWindow.id == CommandWindowID.id) {
|
||||
// Window *window = GetWindow(LastActiveWindow);
|
||||
// View *view = GetView(window->active_view);
|
||||
// SetActiveWindow(window->id);
|
||||
// Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
// return {window, view, buffer};
|
||||
// }
|
||||
|
||||
// Window *window = GetWindow(ActiveWindow);
|
||||
// View *view = GetView(window->active_view);
|
||||
// Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
// return {window, view, buffer};
|
||||
// }
|
||||
|
||||
int LuaListOpenBuffers(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Buffers) {
|
||||
String string = Format(scratch, "%.*s\n", FmtString(it.name));
|
||||
String string = Format(scratch, "open \"%.*s\"", FmtString(it.name));
|
||||
Add(&strings, ToString16(scratch, string));
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaListViews(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Views) {
|
||||
@@ -59,17 +28,11 @@ int LuaListViews(lua_State *L) {
|
||||
String string = Format(scratch, "view = %lld buffer = %lld name = %.*s", (long long)it.id.id, (long long)buffer->id.id, FmtString(buffer->name));
|
||||
Add(&strings, ToString16(scratch, string));
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaListWindows(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Windows) {
|
||||
@@ -84,8 +47,7 @@ int LuaListWindows(lua_State *L) {
|
||||
Add(&strings, ToString16(scratch, child_string));
|
||||
}
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,11 +75,14 @@ void SetInfoBarErrorMessage(String string) {
|
||||
if (string.len) InfoBarErrorMessage = Copy(sys, string);
|
||||
}
|
||||
|
||||
void EvalString(String16 string16) {
|
||||
// @todo: get result from lua?
|
||||
String16 EvalString(String16 string16) {
|
||||
Scratch scratch;
|
||||
LuaCommandResult = {};
|
||||
String string = ToString(scratch, string16);
|
||||
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
||||
const char *text = lua_tostring(LuaState, -1);
|
||||
SetInfoBarErrorMessage(text);
|
||||
}
|
||||
return LuaCommandResult;
|
||||
}
|
||||
@@ -74,12 +74,8 @@ int main(void) {
|
||||
|
||||
MenuFontSize = 19;
|
||||
MenuFont = LoadFontEx("c:\\Windows\\Fonts\\Segoeui.ttf", (int)MenuFontSize, NULL, 500);
|
||||
ReloadFont(16);
|
||||
|
||||
FontSize = 16;
|
||||
FontSpacing = 1;
|
||||
FontLineSpacing = FontSize;
|
||||
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
|
||||
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
|
||||
InitLua();
|
||||
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
@@ -148,7 +144,7 @@ int main(void) {
|
||||
FrameID += 1;
|
||||
|
||||
Rect2I screen_rect = GetScreenRect();
|
||||
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)MenuFontSize);
|
||||
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
|
||||
float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x;
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -109,7 +109,7 @@ WindowID LastActiveWindow;
|
||||
Int LastFrameIDWhenSwitchedActiveWindow;
|
||||
String InfoBarErrorMessage;
|
||||
|
||||
void EvalString(String16 string16);
|
||||
String16 EvalString(String16 string16);
|
||||
Rect2I GetVisibleCells(Window &window);
|
||||
void AfterEdit(View *view, Array<Edit> edits);
|
||||
Scroller ComputeScrollerRect(Window &window);
|
||||
|
||||
Reference in New Issue
Block a user