Consistency/intent

- pass arenas as first parameters (exception being texbox widget, where we always pass tag as first parameter)
- pass lists by value when there's no modification (eg oc_list_for etc...)
- fix sketches, use oc_arena_scope as value.
This commit is contained in:
Martin Fouilleul 2023-09-14 11:54:38 +02:00
parent 47dc052508
commit 09cf30cf45
35 changed files with 131 additions and 206 deletions

View File

@ -51,7 +51,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
@ -69,19 +69,19 @@ int main()
{ {
if(event->key.action == OC_KEY_PRESS) if(event->key.action == OC_KEY_PRESS)
{ {
if(event->key.code == OC_KEY_LEFT) if(event->key.keyCode == OC_KEY_LEFT)
{ {
x -= 1; x -= 1;
} }
if(event->key.code == OC_KEY_RIGHT) if(event->key.keyCode == OC_KEY_RIGHT)
{ {
x += 1; x += 1;
} }
if(event->key.code == OC_KEY_UP) if(event->key.keyCode == OC_KEY_UP)
{ {
y -= 1; y -= 1;
} }
if(event->key.code == OC_KEY_DOWN) if(event->key.keyCode == OC_KEY_DOWN)
{ {
y += 1; y += 1;
} }

View File

@ -42,7 +42,7 @@ int main()
} }
//NOTE: create image //NOTE: create image
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str8 imagePath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/triceratops.png")); oc_str8 imagePath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/triceratops.png"));
oc_image image = oc_image_create_from_file(surface, imagePath, false); oc_image image = oc_image_create_from_file(surface, imagePath, false);

View File

@ -23,7 +23,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)

View File

@ -58,7 +58,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
oc_pump_events(0); oc_pump_events(0);

View File

