Only one infobar

This commit is contained in:
Krzosa Karol
2024-07-23 17:14:11 +02:00
parent 5864b060a9
commit 4cb892133f
7 changed files with 37 additions and 40 deletions

View File

@@ -205,14 +205,17 @@ Range EncloseWord(Buffer &buffer, Int pos) {
}
void HandleGlobalCommands() {
Window *command_window = GetWindow(CommandWindowID);
if (!IsActive(command_window)) {
command_window->visible = false;
}
if (CtrlPress(KEY_P)) {
Window *window = GetWindow(CommandWindowID);
if (window->visible) {
if (command_window->visible) {
SetActiveWindow(LastActiveWindow);
} else {
SetActiveWindow(window->id);
SetActiveWindow(command_window->id);
}
window->visible = !window->visible;
command_window->visible = !command_window->visible;
}
if (CtrlPress(KEY_ONE)) {

View File

@@ -276,7 +276,7 @@ void HandleActiveWindowBindings(Window *window) {
Range range = GetLineRange(*buffer, line);
String16 string = GetString(*buffer, range);
EvalString(string);
} else if (window->banish_new_lines == false && Press(KEY_ENTER)) {
} else if (Press(KEY_ENTER)) {
Command_Replace(&view, L"\n");
}

View File

@@ -5,7 +5,7 @@ int LuaOpenFile(lua_State *L) {
String string = text;
Buffer *buffer = OpenFile(string);
View *view = CreateView(buffer->id);
Window *window = GetWindow({1});
Window *window = GetWindow(LastActiveWindow);
AddView(window, view->id);
window->active_view = view->id;
SetActiveWindow(window->id);
@@ -27,6 +27,6 @@ void EvalString(String16 string16) {
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
// @todo:
const char *text = lua_tostring(LuaState, -1);
printf("lua error: %s", text);
printf("lua error: %s\n", text);
}
}

View File

@@ -29,8 +29,8 @@
#include "lua_api.cpp"
/*
- Open file (utf8->utf16), process determine line endings, tabs to spaces?, Save file (utf16->utf8)
- line endings
- Save file (utf16->utf8)
- reuse buffers!!
- resize windows
- command window
- maybe use lua and have there be lua commands that you choose with cursor
@@ -40,8 +40,6 @@
- We can actually combine this with command window and lua, it's just going to be a buffer of
- open "asd/asd/asd/asd"
- Make only one infobar!!
- Ctrl + F
- word completion
@@ -120,7 +118,6 @@ int main(void) {
Window *w = CreateWindow();
w->draw_scrollbar = false;
w->draw_line_numbers = false;
w->draw_infobar = false;
w->visible = false;
Buffer *b = CreateBuffer(sys_allocator);
View *v = CreateView(b->id);
@@ -134,13 +131,13 @@ int main(void) {
FrameID += 1;
Rect2I screen_rect = GetScreenRect();
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)MenuFontSize);
float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x;
{
int i = 1;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
@@ -148,7 +145,6 @@ int main(void) {
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
@@ -156,7 +152,6 @@ int main(void) {
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_infobar) Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
@@ -186,6 +181,23 @@ int main(void) {
DrawWindow(window);
}
SetMouseCursor();
{
Rect2I r = infobar_rect;
DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground);
{
Window *window = GetActiveWindow();
View *view = GetActiveView(window);
Buffer *buffer = GetBuffer(view->buffer_id);
Vec2 p = ToVec2(r.min);
Scratch scratch;
Caret caret = view->carets[0];
XY xy = PosToXY(*buffer, GetFront(caret));
String s = Format(scratch, "-- line: %lld col: %lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll);
String16 string = ToString16(scratch, s);
DrawString(MenuFont, string, p, MenuFontSize, 1, ColorText);
}
}
EndDrawing();
}
CloseWindow();

View File

@@ -50,7 +50,6 @@ struct Window {
Rect2I total_rect;
Rect2I scrollbar_rect;
Rect2I infobar_rect;
Rect2I line_numbers_rect;
Rect2I document_rect;
@@ -62,9 +61,7 @@ struct Window {
bool mouse_selecting : 1;
bool draw_scrollbar : 1;
bool draw_line_numbers : 1;
bool draw_infobar : 1;
bool visible : 1;
bool banish_new_lines : 1; // @todo: custom new line handler? custom vertical handler! (choosing options with cursor)
};
};
@@ -75,10 +72,6 @@ struct Scroller {
Int line_count;
};
Rect2I GetVisibleCells(Window &window);
void AfterEdit(View *view, Array<Edit> edits);
Scroller ComputeScrollerRect(Window &window);
WindowID WindowIDs = {0};
BufferID BufferIDs = {0};
ViewID ViewIDs = {0};
@@ -136,3 +129,6 @@ inline View *GetActiveView(Window *window) {
}
void EvalString(String16 string16);
Rect2I GetVisibleCells(Window &window);
void AfterEdit(View *view, Array<Edit> edits);
Scroller ComputeScrollerRect(Window &window);

View File

@@ -3,7 +3,6 @@ Window *CreateWindow() {
w->visible = true;
w->draw_scrollbar = true;
w->draw_line_numbers = true;
w->draw_infobar = true;
w->id = AllocWindowID();
return w;
}
@@ -49,7 +48,9 @@ Array<Int> GetWindowZOrder(Allocator allocator) {
void SetActiveWindow(WindowID window) {
if (LastFrameIDWhenSwitchedActiveWindow != FrameID) {
if (ActiveWindow.id != CommandWindowID.id) {
LastActiveWindow = ActiveWindow;
}
ActiveWindow = window;
LastFrameIDWhenSwitchedActiveWindow = FrameID;
}

View File

@@ -214,21 +214,6 @@ void DrawWindow(Window &window) {
EndScissorMode();
}
// Draw info bar
if (window.draw_infobar) {
Rect2I r = window.infobar_rect;
DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground);
{
Vec2 p = ToVec2(r.min);
Scratch scratch;
Caret caret = view.carets[0];
XY xy = PosToXY(*buffer, GetFront(caret));
String s = Format(scratch, "-- line: %lld col: %lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll);
String16 string = ToString16(scratch, s);
DrawString(MenuFont, string, p, MenuFontSize, 1, ColorText);
}
}
if (!IsActive(&window)) {
DrawRectangleRec(ToRectangle(window.total_rect), {0, 0, 0, 30});
}