Improve alignment of infobar, set buffer name in window title
This commit is contained in:
@@ -288,7 +288,7 @@ function GenericTextFileRule(_s)
|
|||||||
|
|
||||||
line, col, _s = match_line_col(_s)
|
line, col, _s = match_line_col(_s)
|
||||||
file_path = match_path(_s)
|
file_path = match_path(_s)
|
||||||
return {kind = "open_textfile", file_path = file_path, line = line, col = col}
|
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -346,10 +346,6 @@ void DrawCircle(Vec2 pos, float radius, Color color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 GetStringSize(Font *font, String16 string) {
|
|
||||||
return DrawString(font, string, {}, {}, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Int GetCharSpacing(Font *font, int codepoint = '_') {
|
Int GetCharSpacing(Font *font, int codepoint = '_') {
|
||||||
Glyph *g = GetGlyph(font, codepoint);
|
Glyph *g = GetGlyph(font, codepoint);
|
||||||
if (g->xadvance) return (Int)g->xadvance;
|
if (g->xadvance) return (Int)g->xadvance;
|
||||||
|
|||||||
@@ -292,10 +292,7 @@ void ReplaceInfobarData() {
|
|||||||
ReplaceText(buffer, GetEndAsRange(*buffer), L" |");
|
ReplaceText(buffer, GetEndAsRange(*buffer), L" |");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *dirty = "";
|
String s = Format(scratch, "Line %lld Column %lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll);
|
||||||
if (last_buffer->dirty) dirty = "!";
|
|
||||||
|
|
||||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s%s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), dirty);
|
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
ReplaceText(buffer, replace_range, string);
|
ReplaceText(buffer, replace_range, string);
|
||||||
Command_SelectRangeOneCursor(view, {});
|
Command_SelectRangeOneCursor(view, {});
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ function GenericTextFileRule(_s)
|
|||||||
|
|
||||||
line, col, _s = match_line_col(_s)
|
line, col, _s = match_line_col(_s)
|
||||||
file_path = match_path(_s)
|
file_path = match_path(_s)
|
||||||
return {kind = "open_textfile", file_path = file_path, line = line, col = col}
|
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,7 @@ int LuaOpen(lua_State *L) {
|
|||||||
UpdateScroll(window, true);
|
UpdateScroll(window, true);
|
||||||
SetActiveWindow(window->id);
|
SetActiveWindow(window->id);
|
||||||
} else {
|
} else {
|
||||||
// Window *window = GetWindow(GetLastActiveWindow());
|
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||||
// View *view = ViewOpenFile(window, path);
|
|
||||||
// SetActiveWindow(window->id);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,22 +142,22 @@ int main()
|
|||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||||
SDL_Window *window = SDL_CreateWindow("Text editor", 1280, 720, window_flags);
|
SDL_Window *sdl_window = SDL_CreateWindow("Text editor", 1280, 720, window_flags);
|
||||||
if (window == NULL) {
|
if (sdl_window == NULL) {
|
||||||
ReportErrorf("Couldn't create window! %s", SDL_GetError());
|
ReportErrorf("Couldn't create window! %s", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window);
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(sdl_window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(sdl_window);
|
||||||
|
|
||||||
// Set icon
|
// Set icon
|
||||||
{
|
{
|
||||||
uint32_t data = 0xddddddff;
|
uint32_t data = 0xddddddff;
|
||||||
SDL_Surface *surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, &data, sizeof(uint32_t));
|
SDL_Surface *surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, &data, sizeof(uint32_t));
|
||||||
SDL_SetWindowIcon(window, surface);
|
SDL_SetWindowIcon(sdl_window, surface);
|
||||||
SDL_DestroySurface(surface);
|
SDL_DestroySurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +166,10 @@ int main()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_StartTextInput(window);
|
SDL_StartTextInput(sdl_window);
|
||||||
SDL_GL_SetSwapInterval(1); // vsync
|
SDL_GL_SetSwapInterval(1); // vsync
|
||||||
{
|
{
|
||||||
float scale = SDL_GetWindowDisplayScale(window);
|
float scale = SDL_GetWindowDisplayScale(sdl_window);
|
||||||
if (scale != 1.0f) DPIScale = scale;
|
if (scale != 1.0f) DPIScale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ int main()
|
|||||||
WaitForEvents = true;
|
WaitForEvents = true;
|
||||||
|
|
||||||
int window_x, window_y;
|
int window_x, window_y;
|
||||||
SDL_GetWindowSize(window, &window_x, &window_y);
|
SDL_GetWindowSize(sdl_window, &window_x, &window_y);
|
||||||
WindowSize = {(float)window_x, (float)window_y};
|
WindowSize = {(float)window_x, (float)window_y};
|
||||||
BeginFrameRender();
|
BeginFrameRender();
|
||||||
LayoutWindows();
|
LayoutWindows();
|
||||||
@@ -265,6 +265,14 @@ int main()
|
|||||||
HandleEvent(event);
|
HandleEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Window *window = GetActiveWindow();
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
const char *dirty = buffer->dirty ? "!" : "";
|
||||||
|
Format(scratch, "%.*s%s", buffer->name, dirty);
|
||||||
|
SDL_SetWindowTitle(sdl_window, buffer->name.data);
|
||||||
|
}
|
||||||
ReplaceInfobarData();
|
ReplaceInfobarData();
|
||||||
ReplaceDebugData();
|
ReplaceDebugData();
|
||||||
|
|
||||||
@@ -302,10 +310,10 @@ int main()
|
|||||||
DrawWindow(window);
|
DrawWindow(window);
|
||||||
}
|
}
|
||||||
EndFrameRender(ColorBackground);
|
EndFrameRender(ColorBackground);
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(sdl_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(sdl_window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
EndProfiler();
|
EndProfiler();
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ void InitWindows(View *null_view) {
|
|||||||
void LayoutWindows() {
|
void LayoutWindows() {
|
||||||
Rect2I screen_rect = GetScreenRectI();
|
Rect2I screen_rect = GetScreenRectI();
|
||||||
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
|
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
|
||||||
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").x;
|
float line_numbers_size = (float)FontCharSpacing * 10;
|
||||||
double sizex = (double)GetSize(screen_rect).x;
|
double sizex = (double)GetSize(screen_rect).x;
|
||||||
{
|
{
|
||||||
Window *window = GetWindow(SearchWindowID);
|
Window *window = GetWindow(SearchWindowID);
|
||||||
@@ -120,14 +120,14 @@ void LayoutWindows() {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5));
|
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5));
|
||||||
Windows[i].document_rect = Windows[i].total_rect;
|
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_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, FontCharSpacing);
|
||||||
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int i = 1;
|
int i = 1;
|
||||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
|
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
|
||||||
Windows[i].document_rect = Windows[i].total_rect;
|
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_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, FontCharSpacing);
|
||||||
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ void DrawWindow(Window *window) {
|
|||||||
pos += window->line_numbers_rect.min;
|
pos += window->line_numbers_rect.min;
|
||||||
String s = Format(scratch, "%lld", (long long)line + 1ll);
|
String s = Format(scratch, "%lld", (long long)line + 1ll);
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
float x = GetStringSize(&MainFont, string).x;
|
float x = FontCharSpacing * (float)string.len;
|
||||||
Vec2 p = ToVec2(pos);
|
Vec2 p = ToVec2(pos);
|
||||||
float rectx = (float)GetSize(window->line_numbers_rect).x;
|
float rectx = (float)GetSize(window->line_numbers_rect).x;
|
||||||
p.x += (rectx - x) / 2.f;
|
p.x += (rectx - x) / 2.f;
|
||||||
|
|||||||
Reference in New Issue
Block a user