Fix line numbers
This commit is contained in:
@@ -78,10 +78,10 @@ int main(void) {
|
||||
Add(&view.carets, {0, 0});
|
||||
view.buffer = CreateBuffer(Perm);
|
||||
// LoadUnicode(view.buffer);
|
||||
// LoadBigTextAndBigLine(view.buffer);
|
||||
LoadBigTextAndBigLine(view.buffer);
|
||||
// LoadBigLine(view.buffer);
|
||||
// LoadBigText(view.buffer);
|
||||
LoadTextA(view.buffer);
|
||||
// LoadTextA(view.buffer);
|
||||
// LoadLine(view.buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -180,28 +180,35 @@ void DrawView(View &view) {
|
||||
|
||||
// Draw line numbers
|
||||
{
|
||||
DrawRectangleRec(ToRectangle(view.line_numbers_rect), ColorBackground);
|
||||
Rect2I r = view.line_numbers_rect;
|
||||
DrawRectangleRec(ToRectangle(r), ColorBackground);
|
||||
BeginScissorMode((int)r.min.x, (int)r.min.y, (int)r.max.x - (int)r.min.x, (int)r.max.y - (int)r.min.y);
|
||||
|
||||
Rect2I vlines = GetVisibleCells(view);
|
||||
for (Int line = vlines.min.y; line <= vlines.max.y; line += 1) {
|
||||
Scratch scratch;
|
||||
Vec2I pos = {0, line * view.line_spacing};
|
||||
pos -= view.scroll;
|
||||
pos += view.line_numbers_rect.min;
|
||||
pos.y -= view.scroll.y;
|
||||
pos += r.min;
|
||||
String s = Format(scratch, "%lld", (long long)line);
|
||||
String16 string = ToString16(scratch, s);
|
||||
float x = MeasureTextEx(view.font, s.data, (float)view.font_size, (float)view.font_spacing).x;
|
||||
Vec2 p = ToVec2(pos);
|
||||
p.x += (GetSize(view.line_numbers_rect).x - x) / 2.f;
|
||||
float rectx = (float)GetSize(r).x;
|
||||
p.x += (rectx - x) / 2.f;
|
||||
if (x > rectx) p.x = 0;
|
||||
DrawString(view.font, string, p, (float)view.font_size, (float)view.font_spacing, ColorTextLineNumbers);
|
||||
}
|
||||
|
||||
EndScissorMode();
|
||||
}
|
||||
|
||||
// Draw info bar
|
||||
{
|
||||
DrawRectangleRec(ToRectangle(view.infobar_rect), ColorScrollbarBackground);
|
||||
|
||||
Rect2I r = view.infobar_rect;
|
||||
DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground);
|
||||
{
|
||||
Vec2 p = ToVec2(view.infobar_rect.min);
|
||||
Vec2 p = ToVec2(r.min);
|
||||
Scratch scratch;
|
||||
Caret caret = view.carets[0];
|
||||
XY xy = PosToXY(*view.buffer, GetFront(caret));
|
||||
|
||||
Reference in New Issue
Block a user