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)
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -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 = '_') {
|
||||
Glyph *g = GetGlyph(font, codepoint);
|
||||
if (g->xadvance) return (Int)g->xadvance;
|
||||
|
||||
@@ -292,10 +292,7 @@ void ReplaceInfobarData() {
|
||||
ReplaceText(buffer, GetEndAsRange(*buffer), L" |");
|
||||
}
|
||||
|
||||
const char *dirty = "";
|
||||
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);
|
||||
String s = Format(scratch, "Line %lld Column %lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll);
|
||||
String16 string = ToString16(scratch, s);
|
||||
ReplaceText(buffer, replace_range, string);
|
||||
Command_SelectRangeOneCursor(view, {});
|
||||
|
||||
@@ -203,7 +203,7 @@ function GenericTextFileRule(_s)
|
||||
|
||||
line, col, _s = match_line_col(_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
|
||||
|
||||
|
||||
|
||||
@@ -56,9 +56,7 @@ int LuaOpen(lua_State *L) {
|
||||
UpdateScroll(window, true);
|
||||
SetActiveWindow(window->id);
|
||||
} else {
|
||||
// Window *window = GetWindow(GetLastActiveWindow());
|
||||
// View *view = ViewOpenFile(window, path);
|
||||
// SetActiveWindow(window->id);
|
||||
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -142,22 +142,22 @@ int main()
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
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;
|
||||
SDL_Window *window = SDL_CreateWindow("Text editor", 1280, 720, window_flags);
|
||||
if (window == NULL) {
|
||||
SDL_Window *sdl_window = SDL_CreateWindow("Text editor", 1280, 720, window_flags);
|
||||
if (sdl_window == NULL) {
|
||||
ReportErrorf("Couldn't create window! %s", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||
SDL_GL_MakeCurrent(window, gl_context);
|
||||
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window);
|
||||
SDL_GL_MakeCurrent(sdl_window, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
SDL_ShowWindow(window);
|
||||
SDL_ShowWindow(sdl_window);
|
||||
|
||||
// Set icon
|
||||
{
|
||||
uint32_t data = 0xddddddff;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -166,10 +166,10 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_StartTextInput(window);
|
||||
SDL_StartTextInput(sdl_window);
|
||||
SDL_GL_SetSwapInterval(1); // vsync
|
||||
{
|
||||
float scale = SDL_GetWindowDisplayScale(window);
|
||||
float scale = SDL_GetWindowDisplayScale(sdl_window);
|
||||
if (scale != 1.0f) DPIScale = scale;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ int main()
|
||||
WaitForEvents = true;
|
||||
|
||||
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};
|
||||
BeginFrameRender();
|
||||
LayoutWindows();
|
||||
@@ -265,6 +265,14 @@ int main()
|
||||
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();
|
||||
ReplaceDebugData();
|
||||
|
||||
@@ -302,10 +310,10 @@ int main()
|
||||
DrawWindow(window);
|
||||
}
|
||||
EndFrameRender(ColorBackground);
|
||||
SDL_GL_SwapWindow(window);
|
||||
SDL_GL_SwapWindow(sdl_window);
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_DestroyWindow(sdl_window);
|
||||
SDL_Quit();
|
||||
|
||||
EndProfiler();
|
||||
|
||||
@@ -105,7 +105,7 @@ void InitWindows(View *null_view) {
|
||||
void LayoutWindows() {
|
||||
Rect2I screen_rect = GetScreenRectI();
|
||||
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;
|
||||
{
|
||||
Window *window = GetWindow(SearchWindowID);
|
||||
@@ -120,14 +120,14 @@ void LayoutWindows() {
|
||||
int i = 0;
|
||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 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_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);
|
||||
}
|
||||
{
|
||||
int i = 1;
|
||||
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
|
||||
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);
|
||||
}
|
||||
{
|
||||
|
||||
@@ -177,7 +177,7 @@ void DrawWindow(Window *window) {
|
||||
pos += window->line_numbers_rect.min;
|
||||
String s = Format(scratch, "%lld", (long long)line + 1ll);
|
||||
String16 string = ToString16(scratch, s);
|
||||
float x = GetStringSize(&MainFont, string).x;
|
||||
float x = FontCharSpacing * (float)string.len;
|
||||
Vec2 p = ToVec2(pos);
|
||||
float rectx = (float)GetSize(window->line_numbers_rect).x;
|
||||
p.x += (rectx - x) / 2.f;
|
||||
|
||||
Reference in New Issue
Block a user