@ -64,7 +64,7 @@ static const char* TEST_STRING =
oc_font create_font(const char* path) oc_font create_font(const char* path)
{ {
//NOTE(martin): create font //NOTE(martin): create font
oc_arena_scope* scratch = oc_scratch_begin() oc_arena_scope scratch = oc_scratch_begin();
oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8(path)); oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8(path));
char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath); char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath);
@ -169,13 +169,13 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
f64 startFrameTime = oc_clock_time(OC_CLOCK_MONOTONIC); f64 startFrameTime = oc_clock_time(OC_CLOCK_MONOTONIC);
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)
{ {
oc_input_process_event(&inputState, event); oc_input_process_event(&inputState, scratch.arena, event);
switch(event->type) switch(event->type)
{ {
@ -187,7 +187,7 @@ int main()
case OC_EVENT_MOUSE_BUTTON: case OC_EVENT_MOUSE_BUTTON:
{ {
if(event->key.code == OC_MOUSE_LEFT) if(event->key.keyCode == OC_MOUSE_LEFT)
{ {
if(event->key.action == OC_KEY_PRESS) if(event->key.action == OC_KEY_PRESS)
{ {
@ -220,7 +220,7 @@ int main()
case OC_EVENT_KEYBOARD_KEY: case OC_EVENT_KEYBOARD_KEY:
{ {
if(event->key.code == OC_KEY_SPACE && event->key.action == OC_KEY_PRESS) if(event->key.keyCode == OC_KEY_SPACE && event->key.action == OC_KEY_PRESS)
{ {
fontIndex = (fontIndex + 1) % FONT_COUNT; fontIndex = (fontIndex + 1) % FONT_COUNT;
} }

View File

@ -18,7 +18,7 @@ i32 render_thread(void* user)
{ {
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)

View File

@ -25,7 +25,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)

View File

@ -18,7 +18,7 @@
oc_font create_font() oc_font create_font()
{ {
//NOTE(martin): create font //NOTE(martin): create font
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/OpenSansLatinSubset.ttf")); oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath); char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath);
@ -89,7 +89,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;

View File

@ -167,7 +167,7 @@ i32 render(void* user)
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_event* event = 0; oc_event* event = 0;

View File

@ -20,7 +20,7 @@
oc_font create_font() oc_font create_font()
{ {
//NOTE(martin): create font //NOTE(martin): create font
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/OpenSansLatinSubset.ttf")); oc_str8 fontPath = oc_path_executable_relative(scratch.arena, OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath); char* fontPathCString = oc_str8_to_cstring(scratch.arena, fontPath);
@ -98,7 +98,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC); f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
oc_pump_events(0); oc_pump_events(0);

View File

@ -120,7 +120,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)

View File

@ -109,7 +109,7 @@ int main()
while(!oc_should_quit()) while(!oc_should_quit())
{ {
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_pump_events(0); oc_pump_events(0);
oc_event* event = 0; oc_event* event = 0;
while((event = oc_next_event(scratch.arena)) != 0) while((event = oc_next_event(scratch.arena)) != 0)

View File

@ -36,7 +36,7 @@ int main()
//NOTE(martin): load the library //NOTE(martin): load the library
id<MTLDevice> device = MTLCreateSystemDefaultDevice(); id<MTLDevice> device = MTLCreateSystemDefaultDevice();
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str8 shaderPath = oc_path_executable_relative(scratch.arena, OC_STR8("triangle_shader.metallib")); oc_str8 shaderPath = oc_path_executable_relative(scratch.arena, OC_STR8("triangle_shader.metallib"));
const char* shaderPathCString = oc_str8_to_cstring(scratch.arena, shaderPath); const char* shaderPathCString = oc_str8_to_cstring(scratch.arena, shaderPath);

View File

@ -109,7 +109,7 @@ void oc_queue_event(oc_event* event)
if(event->type == OC_EVENT_PATHDROP) if(event->type == OC_EVENT_PATHDROP)
{ {
oc_list_for(&event->paths.list, elt, oc_str8_elt, listElt) oc_list_for(event->paths.list, elt, oc_str8_elt, listElt)
{ {
oc_str8* path = &elt->string; oc_str8* path = &elt->string;
if(oc_ringbuffer_write_available(queue) < (sizeof(u64) + path->len)) if(oc_ringbuffer_write_available(queue) < (sizeof(u64) + path->len))

View File

@ -1762,7 +1762,7 @@ void oc_osx_update_layers(oc_window_data* window)
@autoreleasepool @autoreleasepool
{ {
int z = 0; int z = 0;
oc_list_for(&window->osx.layers, layer, oc_layer, listElt) oc_list_for(window->osx.layers, layer, oc_layer, listElt)
{ {
layer->caLayer.zPosition = (CGFloat)z; layer->caLayer.zPosition = (CGFloat)z;
z++; z++;
@ -1962,7 +1962,7 @@ oc_str8 oc_open_dialog(oc_arena* arena,
{ {
NSMutableArray* fileTypesArray = [NSMutableArray array]; NSMutableArray* fileTypesArray = [NSMutableArray array];
oc_list_for((oc_list*)&filters.list, elt, oc_str8_elt, listElt) oc_list_for(filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8 string = elt->string; oc_str8 string = elt->string;
NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding]; NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding];
@ -2044,7 +2044,7 @@ oc_str8 oc_save_dialog(oc_arena* arena,
{ {
NSMutableArray* fileTypesArray = [NSMutableArray array]; NSMutableArray* fileTypesArray = [NSMutableArray array];
oc_list_for((oc_list*)&filters.list, elt, oc_str8_elt, listElt) oc_list_for(filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8 string = elt->string; oc_str8 string = elt->string;
NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding]; NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding];
@ -2184,7 +2184,7 @@ ORCA_API oc_file_dialog_result oc_file_dialog_for_table(oc_arena* arena, oc_file
{ {
NSMutableArray* fileTypesArray = [NSMutableArray array]; NSMutableArray* fileTypesArray = [NSMutableArray array];
oc_list_for((oc_list*)&desc->filters.list, elt, oc_str8_elt, listElt) oc_list_for(desc->filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8 string = elt->string; oc_str8 string = elt->string;
NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding]; NSString* filter = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding];
@ -2261,7 +2261,7 @@ int oc_alert_popup(oc_str8 title,
NSAlert* alert = [[NSAlert alloc] init]; NSAlert* alert = [[NSAlert alloc] init];
NSString* string; NSString* string;
oc_list_for_reverse((oc_list*)&options.list, elt, oc_str8_elt, listElt) oc_list_for_reverse(options.list, elt, oc_str8_elt, listElt)
{ {
string = [[NSString alloc] initWithBytes:elt->string.ptr length:elt->string.len encoding:NSUTF8StringEncoding]; string = [[NSString alloc] initWithBytes:elt->string.ptr length:elt->string.len encoding:NSUTF8StringEncoding];
[alert addButtonWithTitle:string]; [alert addButtonWithTitle:string];

View File

@ -335,7 +335,7 @@ static void oc_win32_update_child_layers(oc_window_data* window)
int clientWidth = (clientRect.right - clientRect.left); int clientWidth = (clientRect.right - clientRect.left);
int clientHeight = (clientRect.bottom - clientRect.top); int clientHeight = (clientRect.bottom - clientRect.top);
oc_list_for(&window->win32.layers, layer, oc_layer, listElt) oc_list_for(window->win32.layers, layer, oc_layer, listElt)
{ {
SetWindowPos(layer->hWnd, SetWindowPos(layer->hWnd,
0, 0,
@ -351,7 +351,7 @@ static void oc_win32_update_child_layers_zorder(oc_window_data* window)
{ {
HWND insertAfter = window->win32.hWnd; HWND insertAfter = window->win32.hWnd;
oc_list_for(&window->win32.layers, layer, oc_layer, listElt) oc_list_for(window->win32.layers, layer, oc_layer, listElt)
{ {
SetWindowPos(layer->hWnd, SetWindowPos(layer->hWnd,
insertAfter, insertAfter,
@ -1416,7 +1416,7 @@ oc_str8 oc_open_dialog(oc_arena* arena,
COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(arena, COMDLG_FILTERSPEC, filters.eltCount); COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(arena, COMDLG_FILTERSPEC, filters.eltCount);
int i = 0; int i = 0;
oc_list_for(&filters.list, elt, oc_str8_elt, listElt) oc_list_for(filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8_list list = { 0 }; oc_str8_list list = { 0 };
oc_str8_list_push(arena, &list, OC_STR8("*.")); oc_str8_list_push(arena, &list, OC_STR8("*."));
@ -1504,7 +1504,7 @@ oc_str8 oc_save_dialog(oc_arena* arena,
COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(arena, COMDLG_FILTERSPEC, filters.eltCount); COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(arena, COMDLG_FILTERSPEC, filters.eltCount);
int i = 0; int i = 0;
oc_list_for(&filters.list, elt, oc_str8_elt, listElt) oc_list_for(filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8_list list = { 0 }; oc_str8_list list = { 0 };
oc_str8_list_push(arena, &list, OC_STR8("*.")); oc_str8_list_push(arena, &list, OC_STR8("*."));
@ -1685,7 +1685,7 @@ oc_file_dialog_result oc_file_dialog_for_table(oc_arena* arena, oc_file_dialog_d
COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(scratch.arena, COMDLG_FILTERSPEC, desc->filters.eltCount); COMDLG_FILTERSPEC* filterSpecs = oc_arena_push_array(scratch.arena, COMDLG_FILTERSPEC, desc->filters.eltCount);
int i = 0; int i = 0;
oc_list_for(&desc->filters.list, elt, oc_str8_elt, listElt) oc_list_for(desc->filters.list, elt, oc_str8_elt, listElt)
{ {
oc_str8_list list = { 0 }; oc_str8_list list = { 0 };
oc_str8_list_push(scratch.arena, &list, OC_STR8("*.")); oc_str8_list_push(scratch.arena, &list, OC_STR8("*."));
@ -1784,7 +1784,7 @@ int oc_alert_popup(oc_str8 title,
TASKDIALOG_BUTTON* buttons = oc_arena_push_array(scratch.arena, TASKDIALOG_BUTTON, options.eltCount); TASKDIALOG_BUTTON* buttons = oc_arena_push_array(scratch.arena, TASKDIALOG_BUTTON, options.eltCount);
int i = 0; int i = 0;
oc_list_for(&options.list, elt, oc_str8_elt, listElt) oc_list_for(options.list, elt, oc_str8_elt, listElt)
{ {
int textWideSize = MultiByteToWideChar(CP_UTF8, 0, elt->string.ptr, elt->string.len, NULL, 0); int textWideSize = MultiByteToWideChar(CP_UTF8, 0, elt->string.ptr, elt->string.len, NULL, 0);
wchar_t* textWide = oc_arena_push_array(scratch.arena, wchar_t, textWideSize + 1); wchar_t* textWide = oc_arena_push_array(scratch.arena, wchar_t, textWideSize + 1);

View File

@ -234,7 +234,7 @@ ORCA_API oc_font oc_font_create_from_path(oc_str8 path, u32 rangeCount, oc_unico
ORCA_API void oc_font_destroy(oc_font font); ORCA_API void oc_font_destroy(oc_font font);
ORCA_API oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing); ORCA_API oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing);
ORCA_API oc_str32 oc_font_push_glyph_indices(oc_font font, oc_arena* arena, oc_str32 codePoints); ORCA_API oc_str32 oc_font_push_glyph_indices(oc_arena* arena, oc_font font, oc_str32 codePoints);
ORCA_API u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint); ORCA_API u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint);
// metrics // metrics

View File

@ -652,7 +652,7 @@ oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 b
return (oc_font_get_glyph_indices_from_font_data(fontData, codePoints, backing)); return (oc_font_get_glyph_indices_from_font_data(fontData, codePoints, backing));
} }
oc_str32 oc_font_push_glyph_indices(oc_font font, oc_arena* arena, oc_str32 codePoints) oc_str32 oc_font_push_glyph_indices(oc_arena* arena, oc_font font, oc_str32 codePoints)
{ {
u32* buffer = oc_arena_push_array(arena, u32, codePoints.len); u32* buffer = oc_arena_push_array(arena, u32, codePoints.len);
oc_str32 backing = { .ptr = buffer, .len = codePoints.len }; oc_str32 backing = { .ptr = buffer, .len = codePoints.len };
@ -774,7 +774,7 @@ oc_text_metrics oc_font_text_metrics_utf32(oc_font font, f32 fontSize, oc_str32
} }
oc_arena_scope scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str32 glyphIndices = oc_font_push_glyph_indices(font, scratch.arena, codePoints); oc_str32 glyphIndices = oc_font_push_glyph_indices(scratch.arena, font, codePoints);
//NOTE(martin): find width of missing character //NOTE(martin): find width of missing character
//TODO(martin): should cache that at font creation... //TODO(martin): should cache that at font creation...
@ -1519,7 +1519,7 @@ void oc_codepoints_outlines(oc_str32 codePoints)
oc_arena_scope scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str32 glyphIndices = oc_font_push_glyph_indices(canvas->attributes.font, scratch.arena, codePoints); oc_str32 glyphIndices = oc_font_push_glyph_indices(scratch.arena, canvas->attributes.font, codePoints);
oc_glyph_outlines_from_font_data(fontData, glyphIndices); oc_glyph_outlines_from_font_data(fontData, glyphIndices);
oc_scratch_end(scratch); oc_scratch_end(scratch);
@ -1540,7 +1540,7 @@ void oc_text_outlines(oc_str8 text)
oc_arena_scope scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str32 codePoints = oc_utf8_push_to_codepoints(scratch.arena, text); oc_str32 codePoints = oc_utf8_push_to_codepoints(scratch.arena, text);
oc_str32 glyphIndices = oc_font_push_glyph_indices(canvas->attributes.font, scratch.arena, codePoints); oc_str32 glyphIndices = oc_font_push_glyph_indices(scratch.arena, canvas->attributes.font, codePoints);
oc_glyph_outlines_from_font_data(fontData, glyphIndices); oc_glyph_outlines_from_font_data(fontData, glyphIndices);

View File

@ -135,13 +135,13 @@ oc_io_open_restrict_result oc_io_open_restrict(oc_file_desc dirFd, oc_str8 path,
if(context.error == OC_IO_OK) if(context.error == OC_IO_OK)
{ {
oc_list_for(&pathElements.list, elt, oc_str8_elt, listElt) oc_list_for(pathElements.list, elt, oc_str8_elt, listElt)
{ {
oc_str8 name = elt->string; oc_str8 name = elt->string;
oc_file_access eltAccessRights = OC_FILE_ACCESS_READ; oc_file_access eltAccessRights = OC_FILE_ACCESS_READ;
oc_file_open_flags eltOpenFlags = 0; oc_file_open_flags eltOpenFlags = 0;
bool atLastElement = (&elt->listElt == oc_list_last(&pathElements.list)); bool atLastElement = (&elt->listElt == oc_list_last(pathElements.list));
if(atLastElement) if(atLastElement)
{ {
eltAccessRights = accessRights; eltAccessRights = accessRights;
@ -224,7 +224,7 @@ oc_io_open_restrict_result oc_io_open_restrict(oc_file_desc dirFd, oc_str8 path,
} }
oc_str8_list linkElements = oc_str8_split(scratch.arena, link.target, sep); oc_str8_list linkElements = oc_str8_split(scratch.arena, link.target, sep);
if(!oc_list_empty(&linkElements.list)) if(!oc_list_empty(linkElements.list))
{ {
//NOTE: insert linkElements into pathElements after elt //NOTE: insert linkElements into pathElements after elt
oc_list_elt* tmp = elt->listElt.next; oc_list_elt* tmp = elt->listElt.next;
@ -404,7 +404,7 @@ oc_file_open_with_dialog_result oc_file_open_with_dialog_for_table(oc_arena* are
if(dialogResult.button == OC_FILE_DIALOG_OK) if(dialogResult.button == OC_FILE_DIALOG_OK)
{ {
int i = 0; int i = 0;
oc_list_for(&dialogResult.selection.list, elt, oc_str8_elt, listElt) oc_list_for(dialogResult.selection.list, elt, oc_str8_elt, listElt)
{ {
oc_file file = oc_file_nil(); oc_file file = oc_file_nil();
if(elt->string.len) if(elt->string.len)

View File

@ -161,7 +161,7 @@ void oc_bridge_log(oc_log_level level,
//NOTE: allocate a new entry //NOTE: allocate a new entry
//TODO: should probably use a buddy allocator over the arena or something //TODO: should probably use a buddy allocator over the arena or something
log_entry* entry = 0; log_entry* entry = 0;
oc_list_for(&debug->logFreeList, elt, log_entry, listElt) oc_list_for(debug->logFreeList, elt, log_entry, listElt)
{ {
if(elt->cap >= cap) if(elt->cap >= cap)
{ {
@ -587,7 +587,7 @@ i32 orca_runloop(void* user)
if(exports[OC_EXPORT_RAW_EVENT]) if(exports[OC_EXPORT_RAW_EVENT])
{ {
oc_event* clipboardEvent = oc_runtime_clipboard_process_event_begin(&__orcaApp.clipboard, scratch.arena, event); oc_event* clipboardEvent = oc_runtime_clipboard_process_event_begin(scratch.arena, &__orcaApp.clipboard, event);
oc_event* events[2]; oc_event* events[2];
u64 eventsCount; u64 eventsCount;
if(clipboardEvent != 0) if(clipboardEvent != 0)
@ -815,7 +815,7 @@ i32 orca_runloop(void* user)
oc_ui_style_match_after(oc_ui_pattern_all(), &buttonStyle, buttonStyleMask); oc_ui_style_match_after(oc_ui_pattern_all(), &buttonStyle, buttonStyleMask);
if(oc_ui_button("Clear").clicked) if(oc_ui_button("Clear").clicked)
{ {
oc_list_for_safe(&app->debugOverlay.logEntries, entry, log_entry, listElt) oc_list_for_safe(app->debugOverlay.logEntries, entry, log_entry, listElt)
{ {
oc_list_remove(&app->debugOverlay.logEntries, &entry->listElt); oc_list_remove(&app->debugOverlay.logEntries, &entry->listElt);
oc_list_push(&app->debugOverlay.logFreeList, &entry->listElt); oc_list_push(&app->debugOverlay.logFreeList, &entry->listElt);
@ -856,7 +856,7 @@ i32 orca_runloop(void* user)
oc_ui_container("contents", 0) oc_ui_container("contents", 0)
{ {
oc_list_for(&app->debugOverlay.logEntries, entry, log_entry, listElt) oc_list_for(app->debugOverlay.logEntries, entry, log_entry, listElt)
{ {
log_entry_ui(&app->debugOverlay, entry); log_entry_ui(&app->debugOverlay, entry);
} }

View File

@ -48,7 +48,7 @@ void oc_runtime_clipboard_set_string(oc_runtime_clipboard* clipboard, oc_wasm_st
} }
} }
oc_event* oc_runtime_clipboard_process_event_begin(oc_runtime_clipboard* clipboard, oc_arena* arena, oc_event* origEvent) oc_event* oc_runtime_clipboard_process_event_begin(oc_arena* arena, oc_runtime_clipboard* clipboard, oc_event* origEvent)
{ {
oc_event* resultEvent = 0; oc_event* resultEvent = 0;
if(origEvent->type == OC_EVENT_KEYBOARD_KEY) if(origEvent->type == OC_EVENT_KEYBOARD_KEY)

View File

@ -21,7 +21,7 @@ typedef struct oc_runtime_clipboard
oc_wasm_str8 oc_runtime_clipboard_get_string(oc_runtime_clipboard* clipboard, oc_wasm_addr wasmArena); oc_wasm_str8 oc_runtime_clipboard_get_string(oc_runtime_clipboard* clipboard, oc_wasm_addr wasmArena);
void oc_runtime_clipboard_set_string(oc_runtime_clipboard* clipboard, oc_wasm_str8 value); void oc_runtime_clipboard_set_string(oc_runtime_clipboard* clipboard, oc_wasm_str8 value);
oc_event* oc_runtime_clipboard_process_event_begin(oc_runtime_clipboard* clipboard, oc_arena* arena, oc_event* origEvent); oc_event* oc_runtime_clipboard_process_event_begin(oc_arena* arena, oc_runtime_clipboard* clipboard, oc_event* origEvent);
void oc_runtime_clipboard_process_event_end(oc_runtime_clipboard* clipboard); void oc_runtime_clipboard_process_event_end(oc_runtime_clipboard* clipboard);
#else #else

View File

@ -132,7 +132,7 @@ oc_wasm_file_open_with_dialog_result oc_file_open_with_dialog_bridge(oc_wasm_add
.file = nativeResult.file .file = nativeResult.file
}; };
oc_list_for(&nativeResult.selection, elt, oc_file_open_with_dialog_elt, listElt) oc_list_for(nativeResult.selection, elt, oc_file_open_with_dialog_elt, listElt)
{ {
oc_wasm_addr wasmEltAddr = oc_wasm_arena_push(wasmArena, sizeof(oc_wasm_file_open_with_dialog_elt)); oc_wasm_addr wasmEltAddr = oc_wasm_arena_push(wasmArena, sizeof(oc_wasm_file_open_with_dialog_elt));
oc_wasm_file_open_with_dialog_elt* wasmElt = oc_wasm_address_to_ptr(wasmEltAddr, sizeof(oc_wasm_file_open_with_dialog_elt)); oc_wasm_file_open_with_dialog_elt* wasmElt = oc_wasm_address_to_ptr(wasmEltAddr, sizeof(oc_wasm_file_open_with_dialog_elt));

View File

@ -63,7 +63,7 @@ static void oc_update_key_mods(oc_input_state* state, oc_keymod_flags mods)
state->keyboard.mods = mods; state->keyboard.mods = mods;
} }
static void oc_update_clipboard_paste(oc_input_state* state, oc_arena* arena) static void oc_update_clipboard_paste(oc_arena* arena, oc_input_state* state)
{ {
state->clipboard.lastUpdate = state->frameCounter; state->clipboard.lastUpdate = state->frameCounter;
state->clipboard.pastedText = oc_clipboard_get_string(arena); state->clipboard.pastedText = oc_clipboard_get_string(arena);
@ -140,7 +140,7 @@ void oc_input_next_frame(oc_input_state* state)
state->frameCounter++; state->frameCounter++;
} }
void oc_input_process_event(oc_input_state* state, oc_arena* arena, oc_event* event) void oc_input_process_event(oc_arena* arena, oc_input_state* state, oc_event* event)
{ {
switch(event->type) switch(event->type)
{ {
@ -161,7 +161,7 @@ void oc_input_process_event(oc_input_state* state, oc_arena* arena, oc_event* ev
break; break;
case OC_EVENT_CLIPBOARD_PASTE: case OC_EVENT_CLIPBOARD_PASTE:
oc_update_clipboard_paste(state, arena); oc_update_clipboard_paste(arena, state);
break; break;
case OC_EVENT_MOUSE_MOVE: case OC_EVENT_MOUSE_MOVE:
@ -399,7 +399,7 @@ oc_vec2 oc_mouse_wheel(oc_input_state* input)
} }
} }
oc_str32 oc_input_text_utf32(oc_input_state* input, oc_arena* arena) oc_str32 oc_input_text_utf32(oc_arena* arena, oc_input_state* input)
{ {
oc_str32 res = { 0 }; oc_str32 res = { 0 };
if(input->text.lastUpdate == input->frameCounter) if(input->text.lastUpdate == input->frameCounter)
@ -409,7 +409,7 @@ oc_str32 oc_input_text_utf32(oc_input_state* input, oc_arena* arena)
return (res); return (res);
} }
oc_str8 oc_input_text_utf8(oc_input_state* input, oc_arena* arena) oc_str8 oc_input_text_utf8(oc_arena* arena, oc_input_state* input)
{ {
oc_str8 res = { 0 }; oc_str8 res = { 0 };
if(input->text.lastUpdate == input->frameCounter) if(input->text.lastUpdate == input->frameCounter)

View File

@ -86,7 +86,7 @@ typedef struct oc_input_state
oc_clipboard_state clipboard; oc_clipboard_state clipboard;
} oc_input_state; } oc_input_state;
ORCA_API void oc_input_process_event(oc_input_state* state, oc_arena* arena, oc_event* event); ORCA_API void oc_input_process_event(oc_arena* arena, oc_input_state* state, oc_event* event);
ORCA_API void oc_input_next_frame(oc_input_state* state); ORCA_API void oc_input_next_frame(oc_input_state* state);
ORCA_API bool oc_key_down(oc_input_state* state, oc_key_code key); ORCA_API bool oc_key_down(oc_input_state* state, oc_key_code key);
@ -109,8 +109,8 @@ ORCA_API oc_vec2 oc_mouse_position(oc_input_state* state);
ORCA_API oc_vec2 oc_mouse_delta(oc_input_state* state); ORCA_API oc_vec2 oc_mouse_delta(oc_input_state* state);
ORCA_API oc_vec2 oc_mouse_wheel(oc_input_state* state); ORCA_API oc_vec2 oc_mouse_wheel(oc_input_state* state);
ORCA_API oc_str32 oc_input_text_utf32(oc_input_state* state, oc_arena* arena); ORCA_API oc_str32 oc_input_text_utf32(oc_arena* arena, oc_input_state* state);
ORCA_API oc_str8 oc_input_text_utf8(oc_input_state* state, oc_arena* arena); ORCA_API oc_str8 oc_input_text_utf8(oc_arena* arena, oc_input_state* state);
ORCA_API bool oc_clipboard_pasted(oc_input_state* state); ORCA_API bool oc_clipboard_pasted(oc_input_state* state);
ORCA_API oc_str8 oc_clipboard_pasted_text(oc_input_state* state); ORCA_API oc_str8 oc_clipboard_pasted_text(oc_input_state* state);

View File

@ -190,7 +190,7 @@ oc_ui_key oc_ui_key_make_path(oc_str8_list path)
{ {
seed = parent->key.hash; seed = parent->key.hash;
} }
oc_list_for(&path.list, elt, oc_str8_elt, listElt) oc_list_for(path.list, elt, oc_str8_elt, listElt)
{ {
seed = oc_hash_xx64_string_seed(elt->string, seed); seed = oc_hash_xx64_string_seed(elt->string, seed);
} }
@ -214,7 +214,7 @@ oc_ui_box* oc_ui_box_lookup_key(oc_ui_key key)
oc_ui_context* ui = oc_ui_get_context(); oc_ui_context* ui = oc_ui_get_context();
u64 index = key.hash & (OC_UI_BOX_MAP_BUCKET_COUNT - 1); u64 index = key.hash & (OC_UI_BOX_MAP_BUCKET_COUNT - 1);
oc_list_for(&ui->boxMap[index], box, oc_ui_box, bucketElt) oc_list_for(ui->boxMap[index], box, oc_ui_box, bucketElt)
{ {
if(oc_ui_key_equal(key, box->key)) if(oc_ui_key_equal(key, box->key))
{ {
@ -331,7 +331,7 @@ void oc_ui_style_box_after(oc_ui_box* box, oc_ui_pattern pattern, oc_ui_style* s
void oc_ui_process_event(oc_event* event) void oc_ui_process_event(oc_event* event)
{ {
oc_ui_context* ui = oc_ui_get_context(); oc_ui_context* ui = oc_ui_get_context();
oc_input_process_event(&ui->input, &ui->frameArena, event); oc_input_process_event(&ui->frameArena, &ui->input, event);
} }
oc_vec2 oc_ui_mouse_position(void) oc_vec2 oc_ui_mouse_position(void)
@ -450,14 +450,14 @@ oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags)
ui->nextBoxTags = (oc_list){ 0 }; ui->nextBoxTags = (oc_list){ 0 };
box->beforeRules = ui->nextBoxBeforeRules; box->beforeRules = ui->nextBoxBeforeRules;
oc_list_for(&box->beforeRules, rule, oc_ui_style_rule, boxElt) oc_list_for(box->beforeRules, rule, oc_ui_style_rule, boxElt)
{ {
rule->owner = box; rule->owner = box;
} }
ui->nextBoxBeforeRules = (oc_list){ 0 }; ui->nextBoxBeforeRules = (oc_list){ 0 };
box->afterRules = ui->nextBoxAfterRules; box->afterRules = ui->nextBoxAfterRules;
oc_list_for(&box->afterRules, rule, oc_ui_style_rule, boxElt) oc_list_for(box->afterRules, rule, oc_ui_style_rule, boxElt)
{ {
rule->owner = box; rule->owner = box;
} }
@ -854,7 +854,7 @@ bool oc_ui_style_selector_match(oc_ui_box* box, oc_ui_style_rule* rule, oc_ui_se
case OC_UI_SEL_TAG: case OC_UI_SEL_TAG:
{ {
oc_list_for(&box->tags, elt, oc_ui_tag_elt, listElt) oc_list_for(box->tags, elt, oc_ui_tag_elt, listElt)
{ {
if(elt->tag.hash == selector->tag.hash) if(elt->tag.hash == selector->tag.hash)
{ {
@ -893,14 +893,14 @@ bool oc_ui_style_selector_match(oc_ui_box* box, oc_ui_style_rule* rule, oc_ui_se
void oc_ui_style_rule_match(oc_ui_context* ui, oc_ui_box* box, oc_ui_style_rule* rule, oc_list* buildList, oc_list* tmpList) void oc_ui_style_rule_match(oc_ui_context* ui, oc_ui_box* box, oc_ui_style_rule* rule, oc_list* buildList, oc_list* tmpList)
{ {
oc_ui_selector* selector = oc_list_first_entry(&rule->pattern.l, oc_ui_selector, listElt); oc_ui_selector* selector = oc_list_first_entry(rule->pattern.l, oc_ui_selector, listElt);
bool match = oc_ui_style_selector_match(box, rule, selector); bool match = oc_ui_style_selector_match(box, rule, selector);
selector = oc_list_next_entry(&rule->pattern.l, selector, oc_ui_selector, listElt); selector = oc_list_next_entry(rule->pattern.l, selector, oc_ui_selector, listElt);
while(match && selector && selector->op == OC_UI_SEL_AND) while(match && selector && selector->op == OC_UI_SEL_AND)
{ {
match = match && oc_ui_style_selector_match(box, rule, selector); match = match && oc_ui_style_selector_match(box, rule, selector);
selector = oc_list_next_entry(&rule->pattern.l, selector, oc_ui_selector, listElt); selector = oc_list_next_entry(rule->pattern.l, selector, oc_ui_selector, listElt);
} }
if(match) if(match)
@ -935,27 +935,27 @@ void oc_ui_styling_prepass(oc_ui_context* ui, oc_ui_box* box, oc_list* before, o
//NOTE: append box before rules to before and tmp //NOTE: append box before rules to before and tmp
oc_list tmpBefore = { 0 }; oc_list tmpBefore = { 0 };
oc_list_for(&box->beforeRules, rule, oc_ui_style_rule, boxElt) oc_list_for(box->beforeRules, rule, oc_ui_style_rule, boxElt)
{ {
oc_list_append(before, &rule->buildElt); oc_list_append(before, &rule->buildElt);
oc_list_append(&tmpBefore, &rule->tmpElt); oc_list_append(&tmpBefore, &rule->tmpElt);
} }
//NOTE: match before rules //NOTE: match before rules
oc_list_for(before, rule, oc_ui_style_rule, buildElt) oc_list_for(*before, rule, oc_ui_style_rule, buildElt)
{ {
oc_ui_style_rule_match(ui, box, rule, before, &tmpBefore); oc_ui_style_rule_match(ui, box, rule, before, &tmpBefore);
} }
//NOTE: prepend box after rules to after and append them to tmp //NOTE: prepend box after rules to after and append them to tmp
oc_list tmpAfter = { 0 }; oc_list tmpAfter = { 0 };
oc_list_for_reverse(&box->afterRules, rule, oc_ui_style_rule, boxElt) oc_list_for_reverse(box->afterRules, rule, oc_ui_style_rule, boxElt)
{ {
oc_list_push(after, &rule->buildElt); oc_list_push(after, &rule->buildElt);
oc_list_append(&tmpAfter, &rule->tmpElt); oc_list_append(&tmpAfter, &rule->tmpElt);
} }
//NOTE: match after rules //NOTE: match after rules
oc_list_for(after, rule, oc_ui_style_rule, buildElt) oc_list_for(*after, rule, oc_ui_style_rule, buildElt)
{ {
oc_ui_style_rule_match(ui, box, rule, after, &tmpAfter); oc_ui_style_rule_match(ui, box, rule, after, &tmpAfter);
} }
@ -996,17 +996,17 @@ void oc_ui_styling_prepass(oc_ui_context* ui, oc_ui_box* box, oc_list* before, o
} }
//NOTE: descend in children //NOTE: descend in children
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
oc_ui_styling_prepass(ui, child, before, after); oc_ui_styling_prepass(ui, child, before, after);
} }
//NOTE: remove temporary rules //NOTE: remove temporary rules
oc_list_for(&tmpBefore, rule, oc_ui_style_rule, tmpElt) oc_list_for(tmpBefore, rule, oc_ui_style_rule, tmpElt)
{ {
oc_list_remove(before, &rule->buildElt); oc_list_remove(before, &rule->buildElt);
} }
oc_list_for(&tmpAfter, rule, oc_ui_style_rule, tmpElt) oc_list_for(tmpAfter, rule, oc_ui_style_rule, tmpElt)
{ {
oc_list_remove(after, &rule->buildElt); oc_list_remove(after, &rule->buildElt);
} }
@ -1024,7 +1024,7 @@ void oc_ui_layout_downward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int
{ {
//NOTE: layout children and compute spacing //NOTE: layout children and compute spacing
f32 count = 0; f32 count = 0;
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(!oc_ui_box_hidden(child)) if(!oc_ui_box_hidden(child))
{ {
@ -1048,7 +1048,7 @@ void oc_ui_layout_downward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int
if(box->style.layout.axis == axis) if(box->style.layout.axis == axis)
{ {
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(oc_ui_layout_downward_dependency(child, axis)) if(oc_ui_layout_downward_dependency(child, axis))
{ {
@ -1058,7 +1058,7 @@ void oc_ui_layout_downward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int
} }
else else
{ {
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(oc_ui_layout_downward_dependency(child, axis)) if(oc_ui_layout_downward_dependency(child, axis))
{ {
@ -1078,7 +1078,7 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
f32 margin = box->style.layout.margin.c[axis]; f32 margin = box->style.layout.margin.c[axis];
f32 availableSize = oc_max(0, box->rect.c[2 + axis] - box->spacing[axis] - 2 * margin); f32 availableSize = oc_max(0, box->rect.c[2 + axis] - box->spacing[axis] - 2 * margin);
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
oc_ui_size* size = &child->style.size.c[axis]; oc_ui_size* size = &child->style.size.c[axis];
if(size->kind == OC_UI_SIZE_PARENT) if(size->kind == OC_UI_SIZE_PARENT)
@ -1101,7 +1101,7 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
// total slack available // total slack available
f32 slack = 0; f32 slack = 0;
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(!oc_ui_box_hidden(child) if(!oc_ui_box_hidden(child)
&& !child->style.floating.c[axis]) && !child->style.floating.c[axis])
@ -1119,7 +1119,7 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
f32 alpha = oc_clamp(excess / slack, 0, 1); f32 alpha = oc_clamp(excess / slack, 0, 1);
sum = 0; sum = 0;
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
f32 relax = child->style.size.c[axis].relax; f32 relax = child->style.size.c[axis].relax;
child->rect.c[2 + axis] -= alpha * child->rect.c[2 + axis] * relax; child->rect.c[2 + axis] -= alpha * child->rect.c[2 + axis] * relax;
@ -1132,7 +1132,7 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
//NOTE: if we're solving on the secondary axis, we remove excess to each box individually //NOTE: if we're solving on the secondary axis, we remove excess to each box individually
// according to its own slack. Children sum is the maximum child size. // according to its own slack. Children sum is the maximum child size.
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(!oc_ui_box_hidden(child) && !child->style.floating.c[axis]) if(!oc_ui_box_hidden(child) && !child->style.floating.c[axis])
{ {
@ -1151,7 +1151,7 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
box->childrenSum[axis] = sum; box->childrenSum[axis] = sum;
//NOTE: recurse in children //NOTE: recurse in children
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
oc_ui_layout_upward_dependent_size(ui, child, axis); oc_ui_layout_upward_dependent_size(ui, child, axis);
} }
@ -1201,7 +1201,7 @@ void oc_ui_layout_compute_rect(oc_ui_context* ui, oc_ui_box* box, oc_vec2 pos)
currentPos.x -= box->scroll.x; currentPos.x -= box->scroll.x;
currentPos.y -= box->scroll.y; currentPos.y -= box->scroll.y;
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
if(align[secondAxis] == OC_UI_ALIGN_CENTER) if(align[secondAxis] == OC_UI_ALIGN_CENTER)
{ {
@ -1250,7 +1250,7 @@ void oc_ui_layout_find_next_hovered_recursive(oc_ui_context* ui, oc_ui_box* box,
} }
if(hit || !(box->flags & OC_UI_FLAG_CLIP)) if(hit || !(box->flags & OC_UI_FLAG_CLIP))
{ {
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
oc_ui_layout_find_next_hovered_recursive(ui, child, p); oc_ui_layout_find_next_hovered_recursive(ui, child, p);
} }
@ -1272,7 +1272,7 @@ void oc_ui_solve_layout(oc_ui_context* ui)
oc_ui_styling_prepass(ui, ui->root, &beforeRules, &afterRules); oc_ui_styling_prepass(ui, ui->root, &beforeRules, &afterRules);
//NOTE: reparent overlay boxes //NOTE: reparent overlay boxes
oc_list_for(&ui->overlayList, box, oc_ui_box, overlayElt) oc_list_for(ui->overlayList, box, oc_ui_box, overlayElt)
{ {
if(box->parent) if(box->parent)
{ {
@ -1368,7 +1368,7 @@ void oc_ui_draw_box(oc_ui_box* box)
box->drawProc(box, box->drawData); box->drawProc(box, box->drawData);
} }
oc_list_for(&box->children, child, oc_ui_box, listElt) oc_list_for(box->children, child, oc_ui_box, listElt)
{ {
oc_ui_draw_box(child); oc_ui_draw_box(child);
} }
@ -1518,7 +1518,7 @@ void oc_ui_end_frame(void)
//NOTE: prune unused boxes //NOTE: prune unused boxes
for(int i = 0; i < OC_UI_BOX_MAP_BUCKET_COUNT; i++) for(int i = 0; i < OC_UI_BOX_MAP_BUCKET_COUNT; i++)
{ {
oc_list_for_safe(&ui->boxMap[i], box, oc_ui_box, bucketElt) oc_list_for_safe(ui->boxMap[i], box, oc_ui_box, bucketElt)
{ {
if(box->frameCounter < ui->frameCounter) if(box->frameCounter < ui->frameCounter)
{ {
@ -3806,7 +3806,7 @@ oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8
ui->editMark = oc_clamp(ui->editMark, 0, codepoints.len); ui->editMark = oc_clamp(ui->editMark, 0, codepoints.len);
//NOTE replace selection with input codepoints //NOTE replace selection with input codepoints
oc_str32 input = oc_input_text_utf32(&ui->input, &ui->frameArena); oc_str32 input = oc_input_text_utf32(&ui->frameArena, &ui->input);
if(input.len) if(input.len)
{ {
codepoints = oc_ui_edit_replace_selection_with_codepoints(ui, codepoints, input); codepoints = oc_ui_edit_replace_selection_with_codepoints(ui, codepoints, input);

View File

@ -21,12 +21,16 @@ extern "C" {
// Intrusive linked lists // Intrusive linked lists
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#define oc_list_entry(ptr, type, member) \ #define oc_list_begin(l) (l).first
oc_container_of(ptr, type, member) #define oc_list_end(l) ((oc_list_elt*)0)
#define oc_list_last(l) (l).last
#define oc_list_next(elt) (elt)->next #define oc_list_next(elt) (elt)->next
#define oc_list_prev(elt) (elt)->prev #define oc_list_prev(elt) (elt)->prev
#define oc_list_entry(ptr, type, member) \
oc_container_of(ptr, type, member)
#define oc_list_next_entry(list, elt, type, member) \ #define oc_list_next_entry(list, elt, type, member) \
((elt->member.next != oc_list_end(list)) ? oc_list_entry(elt->member.next, type, member) : 0) ((elt->member.next != oc_list_end(list)) ? oc_list_entry(elt->member.next, type, member) : 0)
@ -59,7 +63,7 @@ extern "C" {
elt = __tmp, \ elt = __tmp, \
__tmp = elt ? oc_list_checked_entry(elt->member.next, type, member) : 0) __tmp = elt ? oc_list_checked_entry(elt->member.next, type, member) : 0)
#define oc_list_pop_entry(list, type, member) (oc_list_empty(list) ? 0 : oc_list_entry(oc_list_pop(list), type, member)) #define oc_list_pop_entry(list, type, member) (oc_list_empty(*list) ? 0 : oc_list_entry(oc_list_pop(list), type, member))
typedef struct oc_list_elt oc_list_elt; typedef struct oc_list_elt oc_list_elt;
@ -80,21 +84,6 @@ static inline void oc_list_init(oc_list* list)
list->first = list->last = 0; list->first = list->last = 0;
} }
static inline oc_list_elt* oc_list_begin(oc_list* list)
{
return (list->first);
}
static inline oc_list_elt* oc_list_end(oc_list* list)
{
return (0);
}
static inline oc_list_elt* oc_list_last(oc_list* list)
{
return (list->last);
}
static inline void oc_list_insert(oc_list* list, oc_list_elt* afterElt, oc_list_elt* elt) static inline void oc_list_insert(oc_list* list, oc_list_elt* afterElt, oc_list_elt* elt)
{ {
elt->prev = afterElt; elt->prev = afterElt;
@ -170,8 +159,8 @@ static inline void oc_list_push(oc_list* list, oc_list_elt* elt)
static inline oc_list_elt* oc_list_pop(oc_list* list) static inline oc_list_elt* oc_list_pop(oc_list* list)
{ {
oc_list_elt* elt = oc_list_begin(list); oc_list_elt* elt = oc_list_begin(*list);
if(elt != oc_list_end(list)) if(elt != oc_list_end(*list))
{ {
oc_list_remove(list, elt); oc_list_remove(list, elt);
return (elt); return (elt);
@ -201,8 +190,8 @@ static inline void oc_list_push_back(oc_list* list, oc_list_elt* elt)
static inline oc_list_elt* oc_list_pop_back(oc_list* list) static inline oc_list_elt* oc_list_pop_back(oc_list* list)
{ {
oc_list_elt* elt = oc_list_last(list); oc_list_elt* elt = oc_list_last(*list);
if(elt != oc_list_end(list)) if(elt != oc_list_end(*list))
{ {
oc_list_remove(list, elt); oc_list_remove(list, elt);
return (elt); return (elt);
@ -213,9 +202,9 @@ static inline oc_list_elt* oc_list_pop_back(oc_list* list)
} }
} }
static inline bool oc_list_empty(oc_list* list) static inline bool oc_list_empty(oc_list list)
{ {
return (list->first == 0 || list->last == 0); return (list.first == 0 || list.last == 0);
} }
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -69,7 +69,7 @@ void oc_arena_init_with_options(oc_arena* arena, oc_arena_options* options)
void oc_arena_cleanup(oc_arena* arena) void oc_arena_cleanup(oc_arena* arena)
{ {
oc_list_for_safe(&arena->chunks, chunk, oc_arena_chunk, listElt) oc_list_for_safe(arena->chunks, chunk, oc_arena_chunk, listElt)
{ {
oc_base_release(arena->base, chunk, chunk->cap); oc_base_release(arena->base, chunk, chunk->cap);
} }
@ -85,7 +85,7 @@ void* oc_arena_push(oc_arena* arena, u64 size)
u64 lastCap = chunk->cap; u64 lastCap = chunk->cap;
while(nextOffset > chunk->cap) while(nextOffset > chunk->cap)
{ {
chunk = oc_list_next_entry(&arena->chunks, chunk, oc_arena_chunk, listElt); chunk = oc_list_next_entry(arena->chunks, chunk, oc_arena_chunk, listElt);
if(chunk) if(chunk)
{ {
nextOffset = chunk->offset + size; nextOffset = chunk->offset + size;
@ -123,11 +123,11 @@ void* oc_arena_push(oc_arena* arena, u64 size)
void oc_arena_clear(oc_arena* arena) void oc_arena_clear(oc_arena* arena)
{ {
oc_list_for(&arena->chunks, chunk, oc_arena_chunk, listElt) oc_list_for(arena->chunks, chunk, oc_arena_chunk, listElt)
{ {
chunk->offset = sizeof(oc_arena_chunk); chunk->offset = sizeof(oc_arena_chunk);
} }
arena->currentChunk = oc_list_first_entry(&arena->chunks, oc_arena_chunk, listElt); arena->currentChunk = oc_list_first_entry(arena->chunks, oc_arena_chunk, listElt);
} }
oc_arena_scope oc_arena_scope_begin(oc_arena* arena) oc_arena_scope oc_arena_scope_begin(oc_arena* arena)
@ -167,7 +167,7 @@ void oc_pool_cleanup(oc_pool* pool)
void* oc_pool_alloc(oc_pool* pool) void* oc_pool_alloc(oc_pool* pool)
{ {
if(oc_list_empty(&pool->freeList)) if(oc_list_empty(pool->freeList))
{ {
return (oc_arena_push(&pool->arena, pool->blockSize)); return (oc_arena_push(&pool->arena, pool->blockSize));
} }

View File

@ -14,13 +14,13 @@
oc_str8 oc_str8_from_buffer(u64 len, char* buffer) oc_str8 oc_str8_from_buffer(u64 len, char* buffer)
{ {
return ((oc_str8){.ptr = buffer , .len = len}); return ((oc_str8){ .ptr = buffer, .len = len });
} }
oc_str8 oc_str8_slice(oc_str8 s, u64 start, u64 end) oc_str8 oc_str8_slice(oc_str8 s, u64 start, u64 end)
{ {
OC_ASSERT(start <= end && start <= s.len && end <= s.len); OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str8){.ptr = s.ptr + start , .len = end - start}); return ((oc_str8){ .ptr = s.ptr + start, .len = end - start });
} }
oc_str8 oc_str8_push_buffer(oc_arena* arena, u64 len, char* buffer) oc_str8 oc_str8_push_buffer(oc_arena* arena, u64 len, char* buffer)
@ -136,15 +136,15 @@ oc_str8 oc_str8_list_collate(oc_arena* arena, oc_str8_list list, oc_str8 prefix,
memcpy(dst, prefix.ptr, prefix.len); memcpy(dst, prefix.ptr, prefix.len);
dst += prefix.len; dst += prefix.len;
oc_str8_elt* elt = oc_list_first_entry(&list.list, oc_str8_elt, listElt); oc_str8_elt* elt = oc_list_first_entry(list.list, oc_str8_elt, listElt);
if(elt) if(elt)
{ {
memcpy(dst, elt->string.ptr, elt->string.len); memcpy(dst, elt->string.ptr, elt->string.len);
dst += elt->string.len; dst += elt->string.len;
elt = oc_list_next_entry(&list.list, elt, oc_str8_elt, listElt); elt = oc_list_next_entry(list.list, elt, oc_str8_elt, listElt);
} }
for(; elt != 0; elt = oc_list_next_entry(&list.list, elt, oc_str8_elt, listElt)) for(; elt != 0; elt = oc_list_next_entry(list.list, elt, oc_str8_elt, listElt))
{ {
memcpy(dst, separator.ptr, separator.len); memcpy(dst, separator.ptr, separator.len);
dst += separator.len; dst += separator.len;
@ -158,7 +158,7 @@ oc_str8 oc_str8_list_collate(oc_arena* arena, oc_str8_list list, oc_str8 prefix,
oc_str8 oc_str8_list_join(oc_arena* arena, oc_str8_list list) oc_str8 oc_str8_list_join(oc_arena* arena, oc_str8_list list)
{ {
oc_str8 empty = {.ptr = 0 , .len = 0}; oc_str8 empty = { .ptr = 0, .len = 0 };
return (oc_str8_list_collate(arena, list, empty, empty, empty)); return (oc_str8_list_collate(arena, list, empty, empty, empty));
} }
@ -174,7 +174,7 @@ oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list separators
{ {
//NOTE(martin): search all separators and try to match them to the current ptr //NOTE(martin): search all separators and try to match them to the current ptr
oc_str8* foundSep = 0; oc_str8* foundSep = 0;
oc_list_for(&separators.list, elt, oc_str8_elt, listElt) oc_list_for(separators.list, elt, oc_str8_elt, listElt)
{ {
oc_str8* separator = &elt->string; oc_str8* separator = &elt->string;
bool equal = true; bool equal = true;
@ -221,13 +221,13 @@ oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list separators
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
oc_str16 oc_str16_from_buffer(u64 len, u16* buffer) oc_str16 oc_str16_from_buffer(u64 len, u16* buffer)
{ {
return ((oc_str16){.ptr = buffer , .len = len}); return ((oc_str16){ .ptr = buffer, .len = len });
} }
oc_str16 oc_str16_slice(oc_str16 s, u64 start, u64 end) oc_str16 oc_str16_slice(oc_str16 s, u64 start, u64 end)
{ {
OC_ASSERT(start <= end && start <= s.len && end <= s.len); OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str16){.ptr = s.ptr + start , .len = end - start}); return ((oc_str16){ .ptr = s.ptr + start, .len = end - start });
} }
oc_str16 oc_str16_push_buffer(oc_arena* arena, u64 len, u16* buffer) oc_str16 oc_str16_push_buffer(oc_arena* arena, u64 len, u16* buffer)
@ -276,15 +276,15 @@ oc_str16 oc_str16_list_collate(oc_arena* arena, oc_str16_list list, oc_str16 pre
memcpy(dst, prefix.ptr, prefix.len * sizeof(u16)); memcpy(dst, prefix.ptr, prefix.len * sizeof(u16));
dst += prefix.len * sizeof(u16); dst += prefix.len * sizeof(u16);
oc_str16_elt* elt = oc_list_first_entry(&list.list, oc_str16_elt, listElt); oc_str16_elt* elt = oc_list_first_entry(list.list, oc_str16_elt, listElt);
if(elt) if(elt)
{ {
memcpy(dst, elt->string.ptr, elt->string.len * sizeof(u16)); memcpy(dst, elt->string.ptr, elt->string.len * sizeof(u16));
dst += elt->string.len * sizeof(u16); dst += elt->string.len * sizeof(u16);
elt = oc_list_next_entry(&list.list, elt, oc_str16_elt, listElt); elt = oc_list_next_entry(list.list, elt, oc_str16_elt, listElt);
} }
for(; elt != 0; elt = oc_list_next_entry(&list.list, elt, oc_str16_elt, listElt)) for(; elt != 0; elt = oc_list_next_entry(list.list, elt, oc_str16_elt, listElt))
{ {
memcpy(dst, separator.ptr, separator.len * sizeof(u16)); memcpy(dst, separator.ptr, separator.len * sizeof(u16));
dst += separator.len * sizeof(u16); dst += separator.len * sizeof(u16);
@ -298,7 +298,7 @@ oc_str16 oc_str16_list_collate(oc_arena* arena, oc_str16_list list, oc_str16 pre
oc_str16 oc_str16_list_join(oc_arena* arena, oc_str16_list list) oc_str16 oc_str16_list_join(oc_arena* arena, oc_str16_list list)
{ {
oc_str16 empty = {.ptr = 0 , .len = 0}; oc_str16 empty = { .ptr = 0, .len = 0 };
return (oc_str16_list_collate(arena, list, empty, empty, empty)); return (oc_str16_list_collate(arena, list, empty, empty, empty));
} }
@ -307,13 +307,13 @@ oc_str16 oc_str16_list_join(oc_arena* arena, oc_str16_list list)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
oc_str32 oc_str32_from_buffer(u64 len, u32* buffer) oc_str32 oc_str32_from_buffer(u64 len, u32* buffer)
{ {
return ((oc_str32){.ptr = buffer , .len = len}); return ((oc_str32){ .ptr = buffer, .len = len });
} }
oc_str32 oc_str32_slice(oc_str32 s, u64 start, u64 end) oc_str32 oc_str32_slice(oc_str32 s, u64 start, u64 end)
{ {
OC_ASSERT(start <= end && start <= s.len && end <= s.len); OC_ASSERT(start <= end && start <= s.len && end <= s.len);
return ((oc_str32){.ptr = s.ptr + start , .len = end - start}); return ((oc_str32){ .ptr = s.ptr + start, .len = end - start });
} }
oc_str32 oc_str32_push_buffer(oc_arena* arena, u64 len, u32* buffer) oc_str32 oc_str32_push_buffer(oc_arena* arena, u64 len, u32* buffer)
@ -362,15 +362,15 @@ oc_str32 oc_str32_list_collate(oc_arena* arena, oc_str32_list list, oc_str32 pre
memcpy(dst, prefix.ptr, prefix.len * sizeof(u32)); memcpy(dst, prefix.ptr, prefix.len * sizeof(u32));
dst += prefix.len * sizeof(u32); dst += prefix.len * sizeof(u32);
oc_str32_elt* elt = oc_list_first_entry(&list.list, oc_str32_elt, listElt); oc_str32_elt* elt = oc_list_first_entry(list.list, oc_str32_elt, listElt);
if(elt) if(elt)
{ {
memcpy(dst, elt->string.ptr, elt->string.len * sizeof(u32)); memcpy(dst, elt->string.ptr, elt->string.len * sizeof(u32));
dst += elt->string.len * sizeof(u32); dst += elt->string.len * sizeof(u32);
elt = oc_list_next_entry(&list.list, elt, oc_str32_elt, listElt); elt = oc_list_next_entry(list.list, elt, oc_str32_elt, listElt);
} }
for(; elt != 0; elt = oc_list_next_entry(&list.list, elt, oc_str32_elt, listElt)) for(; elt != 0; elt = oc_list_next_entry(list.list, elt, oc_str32_elt, listElt))
{ {
memcpy(dst, separator.ptr, separator.len * sizeof(u32)); memcpy(dst, separator.ptr, separator.len * sizeof(u32));
dst += separator.len * sizeof(u32); dst += separator.len * sizeof(u32);
@ -384,6 +384,6 @@ oc_str32 oc_str32_list_collate(oc_arena* arena, oc_str32_list list, oc_str32 pre
oc_str32 oc_str32_list_join(oc_arena* arena, oc_str32_list list) oc_str32 oc_str32_list_join(oc_arena* arena, oc_str32_list list)
{ {
oc_str32 empty = {.ptr = 0 , .len = 0}; oc_str32 empty = { .ptr = 0, .len = 0 };
return (oc_str32_list_collate(arena, list, empty, empty, empty)); return (oc_str32_list_collate(arena, list, empty, empty, empty));
} }

View File

@ -12,7 +12,7 @@ int main(int argc, char** argv)
{ {
oc_init(); oc_init();
oc_arena_scope* scratch = oc_scratch_begin(); oc_arena_scope scratch = oc_scratch_begin();
oc_str8 path = oc_path_executable_relative(scratch.arena, OC_STR8("../")); oc_str8 path = oc_path_executable_relative(scratch.arena, OC_STR8("../"));
oc_file dir = oc_file_open(path, OC_FILE_ACCESS_READ, 0); oc_file dir = oc_file_open(path, OC_FILE_ACCESS_READ, 0);
@ -36,7 +36,7 @@ int main(int argc, char** argv)
else else
{ {
oc_log_info("Selected files:\n"); oc_log_info("Selected files:\n");
oc_list_for(&res.selection.list, elt, oc_str8_elt, listElt) oc_list_for(res.selection.list, elt, oc_str8_elt, listElt)
{ {
oc_log_info("\t%.*s\n", (int)elt->string.len, elt->string.ptr); oc_log_info("\t%.*s\n", (int)elt->string.len, elt->string.ptr);
} }

View File

@ -1 +0,0 @@
bin

View File

@ -1,5 +0,0 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/test_open_dialog.exe
copy ..\..\build\bin\orca.dll bin

View File

@ -1,18 +0,0 @@
#!/bin/bash
LIBDIR=../../build/bin
SRCDIR=../../src
INCLUDES="-I$SRCDIR"
LIBS="-L$LIBDIR -lorca"
FLAGS="-mmacos-version-min=10.15.4 -DOC_DEBUG -DLOG_COMPILE_DEBUG"
if [ ! \( -e bin \) ] ; then
mkdir ./bin
fi
clang -g $FLAGS $LIBS $INCLUDES -o ./bin/test_open_dialog main.c
cp $LIBDIR/liborca.dylib ./bin/
install_name_tool -add_rpath "@executable_path" ./bin/test_open_dialog

View File

@ -1,39 +0,0 @@
/*************************************************************************
*
* Orca
* Copyright 2023 Martin Fouilleul and the Orca project contributors
* See LICENSE.txt for licensing information
*
**************************************************************************/
#include "orca.h"
int main(int argc, char** argv)
{
oc_init();
oc_file_dialog_desc desc = {
.kind = OC_FILE_DIALOG_OPEN,
.flags = OC_FILE_DIALOG_FILES,
.title = OC_STR8("Select Files"),
.okLabel = OC_STR8("Select")
};
oc_arena_scope* scratch = oc_scratch_begin();
oc_str8_list_push(scratch.arena, &desc.filters, OC_STR8("txt"));
oc_file file = oc_file_open_with_dialog(OC_FILE_ACCESS_READ, 0, &desc);
if(oc_file_is_nil(file))
{
oc_log_error("Couldn't open file\n");
}
else
{
char buffer[1024];
u64 len = oc_file_read(file, 1024, buffer);
oc_log_info("file contents: %.*s\n", (int)len, buffer);
}
return (0);
}

View File

@ -1 +0,0 @@
The quick brown fox jumps over the lazy dog