Null objects

This commit is contained in:
Krzosa Karol
2024-07-23 09:06:39 +02:00
parent 740b0f217f
commit 5f18779f1d
2 changed files with 38 additions and 24 deletions

View File

@@ -81,6 +81,19 @@ int main(void) {
Font = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500); Font = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
FontCharSpacing = GetCharSpacing(Font, FontSize, FontSpacing); FontCharSpacing = GetCharSpacing(Font, FontSize, FontSpacing);
// Create null
{
CreateBuffer(GetSystemAllocator());
View view = {AllocViewID()};
Add(&view.carets, {0, 0});
Add(&Views, view);
Window window = {AllocWindowID()};
Add(&window.views, {0});
Add(&Windows, window);
}
{ {
Window window = {AllocWindowID()}; Window window = {AllocWindowID()};
{ {
@@ -99,8 +112,7 @@ int main(void) {
{ {
Window window = {AllocWindowID()}; Window window = {AllocWindowID()};
{ {
View view = {}; View view = {AllocViewID()};
view.id = AllocViewID();
Add(&view.carets, {0, 0}); Add(&view.carets, {0, 0});
view.buffer_id = CreateBuffer(Perm); view.buffer_id = CreateBuffer(Perm);
Buffer *buffer = GetBuffer(view.buffer_id); Buffer *buffer = GetBuffer(view.buffer_id);
@@ -133,25 +145,27 @@ int main(void) {
Rect2I screen_rect = GetScreenRect(); Rect2I screen_rect = GetScreenRect();
float line_numbers_size = MeasureTextEx(Font, "12345", (float)FontSize, (float)FontSpacing).x; float line_numbers_size = MeasureTextEx(Font, "12345", (float)FontSize, (float)FontSpacing).x;
{ {
Windows[0].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33)); Windows[1].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
Windows[0].document_rect = Windows[0].total_rect;
Windows[0].scrollbar_rect = CutRight(&Windows[0].document_rect, 10);
Windows[0].infobar_rect = CutBottom(&Windows[0].document_rect, (Int)MenuFontSize);
Windows[0].line_numbers_rect = CutLeft(&Windows[0].document_rect, (Int)line_numbers_size);
}
{
Windows[1].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
Windows[1].document_rect = Windows[1].total_rect; Windows[1].document_rect = Windows[1].total_rect;
Windows[1].scrollbar_rect = CutRight(&Windows[1].document_rect, 10); Windows[1].scrollbar_rect = CutRight(&Windows[1].document_rect, 10);
Windows[1].infobar_rect = CutBottom(&Windows[1].document_rect, (Int)MenuFontSize); Windows[1].infobar_rect = CutBottom(&Windows[1].document_rect, (Int)MenuFontSize);
Windows[1].line_numbers_rect = CutLeft(&Windows[1].document_rect, (Int)line_numbers_size); Windows[1].line_numbers_rect = CutLeft(&Windows[1].document_rect, (Int)line_numbers_size);
} }
{ {
Windows[2].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0)); int i = 2;
Windows[2].document_rect = Windows[2].total_rect; Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
Windows[2].scrollbar_rect = CutRight(&Windows[2].document_rect, 10); Windows[i].document_rect = Windows[i].total_rect;
Windows[2].infobar_rect = CutBottom(&Windows[2].document_rect, (Int)MenuFontSize); Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
Windows[2].line_numbers_rect = CutLeft(&Windows[2].document_rect, (Int)line_numbers_size); Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 3;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
Windows[i].document_rect = Windows[i].total_rect;
Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
Windows[i].infobar_rect = CutBottom(&Windows[i].document_rect, (Int)MenuFontSize);
Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
} }
BeginDrawing(); BeginDrawing();

View File

@@ -70,13 +70,13 @@ Rect2I GetVisibleCells(Window &window);
void AfterEdit(View *view, Array<Edit> edits); void AfterEdit(View *view, Array<Edit> edits);
Scroller ComputeScrollerRect(Window &window); Scroller ComputeScrollerRect(Window &window);
WindowID WindowIDs = {1}; WindowID WindowIDs = {0};
BufferID BufferIDs = {1}; BufferID BufferIDs = {0};
ViewID ViewIDs = {1}; ViewID ViewIDs = {0};
Window NullWindow = {}; WindowID NullWindowID = {0};
View NullView = {}; BufferID NullBufferID = {0};
Buffer NullBuffer = {}; ViewID NullViewID = {0};
Array<Buffer> Buffers = {}; Array<Buffer> Buffers = {};
Array<View> Views = {}; Array<View> Views = {};
@@ -85,17 +85,17 @@ WindowID ActiveWindow = {};
inline Window *GetWindow(WindowID id) { inline Window *GetWindow(WindowID id) {
For(Windows) if (it.id.id == id.id) return &it; For(Windows) if (it.id.id == id.id) return &it;
return &NullWindow; return &Windows[0];
} }
inline Buffer *GetBuffer(BufferID id) { inline Buffer *GetBuffer(BufferID id) {
For(Buffers) if (it.id.id == id.id) return &it; For(Buffers) if (it.id.id == id.id) return &it;
return &NullBuffer; return &Buffers[0];
} }
inline View *GetView(ViewID id) { inline View *GetView(ViewID id) {
For(Views) if (it.id.id == id.id) return &it; For(Views) if (it.id.id == id.id) return &it;
return &NullView; return &Views[0];
} }
inline ViewID AllocViewID() { return {ViewIDs.id++}; } inline ViewID AllocViewID() { return {ViewIDs.id++}; }