From 425d9b3448b015cfc29cdc26324252f7d7792d9c Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Tue, 5 Sep 2023 16:25:04 +0200 Subject: [PATCH] - Added basic cheatsheets - Minor cleanups: - Hiding some native-only path APIs - Re-formatting ui.h --- doc/cheatsheet_app.h | 35 ++ doc/cheatsheet_graphics.h | 162 ++++++ doc/cheatsheet_io.h | 39 ++ doc/cheatsheet_ui.h | 64 +++ doc/cheatsheet_util.h | 101 ++++ src/orca.c | 1 + src/platform/platform_path.c | 4 + src/platform/platform_path.h | 5 + src/ui/ui.h | 927 +++++++++++++++++------------------ 9 files changed, 874 insertions(+), 464 deletions(-) create mode 100644 doc/cheatsheet_app.h create mode 100644 doc/cheatsheet_graphics.h create mode 100644 doc/cheatsheet_io.h create mode 100644 doc/cheatsheet_ui.h create mode 100644 doc/cheatsheet_util.h diff --git a/doc/cheatsheet_app.h b/doc/cheatsheet_app.h new file mode 100644 index 0000000..de085c6 --- /dev/null +++ b/doc/cheatsheet_app.h @@ -0,0 +1,35 @@ +/************************************************************/ /** +* +* @file: cheatsheet_app.h +* @author: Martin Fouilleul +* @date: 05/09/2023 +* +*****************************************************************/ + +//---------------------------------------------------------------- +// Handlers (can be defined by your app to respond to events) +//---------------------------------------------------------------- +void oc_on_init(void); +void oc_on_mouse_down(oc_mouse_button button); +void oc_on_mouse_up(oc_mouse_button button); +void oc_on_mouse_enter(void); +void oc_on_mouse_leave(void); +void oc_on_mouse_move(f32 x, f32 y, f32 deltaX, f32 deltaY); +void oc_on_mouse_wheel(f32 deltaX, f32 deltaY); +void oc_on_key_down(oc_key_code key); +void oc_on_key_up(oc_key_code key); +void oc_on_frame_refresh(void); +void oc_on_resize(f32 width, f32 height); +void oc_on_raw_event(oc_event* event); +void oc_on_terminate(void); + +//---------------------------------------------------------------- +// Window +//---------------------------------------------------------------- +void oc_window_set_title(oc_str8 title); +void oc_window_set_size(oc_vec2 size); + +//---------------------------------------------------------------- +// Quitting +//---------------------------------------------------------------- +void oc_request_quit(void) diff --git a/doc/cheatsheet_graphics.h b/doc/cheatsheet_graphics.h new file mode 100644 index 0000000..f683bac --- /dev/null +++ b/doc/cheatsheet_graphics.h @@ -0,0 +1,162 @@ +/************************************************************/ /** +* +* @file: cheatsheet_graphics.h +* @author: Martin Fouilleul +* @date: 05/09/2023 +* +*****************************************************************/ + +//------------------------------------------------------------------------------------------ +// graphics surface +//------------------------------------------------------------------------------------------ +oc_surface oc_surface_nil(void); +bool oc_surface_is_nil(oc_surface surface); +oc_surface oc_surface_canvas(); +oc_surface oc_surface_gles(); +void oc_surface_destroy(oc_surface surface); + +void oc_surface_select(oc_surface surface); +void oc_surface_present(oc_surface surface); +void oc_surface_deselect(void); + +oc_vec2 oc_surface_get_size(oc_surface surface); +oc_vec2 oc_surface_contents_scaling(oc_surface surface); +void oc_surface_bring_to_front(oc_surface surface); +void oc_surface_send_to_back(oc_surface surface); + +//------------------------------------------------------------------------------------------ +// 2D canvas command buffer +//------------------------------------------------------------------------------------------ +oc_canvas oc_canvas_nil(void); +bool oc_canvas_is_nil(oc_canvas canvas); +oc_canvas oc_canvas_create(void); +void oc_canvas_destroy(oc_canvas canvas); +oc_canvas oc_canvas_set_current(oc_canvas canvas); +void oc_render(oc_surface surface, oc_canvas canvas); + +//------------------------------------------------------------------------------------------ +// transform and clipping +//------------------------------------------------------------------------------------------ + +void oc_matrix_push(oc_mat2x3 matrix); +void oc_matrix_pop(void); +oc_mat2x3 oc_matrix_top(); + +void oc_clip_push(f32 x, f32 y, f32 w, f32 h); +void oc_clip_pop(void); +oc_rect oc_clip_top(); + +//------------------------------------------------------------------------------------------ +// graphics attributes setting/getting +//------------------------------------------------------------------------------------------ +void oc_set_color(oc_color color); +void oc_set_color_rgba(f32 r, f32 g, f32 b, f32 a); +void oc_set_width(f32 width); +void oc_set_tolerance(f32 tolerance); +void oc_set_joint(oc_joint_type joint); +void oc_set_max_joint_excursion(f32 maxJointExcursion); +void oc_set_cap(oc_cap_type cap); +void oc_set_font(oc_font font); +void oc_set_font_size(f32 size); +void oc_set_text_flip(bool flip); +void oc_set_image(oc_image image); +void oc_set_image_source_region(oc_rect region); + +oc_color oc_get_color(void); +f32 oc_get_width(void); +f32 oc_get_tolerance(void); +oc_joint_type oc_get_joint(void); +f32 oc_get_max_joint_excursion(void); +oc_cap_type oc_get_cap(void); +oc_font oc_get_font(void); +f32 oc_get_font_size(void); +bool oc_get_text_flip(void); +oc_image oc_get_image(); + +//------------------------------------------------------------------------------------------ +// path construction +//------------------------------------------------------------------------------------------ +oc_vec2 oc_get_position(void); +void oc_move_to(f32 x, f32 y); +void oc_line_to(f32 x, f32 y); +void oc_quadratic_to(f32 x1, f32 y1, f32 x2, f32 y2); +void oc_cubic_to(f32 x1, f32 y1, f32 x2, f32 y2, f32 x3, f32 y3); +void oc_close_path(void); + +oc_rect oc_glyph_outlines(oc_str32 glyphIndices); +void oc_codepoints_outlines(oc_str32 string); +void oc_text_outlines(oc_str8 string); + +//------------------------------------------------------------------------------------------ +// clear/fill/stroke +//------------------------------------------------------------------------------------------ +void oc_clear(void); +void oc_fill(void); +void oc_stroke(void); + +//------------------------------------------------------------------------------------------ +// shapes helpers +//------------------------------------------------------------------------------------------ +void oc_rectangle_fill(f32 x, f32 y, f32 w, f32 h); +void oc_rectangle_stroke(f32 x, f32 y, f32 w, f32 h); +void oc_rounded_rectangle_fill(f32 x, f32 y, f32 w, f32 h, f32 r); +void oc_rounded_rectangle_stroke(f32 x, f32 y, f32 w, f32 h, f32 r); +void oc_ellipse_fill(f32 x, f32 y, f32 rx, f32 ry); +void oc_ellipse_stroke(f32 x, f32 y, f32 rx, f32 ry); +void oc_circle_fill(f32 x, f32 y, f32 r); +void oc_circle_stroke(f32 x, f32 y, f32 r); +void oc_arc(f32 x, f32 y, f32 r, f32 arcAngle, f32 startAngle); +void oc_image_draw(oc_image image, oc_rect rect); +void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion); + +//------------------------------------------------------------------------------------------ +// fonts +//------------------------------------------------------------------------------------------ +oc_font oc_font_nil(void); +bool oc_font_is_nil(oc_font font); + +oc_font oc_font_create_from_memory(oc_str8 mem, u32 rangeCount, oc_unicode_range* ranges); +void oc_font_destroy(oc_font font); + +oc_font_extents oc_font_get_extents(oc_font font); +oc_font_extents oc_font_get_scaled_extents(oc_font font, f32 emSize); +f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize); + +u32 oc_font_get_glyph_index(oc_font font, oc_utf32 codePoint); +oc_str32 oc_font_get_glyph_indices(oc_font font, oc_str32 codePoints, oc_str32 backing); +oc_str32 oc_font_push_glyph_indices(oc_font font, oc_arena* arena, oc_str32 codePoints); + +int oc_font_get_codepoint_extents(oc_font font, oc_utf32 codePoint, oc_text_extents* outExtents); +int oc_font_get_glyph_extents(oc_font font, oc_str32 glyphIndices, oc_text_extents* outExtents); + +oc_rect oc_text_bounding_box_utf32(oc_font font, f32 fontSize, oc_str32 text); +oc_rect oc_text_bounding_box(oc_font font, f32 fontSize, oc_str8 text); + +//------------------------------------------------------------------------------------------ +// images +//------------------------------------------------------------------------------------------ +oc_image oc_image_nil(void); +bool oc_image_is_nil(oc_image a); + +oc_image oc_image_create(oc_surface surface, u32 width, u32 height); +oc_image oc_image_create_from_rgba8(oc_surface surface, u32 width, u32 height, u8* pixels); +oc_image oc_image_create_from_memory(oc_surface surface, oc_str8 mem, bool flip); +oc_image oc_image_create_from_file(oc_surface surface, oc_str8 path, bool flip); + +void oc_image_destroy(oc_image image); + +void oc_image_upload_region_rgba8(oc_image image, oc_rect region, u8* pixels); +oc_vec2 oc_image_size(oc_image image); + +//------------------------------------------------------------------------------------------ +// image atlas +//------------------------------------------------------------------------------------------ + +oc_rect_atlas* oc_rect_atlas_create(oc_arena* arena, i32 width, i32 height); +oc_rect oc_rect_atlas_alloc(oc_rect_atlas* atlas, i32 width, i32 height); +void oc_rect_atlas_recycle(oc_rect_atlas* atlas, oc_rect rect); + +oc_image_region oc_image_atlas_alloc_from_rgba8(oc_rect_atlas* atlas, oc_image backingImage, u32 width, u32 height, u8* pixels); +oc_image_region oc_image_atlas_alloc_from_data(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 data, bool flip); +oc_image_region oc_image_atlas_alloc_from_file(oc_rect_atlas* atlas, oc_image backingImage, oc_str8 path, bool flip); +void oc_image_atlas_recycle(oc_rect_atlas* atlas, oc_image_region imageRgn); diff --git a/doc/cheatsheet_io.h b/doc/cheatsheet_io.h new file mode 100644 index 0000000..59d8a71 --- /dev/null +++ b/doc/cheatsheet_io.h @@ -0,0 +1,39 @@ +/************************************************************/ /** +* +* @file: cheatsheet_io.h +* @author: Martin Fouilleul +* @date: 05/09/2023 +* +*****************************************************************/ + +//---------------------------------------------------------------- +// Low-level File IO API +//---------------------------------------------------------------- +oc_io_cmp oc_io_wait_single_req(oc_io_req* req); + +//---------------------------------------------------------------- +// High-level File IO API +//---------------------------------------------------------------- +oc_file oc_file_nil(); +bool oc_file_is_nil(oc_file handle); + +oc_file oc_file_open(oc_str8 path, oc_file_access rights, oc_file_open_flags flags); +oc_file oc_file_open_at(oc_file dir, oc_str8 path, oc_file_access rights, oc_file_open_flags flags); +void oc_file_close(oc_file file); +oc_io_error oc_file_last_error(oc_file handle); + +i64 oc_file_pos(oc_file file); +i64 oc_file_seek(oc_file file, i64 offset, oc_file_whence whence); +u64 oc_file_write(oc_file file, u64 size, char* buffer); +u64 oc_file_read(oc_file file, u64 size, char* buffer); + +oc_file_status oc_file_get_status(oc_file file); +u64 oc_file_size(oc_file file); + +//---------------------------------------------------------------- +// Asking users for file capabilities +//---------------------------------------------------------------- +oc_file oc_file_open_with_request(oc_str8 path, oc_file_access rights, oc_file_open_flags flags); +oc_file_open_with_dialog_result oc_file_open_with_dialog(oc_arena* arena, oc_file_access rights, oc_file_open_flags flags, oc_file_dialog_desc* desc); + + diff --git a/doc/cheatsheet_ui.h b/doc/cheatsheet_ui.h new file mode 100644 index 0000000..3487195 --- /dev/null +++ b/doc/cheatsheet_ui.h @@ -0,0 +1,64 @@ +/************************************************************/ /** +* +* @file: cheatsheet_ui.h +* @author: Martin Fouilleul +* @date: 05/09/2023 +* +*****************************************************************/ + +//---------------------------------------------------------------- +// Context and frame lifecycle +//---------------------------------------------------------------- + +void oc_ui_init(oc_ui_context* context); +oc_ui_context* oc_ui_get_context(void); +void oc_ui_set_context(oc_ui_context* context); + +void oc_ui_process_event(oc_event* event); +void oc_ui_begin_frame(oc_vec2 size, oc_ui_style* defaultStyle, oc_ui_style_mask mask); +void oc_ui_end_frame(void); +void oc_ui_draw(void); + +#define oc_ui_frame(size, style, mask) + +//---------------------------------------------------------------- +// Common widget helpers +//---------------------------------------------------------------- + +oc_ui_sig oc_ui_label(const char* label); +oc_ui_sig oc_ui_label_str8(oc_str8 label); +oc_ui_sig oc_ui_button(const char* label); +oc_ui_sig oc_ui_checkbox(const char* name, bool* checked); +oc_ui_box* oc_ui_slider(const char* label, f32 thumbRatio, f32* scrollValue); +oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 text); +oc_ui_select_popup_info oc_ui_select_popup(const char* name, oc_ui_select_popup_info* info); + +void oc_ui_panel_begin(const char* name, oc_ui_flags flags); +void oc_ui_panel_end(void); +#define oc_ui_panel(s, f) + +void oc_ui_menu_bar_begin(const char* label); +void oc_ui_menu_bar_end(void); +#define oc_ui_menu_bar(name) + +void oc_ui_menu_begin(const char* label); +void oc_ui_menu_end(void); +#define oc_ui_menu(name) + +oc_ui_sig oc_ui_menu_button(const char* name); + +oc_ui_sig oc_ui_tooltip_begin(const char* name); +void oc_ui_tooltip_end(void); +#define oc_ui_tooltip(name) + +//------------------------------------------------------------------------------------- +// Styling +//------------------------------------------------------------------------------------- +void oc_ui_style_next(oc_ui_style* style, oc_ui_style_mask mask); + +void oc_ui_pattern_push(oc_arena* arena, oc_ui_pattern* pattern, oc_ui_selector selector); +oc_ui_pattern oc_ui_pattern_all(void); +oc_ui_pattern oc_ui_pattern_owner(void); + +void oc_ui_style_match_before(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); +void oc_ui_style_match_after(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); diff --git a/doc/cheatsheet_util.h b/doc/cheatsheet_util.h new file mode 100644 index 0000000..f6349bf --- /dev/null +++ b/doc/cheatsheet_util.h @@ -0,0 +1,101 @@ +/************************************************************/ /** +* +* @file: cheatsheet_util.h +* @author: Martin Fouilleul +* @date: 05/09/2023 +* +*****************************************************************/ + +//---------------------------------------------------------------- +// Arenas +//---------------------------------------------------------------- + +void oc_arena_init(oc_arena* arena); +void oc_arena_init_with_options(oc_arena* arena, oc_arena_options* options); +void oc_arena_cleanup(oc_arena* arena); + +void* oc_arena_push(oc_arena* arena, u64 size); +#define oc_arena_push_type(arena, type) +#define oc_arena_push_array(arena, type, count) +void oc_arena_clear(oc_arena* arena); + +oc_arena_scope oc_arena_scope_begin(oc_arena* arena); +void oc_arena_scope_end(oc_arena_scope scope); + +oc_arena_scope oc_scratch_begin(void); +oc_arena_scope oc_scratch_begin_next(oc_arena* used); +#define oc_scratch_end(scope) + +//---------------------------------------------------------------- +// Lists +//---------------------------------------------------------------- + +void oc_list_init(oc_list* list); +bool oc_list_empty(oc_list* list); + +oc_list_elt* oc_list_begin(oc_list* list); +oc_list_elt* oc_list_end(oc_list* list); +oc_list_elt* oc_list_last(oc_list* list); + +#define oc_list_next(elt) +#define oc_list_prev(elt) +#define oc_list_entry(ptr, type, member) +#define oc_list_next_entry(list, elt, type, member) +#define oc_list_prev_entry(list, elt, type, member) +#define oc_list_first_entry(list, type, member) +#define oc_list_last_entry(list, type, member) +#define oc_list_pop_entry(list, type, member) + +void oc_list_insert(oc_list* list, oc_list_elt* afterElt, oc_list_elt* elt); +void oc_list_insert_before(oc_list* list, oc_list_elt* beforeElt, oc_list_elt* elt); +void oc_list_remove(oc_list* list, oc_list_elt* elt); +void oc_list_push(oc_list* list, oc_list_elt* elt); +oc_list_elt* oc_list_pop(oc_list* list); +void oc_list_push_back(oc_list* list, oc_list_elt* elt); +oc_list_elt* oc_list_pop_back(oc_list* list); + +#define oc_list_for(list, elt, type, member) +#define oc_list_for_reverse(list, elt, type, member) +#define oc_list_for_safe(list, elt, type, member) + +//---------------------------------------------------------------- +// Strings / string lists / path strings +//---------------------------------------------------------------- + +oc_str8 oc_str8_from_buffer(u64 len, char* buffer); +oc_str8 oc_str8_slice(oc_str8 s, u64 start, u64 end); + +oc_str8 oc_str8_push_buffer(oc_arena* arena, u64 len, char* buffer); +oc_str8 oc_str8_push_cstring(oc_arena* arena, const char* str); +oc_str8 oc_str8_push_copy(oc_arena* arena, oc_str8 s); +oc_str8 oc_str8_push_slice(oc_arena* arena, oc_str8 s, u64 start, u64 end); +oc_str8 oc_str8_pushfv(oc_arena* arena, const char* format, va_list args); +oc_str8 oc_str8_pushf(oc_arena* arena, const char* format, ...); + +int oc_str8_cmp(oc_str8 s1, oc_str8 s2); + +char* oc_str8_to_cstring(oc_arena* arena, oc_str8 string); + +void oc_str8_list_push(oc_arena* arena, oc_str8_list* list, oc_str8 str); +void oc_str8_list_pushf(oc_arena* arena, oc_str8_list* list, const char* format, ...); + +oc_str8 oc_str8_list_collate(oc_arena* arena, oc_str8_list list, oc_str8 prefix, oc_str8 separator, oc_str8 postfix); +oc_str8 oc_str8_list_join(oc_arena* arena, oc_str8_list list); +oc_str8_list oc_str8_split(oc_arena* arena, oc_str8 str, oc_str8_list separators); + +oc_str8 oc_path_slice_directory(oc_str8 path); +oc_str8 oc_path_slice_filename(oc_str8 path); +oc_str8_list oc_path_split(oc_arena* arena, oc_str8 path); +oc_str8 oc_path_join(oc_arena* arena, oc_str8_list elements); +oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath); +bool oc_path_is_absolute(oc_str8 path); + +//---------------------------------------------------------------- +// Debugging +//---------------------------------------------------------------- +#define oc_log_info(message, ...) +#define oc_log_warning(message, ...) +#define oc_log_error(message, ...) + +#define OC_ASSERT(test, message, ...) +#define OC_ABORT(message, ...) diff --git a/src/orca.c b/src/orca.c index 078a89e..996f370 100644 --- a/src/orca.c +++ b/src/orca.c @@ -53,6 +53,7 @@ #include "platform/platform_io_common.c" #include "platform/orca_io_stubs.c" #include "platform/orca_platform.c" + #include "platform/platform_path.c" #else #error "Unsupported platform" #endif diff --git a/src/platform/platform_path.c b/src/platform/platform_path.c index 600ec04..9ce8eb8 100644 --- a/src/platform/platform_path.c +++ b/src/platform/platform_path.c @@ -90,6 +90,8 @@ oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath) return (result); } +#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA + oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath) { oc_str8_list list = { 0 }; @@ -103,3 +105,5 @@ oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath) oc_scratch_end(scratch); return (path); } + +#endif diff --git a/src/platform/platform_path.h b/src/platform/platform_path.h index 892a775..a74b1e1 100644 --- a/src/platform/platform_path.h +++ b/src/platform/platform_path.h @@ -8,6 +8,7 @@ #ifndef __PLATFORM_PATH_H_ #define __PLATFORM_PATH_H_ +#include"platform.h" #include "util/strings.h" /*NOTE: @@ -24,10 +25,14 @@ ORCA_API oc_str8 oc_path_join(oc_arena* arena, oc_str8_list elements); ORCA_API oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath); ORCA_API bool oc_path_is_absolute(oc_str8 path); + +#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA + ORCA_API oc_str8 oc_path_executable(oc_arena* arena); ORCA_API oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path); // helper: gets the path from oc_path_executable() and appends relPath ORCA_API oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath); +#endif #endif //__PLATFORM_PATH_H_ diff --git a/src/ui/ui.h b/src/ui/ui.h index 9e9b7a7..cfb60b5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -15,557 +15,556 @@ #include "util/typedefs.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif - typedef struct oc_ui_key +typedef struct oc_ui_key +{ + u64 hash; +} oc_ui_key; + +typedef enum +{ + OC_UI_AXIS_X, + OC_UI_AXIS_Y, + OC_UI_AXIS_COUNT +} oc_ui_axis; + +typedef enum +{ + OC_UI_ALIGN_START, + OC_UI_ALIGN_END, + OC_UI_ALIGN_CENTER, +} oc_ui_align; + +typedef union oc_ui_layout_align +{ + struct { - u64 hash; - } oc_ui_key; - - typedef enum - { - OC_UI_AXIS_X, - OC_UI_AXIS_Y, - OC_UI_AXIS_COUNT - } oc_ui_axis; - - typedef enum - { - OC_UI_ALIGN_START, - OC_UI_ALIGN_END, - OC_UI_ALIGN_CENTER, - } oc_ui_align; - - typedef union oc_ui_layout_align - { - struct - { - oc_ui_align x; - oc_ui_align y; - }; - - oc_ui_align c[OC_UI_AXIS_COUNT]; - } oc_ui_layout_align; - - typedef struct oc_ui_layout - { - oc_ui_axis axis; - f32 spacing; - - union - { - struct - { - f32 x; - f32 y; - }; - - f32 c[OC_UI_AXIS_COUNT]; - } margin; - - oc_ui_layout_align align; - - } oc_ui_layout; - - typedef enum oc_ui_size_kind - { - OC_UI_SIZE_TEXT, - OC_UI_SIZE_PIXELS, - OC_UI_SIZE_CHILDREN, - OC_UI_SIZE_PARENT, - OC_UI_SIZE_PARENT_MINUS_PIXELS, - - } oc_ui_size_kind; - - typedef struct oc_ui_size - { - oc_ui_size_kind kind; - f32 value; - f32 relax; - } oc_ui_size; - - typedef union oc_ui_box_size - { - struct - { - oc_ui_size width; - oc_ui_size height; - }; - - oc_ui_size c[OC_UI_AXIS_COUNT]; - } oc_ui_box_size; - - typedef union oc_ui_box_floating - { - struct - { - bool x; - bool y; - }; - - bool c[OC_UI_AXIS_COUNT]; - } oc_ui_box_floating; - - //NOTE: flags for axis-dependent properties (e.g. OC_UI_STYLE_FLOAT_X/Y) need to be consecutive bits - // in order to play well with axis agnostic functions - typedef u64 oc_ui_style_mask; - - enum - { - OC_UI_STYLE_NONE = 0, - OC_UI_STYLE_SIZE_WIDTH = 1 << 1, - OC_UI_STYLE_SIZE_HEIGHT = 1 << 2, - OC_UI_STYLE_LAYOUT_AXIS = 1 << 3, - OC_UI_STYLE_LAYOUT_ALIGN_X = 1 << 4, - OC_UI_STYLE_LAYOUT_ALIGN_Y = 1 << 5, - OC_UI_STYLE_LAYOUT_SPACING = 1 << 6, - OC_UI_STYLE_LAYOUT_MARGIN_X = 1 << 7, - OC_UI_STYLE_LAYOUT_MARGIN_Y = 1 << 8, - OC_UI_STYLE_FLOAT_X = 1 << 9, - OC_UI_STYLE_FLOAT_Y = 1 << 10, - OC_UI_STYLE_COLOR = 1 << 11, - OC_UI_STYLE_BG_COLOR = 1 << 12, - OC_UI_STYLE_BORDER_COLOR = 1 << 13, - OC_UI_STYLE_BORDER_SIZE = 1 << 14, - OC_UI_STYLE_ROUNDNESS = 1 << 15, - OC_UI_STYLE_FONT = 1 << 16, - OC_UI_STYLE_FONT_SIZE = 1 << 17, - OC_UI_STYLE_ANIMATION_TIME = 1 << 18, - OC_UI_STYLE_ANIMATION_MASK = 1 << 19, - - //masks - OC_UI_STYLE_SIZE = OC_UI_STYLE_SIZE_WIDTH - | OC_UI_STYLE_SIZE_HEIGHT, - - OC_UI_STYLE_LAYOUT_MARGINS = OC_UI_STYLE_LAYOUT_MARGIN_X - | OC_UI_STYLE_LAYOUT_MARGIN_Y, - - OC_UI_STYLE_LAYOUT = OC_UI_STYLE_LAYOUT_AXIS - | OC_UI_STYLE_LAYOUT_ALIGN_X - | OC_UI_STYLE_LAYOUT_ALIGN_Y - | OC_UI_STYLE_LAYOUT_SPACING - | OC_UI_STYLE_LAYOUT_MARGIN_X - | OC_UI_STYLE_LAYOUT_MARGIN_Y, - - OC_UI_STYLE_FLOAT = OC_UI_STYLE_FLOAT_X - | OC_UI_STYLE_FLOAT_Y, - - OC_UI_STYLE_MASK_INHERITED = OC_UI_STYLE_COLOR - | OC_UI_STYLE_FONT - | OC_UI_STYLE_FONT_SIZE - | OC_UI_STYLE_ANIMATION_TIME - | OC_UI_STYLE_ANIMATION_MASK, + oc_ui_align x; + oc_ui_align y; }; - typedef struct oc_ui_style - { - oc_ui_box_size size; - oc_ui_layout layout; - oc_ui_box_floating floating; - oc_vec2 floatTarget; - oc_color color; - oc_color bgColor; - oc_color borderColor; - oc_font font; - f32 fontSize; - f32 borderSize; - f32 roundness; - f32 animationTime; - oc_ui_style_mask animationMask; - } oc_ui_style; + oc_ui_align c[OC_UI_AXIS_COUNT]; +} oc_ui_layout_align; - typedef struct oc_ui_tag - { - u64 hash; - } oc_ui_tag; +typedef struct oc_ui_layout +{ + oc_ui_axis axis; + f32 spacing; - typedef enum + union { - OC_UI_SEL_ANY, - OC_UI_SEL_OWNER, - OC_UI_SEL_TEXT, - OC_UI_SEL_TAG, - OC_UI_SEL_STATUS, - OC_UI_SEL_KEY, - //... - } oc_ui_selector_kind; + struct + { + f32 x; + f32 y; + }; - typedef u8 oc_ui_status; + f32 c[OC_UI_AXIS_COUNT]; + } margin; - enum + oc_ui_layout_align align; + +} oc_ui_layout; + +typedef enum oc_ui_size_kind +{ + OC_UI_SIZE_TEXT, + OC_UI_SIZE_PIXELS, + OC_UI_SIZE_CHILDREN, + OC_UI_SIZE_PARENT, + OC_UI_SIZE_PARENT_MINUS_PIXELS, + +} oc_ui_size_kind; + +typedef struct oc_ui_size +{ + oc_ui_size_kind kind; + f32 value; + f32 relax; +} oc_ui_size; + +typedef union oc_ui_box_size +{ + struct { - OC_UI_NONE = 0, - OC_UI_HOVER = 1 << 1, - OC_UI_ACTIVE = 1 << 2, - OC_UI_DRAGGING = 1 << 3, + oc_ui_size width; + oc_ui_size height; }; - typedef enum + oc_ui_size c[OC_UI_AXIS_COUNT]; +} oc_ui_box_size; + +typedef union oc_ui_box_floating +{ + struct { - OC_UI_SEL_DESCENDANT = 0, - OC_UI_SEL_AND = 1, + bool x; + bool y; + }; + + bool c[OC_UI_AXIS_COUNT]; +} oc_ui_box_floating; + +//NOTE: flags for axis-dependent properties (e.g. OC_UI_STYLE_FLOAT_X/Y) need to be consecutive bits +// in order to play well with axis agnostic functions +typedef u64 oc_ui_style_mask; + +enum +{ + OC_UI_STYLE_NONE = 0, + OC_UI_STYLE_SIZE_WIDTH = 1 << 1, + OC_UI_STYLE_SIZE_HEIGHT = 1 << 2, + OC_UI_STYLE_LAYOUT_AXIS = 1 << 3, + OC_UI_STYLE_LAYOUT_ALIGN_X = 1 << 4, + OC_UI_STYLE_LAYOUT_ALIGN_Y = 1 << 5, + OC_UI_STYLE_LAYOUT_SPACING = 1 << 6, + OC_UI_STYLE_LAYOUT_MARGIN_X = 1 << 7, + OC_UI_STYLE_LAYOUT_MARGIN_Y = 1 << 8, + OC_UI_STYLE_FLOAT_X = 1 << 9, + OC_UI_STYLE_FLOAT_Y = 1 << 10, + OC_UI_STYLE_COLOR = 1 << 11, + OC_UI_STYLE_BG_COLOR = 1 << 12, + OC_UI_STYLE_BORDER_COLOR = 1 << 13, + OC_UI_STYLE_BORDER_SIZE = 1 << 14, + OC_UI_STYLE_ROUNDNESS = 1 << 15, + OC_UI_STYLE_FONT = 1 << 16, + OC_UI_STYLE_FONT_SIZE = 1 << 17, + OC_UI_STYLE_ANIMATION_TIME = 1 << 18, + OC_UI_STYLE_ANIMATION_MASK = 1 << 19, + + //masks + OC_UI_STYLE_SIZE = OC_UI_STYLE_SIZE_WIDTH + | OC_UI_STYLE_SIZE_HEIGHT, + + OC_UI_STYLE_LAYOUT_MARGINS = OC_UI_STYLE_LAYOUT_MARGIN_X + | OC_UI_STYLE_LAYOUT_MARGIN_Y, + + OC_UI_STYLE_LAYOUT = OC_UI_STYLE_LAYOUT_AXIS + | OC_UI_STYLE_LAYOUT_ALIGN_X + | OC_UI_STYLE_LAYOUT_ALIGN_Y + | OC_UI_STYLE_LAYOUT_SPACING + | OC_UI_STYLE_LAYOUT_MARGIN_X + | OC_UI_STYLE_LAYOUT_MARGIN_Y, + + OC_UI_STYLE_FLOAT = OC_UI_STYLE_FLOAT_X + | OC_UI_STYLE_FLOAT_Y, + + OC_UI_STYLE_MASK_INHERITED = OC_UI_STYLE_COLOR + | OC_UI_STYLE_FONT + | OC_UI_STYLE_FONT_SIZE + | OC_UI_STYLE_ANIMATION_TIME + | OC_UI_STYLE_ANIMATION_MASK, +}; + +typedef struct oc_ui_style +{ + oc_ui_box_size size; + oc_ui_layout layout; + oc_ui_box_floating floating; + oc_vec2 floatTarget; + oc_color color; + oc_color bgColor; + oc_color borderColor; + oc_font font; + f32 fontSize; + f32 borderSize; + f32 roundness; + f32 animationTime; + oc_ui_style_mask animationMask; +} oc_ui_style; + +typedef struct oc_ui_tag +{ + u64 hash; +} oc_ui_tag; + +typedef enum +{ + OC_UI_SEL_ANY, + OC_UI_SEL_OWNER, + OC_UI_SEL_TEXT, + OC_UI_SEL_TAG, + OC_UI_SEL_STATUS, + OC_UI_SEL_KEY, + //... +} oc_ui_selector_kind; + +typedef u8 oc_ui_status; + +enum +{ + OC_UI_NONE = 0, + OC_UI_HOVER = 1 << 1, + OC_UI_ACTIVE = 1 << 2, + OC_UI_DRAGGING = 1 << 3, +}; + +typedef enum +{ + OC_UI_SEL_DESCENDANT = 0, + OC_UI_SEL_AND = 1, + //... +} oc_ui_selector_op; + +typedef struct oc_ui_selector +{ + oc_list_elt listElt; + oc_ui_selector_kind kind; + oc_ui_selector_op op; + + union + { + oc_str8 text; + oc_ui_key key; + oc_ui_tag tag; + oc_ui_status status; //... - } oc_ui_selector_op; + }; +} oc_ui_selector; - typedef struct oc_ui_selector - { - oc_list_elt listElt; - oc_ui_selector_kind kind; - oc_ui_selector_op op; +typedef struct oc_ui_pattern +{ + oc_list l; +} oc_ui_pattern; - union - { - oc_str8 text; - oc_ui_key key; - oc_ui_tag tag; - oc_ui_status status; - //... - }; - } oc_ui_selector; +typedef struct oc_ui_box oc_ui_box; - typedef struct oc_ui_pattern - { - oc_list l; - } oc_ui_pattern; +typedef struct oc_ui_style_rule +{ + oc_list_elt boxElt; + oc_list_elt buildElt; + oc_list_elt tmpElt; - typedef struct oc_ui_box oc_ui_box; + oc_ui_box* owner; + oc_ui_pattern pattern; + oc_ui_style_mask mask; + oc_ui_style* style; +} oc_ui_style_rule; - typedef struct oc_ui_style_rule - { - oc_list_elt boxElt; - oc_list_elt buildElt; - oc_list_elt tmpElt; +typedef struct oc_ui_sig +{ + oc_ui_box* box; - oc_ui_box* owner; - oc_ui_pattern pattern; - oc_ui_style_mask mask; - oc_ui_style* style; - } oc_ui_style_rule; + oc_vec2 mouse; + oc_vec2 delta; + oc_vec2 wheel; - typedef struct oc_ui_sig + bool pressed; + bool released; + bool clicked; + bool doubleClicked; + bool rightPressed; + + bool dragging; + bool hovering; + +} oc_ui_sig; + +typedef void (*oc_ui_box_draw_proc)(oc_ui_box* box, void* data); + +typedef enum +{ + OC_UI_FLAG_CLICKABLE = (1 << 0), + OC_UI_FLAG_SCROLL_WHEEL_X = (1 << 1), + OC_UI_FLAG_SCROLL_WHEEL_Y = (1 << 2), + OC_UI_FLAG_BLOCK_MOUSE = (1 << 3), + OC_UI_FLAG_HOT_ANIMATION = (1 << 4), + OC_UI_FLAG_ACTIVE_ANIMATION = (1 << 5), + //WARN: these two following flags need to be kept as consecutive bits to + // play well with axis-agnostic functions + OC_UI_FLAG_ALLOW_OVERFLOW_X = (1 << 6), + OC_UI_FLAG_ALLOW_OVERFLOW_Y = (1 << 7), + OC_UI_FLAG_CLIP = (1 << 8), + OC_UI_FLAG_DRAW_BACKGROUND = (1 << 9), + OC_UI_FLAG_DRAW_FOREGROUND = (1 << 10), + OC_UI_FLAG_DRAW_BORDER = (1 << 11), + OC_UI_FLAG_DRAW_TEXT = (1 << 12), + OC_UI_FLAG_DRAW_PROC = (1 << 13), + + OC_UI_FLAG_OVERLAY = (1 << 14), +} oc_ui_flags; + +struct oc_ui_box +{ + // hierarchy + oc_list_elt listElt; + oc_list children; + oc_ui_box* parent; + + oc_list_elt overlayElt; + + // keying and caching + oc_list_elt bucketElt; + oc_ui_key key; + u64 frameCounter; + + // builder-provided info + oc_ui_flags flags; + oc_str8 string; + oc_list tags; + + oc_ui_box_draw_proc drawProc; + void* drawData; + + // styling + oc_list beforeRules; + oc_list afterRules; + + //oc_ui_style_tag tag; + oc_ui_style* targetStyle; + oc_ui_style style; + u32 z; + + oc_vec2 floatPos; + f32 childrenSum[2]; + f32 spacing[2]; + oc_rect rect; + + // signals + oc_ui_sig* sig; + + // stateful behaviour + bool fresh; + bool closed; + bool parentClosed; + bool dragging; + bool hot; + bool active; + oc_vec2 scroll; + oc_vec2 pressedMouse; + + // animation data + f32 hotTransition; + f32 activeTransition; +}; + +//----------------------------------------------------------------------------- +// context +//----------------------------------------------------------------------------- + +enum +{ + OC_UI_MAX_INPUT_CHAR_PER_FRAME = 64 +}; + +typedef struct oc_ui_input_text +{ + u8 count; + oc_utf32 codePoints[OC_UI_MAX_INPUT_CHAR_PER_FRAME]; + +} oc_ui_input_text; + +typedef struct oc_ui_stack_elt oc_ui_stack_elt; + +struct oc_ui_stack_elt +{ + oc_ui_stack_elt* parent; + + union { oc_ui_box* box; - - oc_vec2 mouse; - oc_vec2 delta; - oc_vec2 wheel; - - bool pressed; - bool released; - bool clicked; - bool doubleClicked; - bool rightPressed; - - bool dragging; - bool hovering; - - } oc_ui_sig; - - typedef void (*oc_ui_box_draw_proc)(oc_ui_box* box, void* data); - - typedef enum - { - OC_UI_FLAG_CLICKABLE = (1 << 0), - OC_UI_FLAG_SCROLL_WHEEL_X = (1 << 1), - OC_UI_FLAG_SCROLL_WHEEL_Y = (1 << 2), - OC_UI_FLAG_BLOCK_MOUSE = (1 << 3), - OC_UI_FLAG_HOT_ANIMATION = (1 << 4), - OC_UI_FLAG_ACTIVE_ANIMATION = (1 << 5), - //WARN: these two following flags need to be kept as consecutive bits to - // play well with axis-agnostic functions - OC_UI_FLAG_ALLOW_OVERFLOW_X = (1 << 6), - OC_UI_FLAG_ALLOW_OVERFLOW_Y = (1 << 7), - OC_UI_FLAG_CLIP = (1 << 8), - OC_UI_FLAG_DRAW_BACKGROUND = (1 << 9), - OC_UI_FLAG_DRAW_FOREGROUND = (1 << 10), - OC_UI_FLAG_DRAW_BORDER = (1 << 11), - OC_UI_FLAG_DRAW_TEXT = (1 << 12), - OC_UI_FLAG_DRAW_PROC = (1 << 13), - - OC_UI_FLAG_OVERLAY = (1 << 14), - } oc_ui_flags; - - struct oc_ui_box - { - // hierarchy - oc_list_elt listElt; - oc_list children; - oc_ui_box* parent; - - oc_list_elt overlayElt; - - // keying and caching - oc_list_elt bucketElt; - oc_ui_key key; - u64 frameCounter; - - // builder-provided info - oc_ui_flags flags; - oc_str8 string; - oc_list tags; - - oc_ui_box_draw_proc drawProc; - void* drawData; - - // styling - oc_list beforeRules; - oc_list afterRules; - - //oc_ui_style_tag tag; - oc_ui_style* targetStyle; - oc_ui_style style; - u32 z; - - oc_vec2 floatPos; - f32 childrenSum[2]; - f32 spacing[2]; - oc_rect rect; - - // signals - oc_ui_sig* sig; - - // stateful behaviour - bool fresh; - bool closed; - bool parentClosed; - bool dragging; - bool hot; - bool active; - oc_vec2 scroll; - oc_vec2 pressedMouse; - - // animation data - f32 hotTransition; - f32 activeTransition; + oc_ui_size size; + oc_rect clip; }; +}; - //----------------------------------------------------------------------------- - // context - //----------------------------------------------------------------------------- +typedef struct oc_ui_tag_elt +{ + oc_list_elt listElt; + oc_ui_tag tag; +} oc_ui_tag_elt; - enum - { - OC_UI_MAX_INPUT_CHAR_PER_FRAME = 64 - }; +enum +{ + OC_UI_BOX_MAP_BUCKET_COUNT = 1024 +}; - typedef struct oc_ui_input_text - { - u8 count; - oc_utf32 codePoints[OC_UI_MAX_INPUT_CHAR_PER_FRAME]; +typedef struct oc_ui_context +{ + bool init; - } oc_ui_input_text; + oc_input_state input; - typedef struct oc_ui_stack_elt oc_ui_stack_elt; + u64 frameCounter; + f64 frameTime; + f64 lastFrameDuration; - struct oc_ui_stack_elt - { - oc_ui_stack_elt* parent; + oc_arena frameArena; + oc_pool boxPool; + oc_list boxMap[OC_UI_BOX_MAP_BUCKET_COUNT]; - union - { - oc_ui_box* box; - oc_ui_size size; - oc_rect clip; - }; - }; + oc_ui_box* root; + oc_ui_box* overlay; + oc_list overlayList; + oc_ui_stack_elt* boxStack; + oc_ui_stack_elt* clipStack; - typedef struct oc_ui_tag_elt - { - oc_list_elt listElt; - oc_ui_tag tag; - } oc_ui_tag_elt; + oc_list nextBoxBeforeRules; + oc_list nextBoxAfterRules; + oc_list nextBoxTags; - enum - { - OC_UI_BOX_MAP_BUCKET_COUNT = 1024 - }; + u32 z; + oc_ui_box* hovered; - typedef struct oc_ui_context - { - bool init; + oc_ui_box* focus; + i32 editCursor; + i32 editMark; + i32 editFirstDisplayedChar; + f64 editCursorBlinkStart; - oc_input_state input; +} oc_ui_context; - u64 frameCounter; - f64 frameTime; - f64 lastFrameDuration; +//------------------------------------------------------------------------------------- +// UI context initialization and frame cycle +//------------------------------------------------------------------------------------- +ORCA_API void oc_ui_init(oc_ui_context* context); +ORCA_API oc_ui_context* oc_ui_get_context(void); +ORCA_API void oc_ui_set_context(oc_ui_context* context); - oc_arena frameArena; - oc_pool boxPool; - oc_list boxMap[OC_UI_BOX_MAP_BUCKET_COUNT]; - - oc_ui_box* root; - oc_ui_box* overlay; - oc_list overlayList; - oc_ui_stack_elt* boxStack; - oc_ui_stack_elt* clipStack; - - oc_list nextBoxBeforeRules; - oc_list nextBoxAfterRules; - oc_list nextBoxTags; - - u32 z; - oc_ui_box* hovered; - - oc_ui_box* focus; - i32 editCursor; - i32 editMark; - i32 editFirstDisplayedChar; - f64 editCursorBlinkStart; - - } oc_ui_context; - - //------------------------------------------------------------------------------------- - // UI context initialization and frame cycle - //------------------------------------------------------------------------------------- - ORCA_API void oc_ui_init(oc_ui_context* context); - ORCA_API oc_ui_context* oc_ui_get_context(void); - ORCA_API void oc_ui_set_context(oc_ui_context* context); - - ORCA_API void oc_ui_process_event(oc_event* event); - ORCA_API void oc_ui_begin_frame(oc_vec2 size, oc_ui_style* defaultStyle, oc_ui_style_mask mask); - ORCA_API void oc_ui_end_frame(void); - ORCA_API void oc_ui_draw(void); +ORCA_API void oc_ui_process_event(oc_event* event); +ORCA_API void oc_ui_begin_frame(oc_vec2 size, oc_ui_style* defaultStyle, oc_ui_style_mask mask); +ORCA_API void oc_ui_end_frame(void); +ORCA_API void oc_ui_draw(void); #define oc_ui_frame(size, style, mask) oc_defer_loop(oc_ui_begin_frame((size), (style), (mask)), oc_ui_end_frame()) - //------------------------------------------------------------------------------------- - // Box keys - //------------------------------------------------------------------------------------- - ORCA_API oc_ui_key oc_ui_key_make_str8(oc_str8 string); - ORCA_API oc_ui_key oc_ui_key_make_path(oc_str8_list path); +//------------------------------------------------------------------------------------- +// Box keys +//------------------------------------------------------------------------------------- +ORCA_API oc_ui_key oc_ui_key_make_str8(oc_str8 string); +ORCA_API oc_ui_key oc_ui_key_make_path(oc_str8_list path); - ORCA_API oc_ui_box* oc_ui_box_lookup_key(oc_ui_key key); - ORCA_API oc_ui_box* oc_ui_box_lookup_str8(oc_str8 string); +ORCA_API oc_ui_box* oc_ui_box_lookup_key(oc_ui_key key); +ORCA_API oc_ui_box* oc_ui_box_lookup_str8(oc_str8 string); // C-string helper #define oc_ui_key_make(s) oc_ui_key_make_str8(OC_STR8(s)) #define oc_ui_box_lookup(s) oc_ui_box_lookup_str8(OC_STR8(s)) - //------------------------------------------------------------------------------------- - // Box hierarchy building - //------------------------------------------------------------------------------------- - ORCA_API oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags); - ORCA_API oc_ui_box* oc_ui_box_begin_str8(oc_str8 string, oc_ui_flags flags); +//------------------------------------------------------------------------------------- +// Box hierarchy building +//------------------------------------------------------------------------------------- +ORCA_API oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags); +ORCA_API oc_ui_box* oc_ui_box_begin_str8(oc_str8 string, oc_ui_flags flags); - ORCA_API oc_ui_box* oc_ui_box_end(void); +ORCA_API oc_ui_box* oc_ui_box_end(void); #define oc_ui_container(name, flags) oc_defer_loop(oc_ui_box_begin(name, flags), oc_ui_box_end()) #define oc_ui_container_str8(name, flags) oc_defer_loop(oc_ui_box_begin_str8(name, flags), oc_ui_box_end()) - ORCA_API void oc_ui_box_push(oc_ui_box* box); - ORCA_API void oc_ui_box_pop(void); - ORCA_API oc_ui_box* oc_ui_box_top(void); +ORCA_API void oc_ui_box_push(oc_ui_box* box); +ORCA_API void oc_ui_box_pop(void); +ORCA_API oc_ui_box* oc_ui_box_top(void); - ORCA_API void oc_ui_box_set_draw_proc(oc_ui_box* box, oc_ui_box_draw_proc proc, void* data); +ORCA_API void oc_ui_box_set_draw_proc(oc_ui_box* box, oc_ui_box_draw_proc proc, void* data); // C-string helpers #define oc_ui_box_lookup(s) oc_ui_box_lookup_str8(OC_STR8(s)) #define oc_ui_box_make(s, flags) oc_ui_box_make_str8(OC_STR8(s), flags) #define oc_ui_box_begin(s, flags) oc_ui_box_begin_str8(OC_STR8(s), flags) - //------------------------------------------------------------------------------------- - // Box status and signals - //------------------------------------------------------------------------------------- - ORCA_API bool oc_ui_box_closed(oc_ui_box* box); - ORCA_API void oc_ui_box_set_closed(oc_ui_box* box, bool closed); +//------------------------------------------------------------------------------------- +// Box status and signals +//------------------------------------------------------------------------------------- +ORCA_API bool oc_ui_box_closed(oc_ui_box* box); +ORCA_API void oc_ui_box_set_closed(oc_ui_box* box, bool closed); - ORCA_API bool oc_ui_box_active(oc_ui_box* box); - ORCA_API void oc_ui_box_activate(oc_ui_box* box); - ORCA_API void oc_ui_box_deactivate(oc_ui_box* box); +ORCA_API bool oc_ui_box_active(oc_ui_box* box); +ORCA_API void oc_ui_box_activate(oc_ui_box* box); +ORCA_API void oc_ui_box_deactivate(oc_ui_box* box); - ORCA_API bool oc_ui_box_hot(oc_ui_box* box); - ORCA_API void oc_ui_box_set_hot(oc_ui_box* box, bool hot); +ORCA_API bool oc_ui_box_hot(oc_ui_box* box); +ORCA_API void oc_ui_box_set_hot(oc_ui_box* box, bool hot); - ORCA_API oc_ui_sig oc_ui_box_sig(oc_ui_box* box); +ORCA_API oc_ui_sig oc_ui_box_sig(oc_ui_box* box); - //------------------------------------------------------------------------------------- - // Tagging - //------------------------------------------------------------------------------------- - ORCA_API oc_ui_tag oc_ui_tag_make_str8(oc_str8 string); - ORCA_API void oc_ui_tag_box_str8(oc_ui_box* box, oc_str8 string); - ORCA_API void oc_ui_tag_next_str8(oc_str8 string); +//------------------------------------------------------------------------------------- +// Tagging +//------------------------------------------------------------------------------------- +ORCA_API oc_ui_tag oc_ui_tag_make_str8(oc_str8 string); +ORCA_API void oc_ui_tag_box_str8(oc_ui_box* box, oc_str8 string); +ORCA_API void oc_ui_tag_next_str8(oc_str8 string); // C-string helpers #define oc_ui_tag_make(s) oc_ui_tag_make_str8(OC_STR8(s)) #define oc_ui_tag_box(b, s) oc_ui_tag_box_str8(b, OC_STR8(s)) #define oc_ui_tag_next(s) oc_ui_tag_next_str8(OC_STR8(s)) - //------------------------------------------------------------------------------------- - // Styling - //------------------------------------------------------------------------------------- - //NOTE: styling API - //WARN: You can use a pattern in multiple rules, but be aware that a pattern is references an underlying list of selectors, - // hence pushing to a pattern also modifies rules in which the pattern was previously used! - ORCA_API void oc_ui_apply_style_with_mask(oc_ui_style* dst, oc_ui_style* src, oc_ui_style_mask mask); +//------------------------------------------------------------------------------------- +// Styling +//------------------------------------------------------------------------------------- +//NOTE: styling API +//WARN: You can use a pattern in multiple rules, but be aware that a pattern is references an underlying list of selectors, +// hence pushing to a pattern also modifies rules in which the pattern was previously used! +ORCA_API void oc_ui_apply_style_with_mask(oc_ui_style* dst, oc_ui_style* src, oc_ui_style_mask mask); - ORCA_API void oc_ui_pattern_push(oc_arena* arena, oc_ui_pattern* pattern, oc_ui_selector selector); - ORCA_API oc_ui_pattern oc_ui_pattern_all(void); - ORCA_API oc_ui_pattern oc_ui_pattern_owner(void); +ORCA_API void oc_ui_pattern_push(oc_arena* arena, oc_ui_pattern* pattern, oc_ui_selector selector); +ORCA_API oc_ui_pattern oc_ui_pattern_all(void); +ORCA_API oc_ui_pattern oc_ui_pattern_owner(void); - ORCA_API void oc_ui_style_next(oc_ui_style* style, oc_ui_style_mask mask); - ORCA_API void oc_ui_style_match_before(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); - ORCA_API void oc_ui_style_match_after(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); +ORCA_API void oc_ui_style_next(oc_ui_style* style, oc_ui_style_mask mask); +ORCA_API void oc_ui_style_match_before(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); +ORCA_API void oc_ui_style_match_after(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask); - //------------------------------------------------------------------------- - // Basic widget helpers - //------------------------------------------------------------------------- - enum - { - OC_UI_STYLE_TAG_USER_MAX = 1 << 16, - OC_UI_STYLE_TAG_LABEL, - OC_UI_STYLE_TAG_BUTTON, - OC_UI_STYLE_TAG_SCROLLBAR, - OC_UI_STYLE_TAG_PANEL, - OC_UI_STYLE_TAG_TOOLTIP, - OC_UI_STYLE_TAG_MENU - }; +//------------------------------------------------------------------------- +// Basic widget helpers +//------------------------------------------------------------------------- +enum +{ + OC_UI_STYLE_TAG_USER_MAX = 1 << 16, + OC_UI_STYLE_TAG_LABEL, + OC_UI_STYLE_TAG_BUTTON, + OC_UI_STYLE_TAG_SCROLLBAR, + OC_UI_STYLE_TAG_PANEL, + OC_UI_STYLE_TAG_TOOLTIP, + OC_UI_STYLE_TAG_MENU +}; - ORCA_API oc_ui_sig oc_ui_label(const char* label); - ORCA_API oc_ui_sig oc_ui_label_str8(oc_str8 label); +ORCA_API oc_ui_sig oc_ui_label(const char* label); +ORCA_API oc_ui_sig oc_ui_label_str8(oc_str8 label); - ORCA_API oc_ui_sig oc_ui_button(const char* label); - ORCA_API oc_ui_sig oc_ui_checkbox(const char* name, bool* checked); - ORCA_API oc_ui_box* oc_ui_slider(const char* label, f32 thumbRatio, f32* scrollValue); +ORCA_API oc_ui_sig oc_ui_button(const char* label); +ORCA_API oc_ui_sig oc_ui_checkbox(const char* name, bool* checked); +ORCA_API oc_ui_box* oc_ui_slider(const char* label, f32 thumbRatio, f32* scrollValue); - ORCA_API void oc_ui_panel_begin(const char* name, oc_ui_flags flags); - ORCA_API void oc_ui_panel_end(void); +ORCA_API void oc_ui_panel_begin(const char* name, oc_ui_flags flags); +ORCA_API void oc_ui_panel_end(void); #define oc_ui_panel(s, f) oc_defer_loop(oc_ui_panel_begin(s, f), oc_ui_panel_end()) - ORCA_API oc_ui_sig oc_ui_tooltip_begin(const char* name); - ORCA_API void oc_ui_tooltip_end(void); +ORCA_API oc_ui_sig oc_ui_tooltip_begin(const char* name); +ORCA_API void oc_ui_tooltip_end(void); #define oc_ui_tooltip(name) oc_defer_loop(oc_ui_tooltip_begin(name), oc_ui_tooltip_end()) - ORCA_API void oc_ui_menu_bar_begin(const char* label); - ORCA_API void oc_ui_menu_bar_end(void); +ORCA_API void oc_ui_menu_bar_begin(const char* label); +ORCA_API void oc_ui_menu_bar_end(void); #define oc_ui_menu_bar(name) oc_defer_loop(oc_ui_menu_bar_begin(name), oc_ui_menu_bar_end()) - ORCA_API void oc_ui_menu_begin(const char* label); - ORCA_API void oc_ui_menu_end(void); +ORCA_API void oc_ui_menu_begin(const char* label); +ORCA_API void oc_ui_menu_end(void); #define oc_ui_menu(name) oc_defer_loop(oc_ui_menu_begin(name), oc_ui_menu_end()) - ORCA_API oc_ui_sig oc_ui_menu_button(const char* name); +ORCA_API oc_ui_sig oc_ui_menu_button(const char* name); - typedef struct oc_ui_text_box_result - { - bool changed; - bool accepted; - oc_str8 text; +typedef struct oc_ui_text_box_result +{ + bool changed; + bool accepted; + oc_str8 text; - } oc_ui_text_box_result; +} oc_ui_text_box_result; - ORCA_API oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 text); +ORCA_API oc_ui_text_box_result oc_ui_text_box(const char* name, oc_arena* arena, oc_str8 text); - typedef struct oc_ui_select_popup_info - { - bool changed; - int selectedIndex; - int optionCount; - oc_str8* options; - } oc_ui_select_popup_info; +typedef struct oc_ui_select_popup_info +{ + bool changed; + int selectedIndex; + int optionCount; + oc_str8* options; +} oc_ui_select_popup_info; - ORCA_API oc_ui_select_popup_info oc_ui_select_popup(const char* name, oc_ui_select_popup_info* info); +ORCA_API oc_ui_select_popup_info oc_ui_select_popup(const char* name, oc_ui_select_popup_info* info); #ifdef __cplusplus } // extern "C"