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;
|
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() {
|
void HandleGlobalCommands() {
|
||||||
Window *command_window = GetWindow(CommandWindowID);
|
Window *command_window = GetWindow(CommandWindowID);
|
||||||
if (!IsActive(command_window)) {
|
if (!IsActive(command_window)) {
|
||||||
@@ -218,6 +231,15 @@ void HandleGlobalCommands() {
|
|||||||
command_window->visible = !command_window->visible;
|
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)) {
|
if (CtrlPress(KEY_ONE)) {
|
||||||
SetActiveWindow({0});
|
SetActiveWindow({0});
|
||||||
} else if (CtrlPress(KEY_TWO)) {
|
} else if (CtrlPress(KEY_TWO)) {
|
||||||
|
|||||||
@@ -112,6 +112,18 @@ void Command_CreateCursorVertical(View *_view, int direction) {
|
|||||||
MergeCarets(*buffer, &view.carets);
|
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 FuzzyCloserWordBegin = 5;
|
||||||
int64_t FuzzyConsecutiveMultiplier = 3;
|
int64_t FuzzyConsecutiveMultiplier = 3;
|
||||||
int64_t FuzzyRate(String16 string, String16 with) {
|
int64_t FuzzyRate(String16 string, String16 with) {
|
||||||
@@ -266,8 +278,7 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
|
|
||||||
bool dont_update_scroll = false;
|
bool dont_update_scroll = false;
|
||||||
if (CtrlPress(KEY_A)) {
|
if (CtrlPress(KEY_A)) {
|
||||||
view.carets.len = 1;
|
Command_SelectEntireBuffer(&view);
|
||||||
view.carets[0] = MakeCaret(0, buffer->len);
|
|
||||||
dont_update_scroll = true;
|
dont_update_scroll = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +369,11 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
String16 s = GetString(*buffer, l);
|
String16 s = GetString(*buffer, l);
|
||||||
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
|
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) {
|
if (window->execute_line) {
|
||||||
@@ -366,12 +381,36 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
Int line = PosToLine(*buffer, GetFront(view.carets[0]));
|
Int line = PosToLine(*buffer, GetFront(view.carets[0]));
|
||||||
Range range = GetLineRange(*buffer, line);
|
Range range = GetLineRange(*buffer, line);
|
||||||
String16 string = GetString(*buffer, range);
|
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) {
|
if (window->id.id == CommandWindowID.id) {
|
||||||
Window *command_window = GetWindow(CommandWindowID);
|
Window *command_window = GetWindow(CommandWindowID);
|
||||||
command_window->visible = !command_window->visible;
|
command_window->visible = !command_window->visible;
|
||||||
ActiveWindow = LastActiveWindow;
|
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 {
|
} else {
|
||||||
if (Press(KEY_ENTER)) {
|
if (Press(KEY_ENTER)) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
lua_State *LuaState = NULL;
|
lua_State *LuaState = NULL;
|
||||||
|
String16 LuaCommandResult = {};
|
||||||
|
|
||||||
int LuaOpenFile(lua_State *L) {
|
int LuaOpenFile(lua_State *L) {
|
||||||
const char *text = luaL_checkstring(L, 1);
|
const char *text = luaL_checkstring(L, 1);
|
||||||
@@ -8,50 +9,18 @@ int LuaOpenFile(lua_State *L) {
|
|||||||
return 0; // number of results
|
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) {
|
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;
|
Scratch scratch;
|
||||||
Array<String16> strings = {scratch};
|
Array<String16> strings = {scratch};
|
||||||
For(Buffers) {
|
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));
|
Add(&strings, ToString16(scratch, string));
|
||||||
}
|
}
|
||||||
String16 string = Merge(scratch, strings, L"\n");
|
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||||
Command_Replace(view, string);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaListViews(lua_State *L) {
|
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;
|
Scratch scratch;
|
||||||
Array<String16> strings = {scratch};
|
Array<String16> strings = {scratch};
|
||||||
For(Views) {
|
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));
|
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));
|
Add(&strings, ToString16(scratch, string));
|
||||||
}
|
}
|
||||||
String16 string = Merge(scratch, strings, L"\n");
|
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||||
Command_Replace(view, string);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaListWindows(lua_State *L) {
|
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;
|
Scratch scratch;
|
||||||
Array<String16> strings = {scratch};
|
Array<String16> strings = {scratch};
|
||||||
For(Windows) {
|
For(Windows) {
|
||||||
@@ -84,8 +47,7 @@ int LuaListWindows(lua_State *L) {
|
|||||||
Add(&strings, ToString16(scratch, child_string));
|
Add(&strings, ToString16(scratch, child_string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String16 string = Merge(scratch, strings, L"\n");
|
LuaCommandResult = Merge(scratch, strings, L"\n");
|
||||||
Command_Replace(view, string);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,11 +75,14 @@ void SetInfoBarErrorMessage(String string) {
|
|||||||
if (string.len) InfoBarErrorMessage = Copy(sys, string);
|
if (string.len) InfoBarErrorMessage = Copy(sys, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalString(String16 string16) {
|
// @todo: get result from lua?
|
||||||
|
String16 EvalString(String16 string16) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
|
LuaCommandResult = {};
|
||||||
String string = ToString(scratch, string16);
|
String string = ToString(scratch, string16);
|
||||||
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
||||||
const char *text = lua_tostring(LuaState, -1);
|
const char *text = lua_tostring(LuaState, -1);
|
||||||
SetInfoBarErrorMessage(text);
|
SetInfoBarErrorMessage(text);
|
||||||
}
|
}
|
||||||
|
return LuaCommandResult;
|
||||||
}
|
}
|
||||||
@@ -74,12 +74,8 @@ int main(void) {
|
|||||||
|
|
||||||
MenuFontSize = 19;
|
MenuFontSize = 19;
|
||||||
MenuFont = LoadFontEx("c:\\Windows\\Fonts\\Segoeui.ttf", (int)MenuFontSize, NULL, 500);
|
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();
|
InitLua();
|
||||||
|
|
||||||
Allocator sys_allocator = GetSystemAllocator();
|
Allocator sys_allocator = GetSystemAllocator();
|
||||||
@@ -148,7 +144,7 @@ int main(void) {
|
|||||||
FrameID += 1;
|
FrameID += 1;
|
||||||
|
|
||||||
Rect2I screen_rect = GetScreenRect();
|
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;
|
float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x;
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ WindowID LastActiveWindow;
|
|||||||
Int LastFrameIDWhenSwitchedActiveWindow;
|
Int LastFrameIDWhenSwitchedActiveWindow;
|
||||||
String InfoBarErrorMessage;
|
String InfoBarErrorMessage;
|
||||||
|
|
||||||
void EvalString(String16 string16);
|
String16 EvalString(String16 string16);
|
||||||
Rect2I GetVisibleCells(Window &window);
|
Rect2I GetVisibleCells(Window &window);
|
||||||
void AfterEdit(View *view, Array<Edit> edits);
|
void AfterEdit(View *view, Array<Edit> edits);
|
||||||
Scroller ComputeScrollerRect(Window &window);
|
Scroller ComputeScrollerRect(Window &window);
|
||||||
|
|||||||
Reference in New Issue
Block a user