Drawing line numbers
This commit is contained in:
@@ -14,15 +14,14 @@ Arena FrameArena;
|
||||
// WindowBuffer units
|
||||
// WindowBufferWorld units
|
||||
|
||||
const uint64_t WindowFlag_DrawTitleBar = 1 << 1;
|
||||
const uint64_t WindowFlag_DrawLineNumbers = 1 << 2;
|
||||
const uint64_t WindowFlag_DrawRightScrollBar = 1 << 3;
|
||||
const uint64_t WindowFlag_DrawBottomScrollBar = 1 << 4;
|
||||
|
||||
struct Window {
|
||||
uint64_t flags;
|
||||
Rect2 rect_in_world_units;
|
||||
Vec2 scroll; // window_world_to_window_units
|
||||
float title_bar_pixel_size;
|
||||
float line_number_bar_pixel_size;
|
||||
float right_scroll_bar_pixel_size;
|
||||
float bottom_scroll_bar_pixel_size;
|
||||
|
||||
Array<Range> cursors;
|
||||
Buffer buffer;
|
||||
@@ -117,18 +116,26 @@ int main() {
|
||||
float font_size = 64;
|
||||
float font_spacing = 1;
|
||||
Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250);
|
||||
|
||||
float title_bar_font_size = 15;
|
||||
Font title_bar_font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)title_bar_font_size, NULL, 250);
|
||||
if (0) font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
|
||||
|
||||
Array<Window> windows = {};
|
||||
{
|
||||
Window window = {};
|
||||
window.flags = WindowFlag_DrawTitleBar | WindowFlag_DrawLineNumbers;
|
||||
window.rect_in_world_units = GetScreenRectRenderUnits();
|
||||
window.rect_in_world_units.max.x *= 2;
|
||||
window.rect_in_world_units.max.y *= 2;
|
||||
|
||||
window.title_bar_pixel_size = 20;
|
||||
window.line_number_bar_pixel_size = 40;
|
||||
window.right_scroll_bar_pixel_size = 30;
|
||||
window.bottom_scroll_bar_pixel_size = 30;
|
||||
|
||||
InitBuffer(&window.buffer);
|
||||
if (1) {
|
||||
for (int i = 0; i < 5; i += 1) {
|
||||
for (int i = 0; i < 50; i += 1) {
|
||||
Array<Edit> edits = {FrameArena};
|
||||
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i));
|
||||
ApplyEdits(&window.buffer, edits);
|
||||
@@ -136,7 +143,8 @@ int main() {
|
||||
}
|
||||
|
||||
window.cursors.add({});
|
||||
window.cursors.add(GetLine(window.buffer, 1).range);
|
||||
int64_t pos = GetLine(window.buffer, 1).range.min;
|
||||
window.cursors.add({pos, pos});
|
||||
windows.add(window);
|
||||
}
|
||||
|
||||
@@ -223,8 +231,7 @@ int main() {
|
||||
Rectangle rectangle_in_render_units = ToRectangle(window_rect_in_render_units);
|
||||
DrawRectangleRec(rectangle_in_render_units, WHITE);
|
||||
|
||||
Rect2 window_text_rect_in_render_units = window_rect_in_render_units;
|
||||
|
||||
Rect2 window_text_rect_in_render_units = window_rect_in_render_units;
|
||||
Rect2 window_text_rect_in_render_units_clamped_to_screen = window_text_rect_in_render_units;
|
||||
Rect2 screen_rect_in_render_units = GetScreenRectRenderUnits();
|
||||
window_text_rect_in_render_units_clamped_to_screen.min.x = Clamp(window_text_rect_in_render_units_clamped_to_screen.min.x, screen_rect_in_render_units.min.x, screen_rect_in_render_units.max.x);
|
||||
@@ -232,19 +239,17 @@ int main() {
|
||||
window_text_rect_in_render_units_clamped_to_screen.min.y = Clamp(window_text_rect_in_render_units_clamped_to_screen.min.y, screen_rect_in_render_units.min.y, screen_rect_in_render_units.max.y);
|
||||
window_text_rect_in_render_units_clamped_to_screen.max.y = Clamp(window_text_rect_in_render_units_clamped_to_screen.max.y, screen_rect_in_render_units.min.y, screen_rect_in_render_units.max.y);
|
||||
|
||||
float title_bar_size = 20;
|
||||
float line_number_bar_size = 40;
|
||||
float scroll_bar_size = 30;
|
||||
Vec2 window_buffer_to_window_units = {line_number_bar_size, title_bar_size};
|
||||
Rect2 title_bar_in_render_units = CutTop(&window_text_rect_in_render_units_clamped_to_screen, title_bar_size);
|
||||
Rect2 line_number_bar_in_render_units = CutLeft(&window_text_rect_in_render_units_clamped_to_screen, line_number_bar_size);
|
||||
Rect2 bottom_scroll_bar_in_render_units = CutBottom(&window_text_rect_in_render_units_clamped_to_screen, scroll_bar_size);
|
||||
Rect2 right_scroll_bar_in_render_units = CutRight(&window_text_rect_in_render_units_clamped_to_screen, scroll_bar_size);
|
||||
Vec2 window_buffer_to_window_units = {window.line_number_bar_pixel_size, window.title_bar_pixel_size};
|
||||
Rect2 title_bar_in_render_units = CutTop(&window_text_rect_in_render_units_clamped_to_screen, window.title_bar_pixel_size);
|
||||
Rect2 line_number_bar_in_render_units = CutLeft(&window_text_rect_in_render_units_clamped_to_screen, window.line_number_bar_pixel_size);
|
||||
Rect2 bottom_scroll_bar_in_render_units = CutBottom(&window_text_rect_in_render_units_clamped_to_screen, window.bottom_scroll_bar_pixel_size);
|
||||
Rect2 right_scroll_bar_in_render_units = CutRight(&window_text_rect_in_render_units_clamped_to_screen, window.right_scroll_bar_pixel_size);
|
||||
|
||||
DrawRectangleRec(ToRectangle(title_bar_in_render_units), GRAY);
|
||||
DrawRectangleRec(ToRectangle(line_number_bar_in_render_units), GRAY);
|
||||
DrawRectangleRec(ToRectangle(bottom_scroll_bar_in_render_units), GRAY);
|
||||
DrawRectangleRec(ToRectangle(right_scroll_bar_in_render_units), GRAY);
|
||||
DrawString(title_bar_font, "title bar :)", title_bar_in_render_units.min, title_bar_font_size, font_spacing, BLACK);
|
||||
|
||||
if (0) {
|
||||
window_text_rect_in_render_units_clamped_to_screen = Shrink(window_text_rect_in_render_units_clamped_to_screen, 10);
|
||||
@@ -373,8 +378,21 @@ int main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EndScissorMode();
|
||||
|
||||
// Draw the line numbers
|
||||
{
|
||||
Rectangle bar_rectangle = ToRectangle(line_number_bar_in_render_units);
|
||||
BeginScissorMode((int)bar_rectangle.x, (int)bar_rectangle.y, (int)bar_rectangle.width, (int)bar_rectangle.height);
|
||||
Vec2 text_position_in_render_units = line_number_bar_in_render_units.min;
|
||||
For(rows) {
|
||||
Assert(it.cells.len);
|
||||
text_position_in_render_units.y = it.cells[0].rect.min.y;
|
||||
String string_num = Format(FrameArena, "%lld", (long long)it.line);
|
||||
DrawString(font, string_num, text_position_in_render_units, font_size, font_spacing, BLACK);
|
||||
}
|
||||
EndScissorMode();
|
||||
}
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
|
||||
Reference in New Issue
Block a user