- Added basic cheatsheets

- Minor cleanups:
    - Hiding some native-only path APIs
    - Re-formatting ui.h
This commit is contained in:
Martin Fouilleul 2023-09-05 16:25:04 +02:00
parent bd35b75f4b
commit 425d9b3448
9 changed files with 874 additions and 464 deletions

35
doc/cheatsheet_app.h Normal file
View File

@ -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)

162
doc/cheatsheet_graphics.h Normal file
View File

@ -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);

39
doc/cheatsheet_io.h Normal file
View File

@ -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);

64
doc/cheatsheet_ui.h Normal file
View File

@ -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);

101
doc/cheatsheet_util.h Normal file
View File

@ -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, ...)

View File

@ -53,6 +53,7 @@
#include "platform/platform_io_common.c" #include "platform/platform_io_common.c"
#include "platform/orca_io_stubs.c" #include "platform/orca_io_stubs.c"
#include "platform/orca_platform.c" #include "platform/orca_platform.c"
#include "platform/platform_path.c"
#else #else
#error "Unsupported platform" #error "Unsupported platform"
#endif #endif

View File

@ -90,6 +90,8 @@ oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath)
return (result); return (result);
} }
#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA
oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath) oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath)
{ {
oc_str8_list list = { 0 }; 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); oc_scratch_end(scratch);
return (path); return (path);
} }
#endif

View File

@ -8,6 +8,7 @@
#ifndef __PLATFORM_PATH_H_ #ifndef __PLATFORM_PATH_H_
#define __PLATFORM_PATH_H_ #define __PLATFORM_PATH_H_
#include"platform.h"
#include "util/strings.h" #include "util/strings.h"
/*NOTE: /*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 oc_str8 oc_path_append(oc_arena* arena, oc_str8 parent, oc_str8 relPath);
ORCA_API bool oc_path_is_absolute(oc_str8 path); 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_executable(oc_arena* arena);
ORCA_API oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path); ORCA_API oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path);
// helper: gets the path from oc_path_executable() and appends relPath // 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); ORCA_API oc_str8 oc_path_executable_relative(oc_arena* arena, oc_str8 relPath);
#endif
#endif //__PLATFORM_PATH_H_ #endif //__PLATFORM_PATH_H_

View File

@ -15,31 +15,30 @@
#include "util/typedefs.h" #include "util/typedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif #endif
typedef struct oc_ui_key typedef struct oc_ui_key
{ {
u64 hash; u64 hash;
} oc_ui_key; } oc_ui_key;
typedef enum typedef enum
{ {
OC_UI_AXIS_X, OC_UI_AXIS_X,
OC_UI_AXIS_Y, OC_UI_AXIS_Y,
OC_UI_AXIS_COUNT OC_UI_AXIS_COUNT
} oc_ui_axis; } oc_ui_axis;
typedef enum typedef enum
{ {
OC_UI_ALIGN_START, OC_UI_ALIGN_START,
OC_UI_ALIGN_END, OC_UI_ALIGN_END,
OC_UI_ALIGN_CENTER, OC_UI_ALIGN_CENTER,
} oc_ui_align; } oc_ui_align;
typedef union oc_ui_layout_align typedef union oc_ui_layout_align
{ {
struct struct
{ {
oc_ui_align x; oc_ui_align x;
@ -47,10 +46,10 @@ extern "C"
}; };
oc_ui_align c[OC_UI_AXIS_COUNT]; oc_ui_align c[OC_UI_AXIS_COUNT];
} oc_ui_layout_align; } oc_ui_layout_align;
typedef struct oc_ui_layout typedef struct oc_ui_layout
{ {
oc_ui_axis axis; oc_ui_axis axis;
f32 spacing; f32 spacing;
@ -67,27 +66,27 @@ extern "C"
oc_ui_layout_align align; oc_ui_layout_align align;
} oc_ui_layout; } oc_ui_layout;
typedef enum oc_ui_size_kind typedef enum oc_ui_size_kind
{ {
OC_UI_SIZE_TEXT, OC_UI_SIZE_TEXT,
OC_UI_SIZE_PIXELS, OC_UI_SIZE_PIXELS,
OC_UI_SIZE_CHILDREN, OC_UI_SIZE_CHILDREN,
OC_UI_SIZE_PARENT, OC_UI_SIZE_PARENT,
OC_UI_SIZE_PARENT_MINUS_PIXELS, OC_UI_SIZE_PARENT_MINUS_PIXELS,
} oc_ui_size_kind; } oc_ui_size_kind;
typedef struct oc_ui_size typedef struct oc_ui_size
{ {
oc_ui_size_kind kind; oc_ui_size_kind kind;
f32 value; f32 value;
f32 relax; f32 relax;
} oc_ui_size; } oc_ui_size;
typedef union oc_ui_box_size typedef union oc_ui_box_size
{ {
struct struct
{ {
oc_ui_size width; oc_ui_size width;
@ -95,10 +94,10 @@ extern "C"
}; };
oc_ui_size c[OC_UI_AXIS_COUNT]; oc_ui_size c[OC_UI_AXIS_COUNT];
} oc_ui_box_size; } oc_ui_box_size;
typedef union oc_ui_box_floating typedef union oc_ui_box_floating
{ {
struct struct
{ {
bool x; bool x;
@ -106,14 +105,14 @@ extern "C"
}; };
bool c[OC_UI_AXIS_COUNT]; bool c[OC_UI_AXIS_COUNT];
} oc_ui_box_floating; } oc_ui_box_floating;
//NOTE: flags for axis-dependent properties (e.g. OC_UI_STYLE_FLOAT_X/Y) need to be consecutive bits //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 // in order to play well with axis agnostic functions
typedef u64 oc_ui_style_mask; typedef u64 oc_ui_style_mask;
enum enum
{ {
OC_UI_STYLE_NONE = 0, OC_UI_STYLE_NONE = 0,
OC_UI_STYLE_SIZE_WIDTH = 1 << 1, OC_UI_STYLE_SIZE_WIDTH = 1 << 1,
OC_UI_STYLE_SIZE_HEIGHT = 1 << 2, OC_UI_STYLE_SIZE_HEIGHT = 1 << 2,
@ -157,10 +156,10 @@ extern "C"
| OC_UI_STYLE_FONT_SIZE | OC_UI_STYLE_FONT_SIZE
| OC_UI_STYLE_ANIMATION_TIME | OC_UI_STYLE_ANIMATION_TIME
| OC_UI_STYLE_ANIMATION_MASK, | OC_UI_STYLE_ANIMATION_MASK,
}; };
typedef struct oc_ui_style typedef struct oc_ui_style
{ {
oc_ui_box_size size; oc_ui_box_size size;
oc_ui_layout layout; oc_ui_layout layout;
oc_ui_box_floating floating; oc_ui_box_floating floating;
@ -174,15 +173,15 @@ extern "C"
f32 roundness; f32 roundness;
f32 animationTime; f32 animationTime;
oc_ui_style_mask animationMask; oc_ui_style_mask animationMask;
} oc_ui_style; } oc_ui_style;
typedef struct oc_ui_tag typedef struct oc_ui_tag
{ {
u64 hash; u64 hash;
} oc_ui_tag; } oc_ui_tag;
typedef enum typedef enum
{ {
OC_UI_SEL_ANY, OC_UI_SEL_ANY,
OC_UI_SEL_OWNER, OC_UI_SEL_OWNER,
OC_UI_SEL_TEXT, OC_UI_SEL_TEXT,
@ -190,27 +189,27 @@ extern "C"
OC_UI_SEL_STATUS, OC_UI_SEL_STATUS,
OC_UI_SEL_KEY, OC_UI_SEL_KEY,
//... //...
} oc_ui_selector_kind; } oc_ui_selector_kind;
typedef u8 oc_ui_status; typedef u8 oc_ui_status;
enum enum
{ {
OC_UI_NONE = 0, OC_UI_NONE = 0,
OC_UI_HOVER = 1 << 1, OC_UI_HOVER = 1 << 1,
OC_UI_ACTIVE = 1 << 2, OC_UI_ACTIVE = 1 << 2,
OC_UI_DRAGGING = 1 << 3, OC_UI_DRAGGING = 1 << 3,
}; };
typedef enum typedef enum
{ {
OC_UI_SEL_DESCENDANT = 0, OC_UI_SEL_DESCENDANT = 0,
OC_UI_SEL_AND = 1, OC_UI_SEL_AND = 1,
//... //...
} oc_ui_selector_op; } oc_ui_selector_op;
typedef struct oc_ui_selector typedef struct oc_ui_selector
{ {
oc_list_elt listElt; oc_list_elt listElt;
oc_ui_selector_kind kind; oc_ui_selector_kind kind;
oc_ui_selector_op op; oc_ui_selector_op op;
@ -223,17 +222,17 @@ extern "C"
oc_ui_status status; oc_ui_status status;
//... //...
}; };
} oc_ui_selector; } oc_ui_selector;
typedef struct oc_ui_pattern typedef struct oc_ui_pattern
{ {
oc_list l; oc_list l;
} oc_ui_pattern; } oc_ui_pattern;
typedef struct oc_ui_box oc_ui_box; typedef struct oc_ui_box oc_ui_box;
typedef struct oc_ui_style_rule typedef struct oc_ui_style_rule
{ {
oc_list_elt boxElt; oc_list_elt boxElt;
oc_list_elt buildElt; oc_list_elt buildElt;
oc_list_elt tmpElt; oc_list_elt tmpElt;
@ -242,10 +241,10 @@ extern "C"
oc_ui_pattern pattern; oc_ui_pattern pattern;
oc_ui_style_mask mask; oc_ui_style_mask mask;
oc_ui_style* style; oc_ui_style* style;
} oc_ui_style_rule; } oc_ui_style_rule;
typedef struct oc_ui_sig typedef struct oc_ui_sig
{ {
oc_ui_box* box; oc_ui_box* box;
oc_vec2 mouse; oc_vec2 mouse;
@ -261,12 +260,12 @@ extern "C"
bool dragging; bool dragging;
bool hovering; bool hovering;
} oc_ui_sig; } oc_ui_sig;
typedef void (*oc_ui_box_draw_proc)(oc_ui_box* box, void* data); typedef void (*oc_ui_box_draw_proc)(oc_ui_box* box, void* data);
typedef enum typedef enum
{ {
OC_UI_FLAG_CLICKABLE = (1 << 0), OC_UI_FLAG_CLICKABLE = (1 << 0),
OC_UI_FLAG_SCROLL_WHEEL_X = (1 << 1), OC_UI_FLAG_SCROLL_WHEEL_X = (1 << 1),
OC_UI_FLAG_SCROLL_WHEEL_Y = (1 << 2), OC_UI_FLAG_SCROLL_WHEEL_Y = (1 << 2),
@ -285,10 +284,10 @@ extern "C"
OC_UI_FLAG_DRAW_PROC = (1 << 13), OC_UI_FLAG_DRAW_PROC = (1 << 13),
OC_UI_FLAG_OVERLAY = (1 << 14), OC_UI_FLAG_OVERLAY = (1 << 14),
} oc_ui_flags; } oc_ui_flags;
struct oc_ui_box struct oc_ui_box
{ {
// hierarchy // hierarchy
oc_list_elt listElt; oc_list_elt listElt;
oc_list children; oc_list children;
@ -339,28 +338,28 @@ extern "C"
// animation data // animation data
f32 hotTransition; f32 hotTransition;
f32 activeTransition; f32 activeTransition;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// context // context
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
enum enum
{ {
OC_UI_MAX_INPUT_CHAR_PER_FRAME = 64 OC_UI_MAX_INPUT_CHAR_PER_FRAME = 64
}; };
typedef struct oc_ui_input_text typedef struct oc_ui_input_text
{ {
u8 count; u8 count;
oc_utf32 codePoints[OC_UI_MAX_INPUT_CHAR_PER_FRAME]; oc_utf32 codePoints[OC_UI_MAX_INPUT_CHAR_PER_FRAME];
} oc_ui_input_text; } oc_ui_input_text;
typedef struct oc_ui_stack_elt oc_ui_stack_elt; typedef struct oc_ui_stack_elt oc_ui_stack_elt;
struct oc_ui_stack_elt struct oc_ui_stack_elt
{ {
oc_ui_stack_elt* parent; oc_ui_stack_elt* parent;
union union
@ -369,21 +368,21 @@ extern "C"
oc_ui_size size; oc_ui_size size;
oc_rect clip; oc_rect clip;
}; };
}; };
typedef struct oc_ui_tag_elt typedef struct oc_ui_tag_elt
{ {
oc_list_elt listElt; oc_list_elt listElt;
oc_ui_tag tag; oc_ui_tag tag;
} oc_ui_tag_elt; } oc_ui_tag_elt;
enum enum
{ {
OC_UI_BOX_MAP_BUCKET_COUNT = 1024 OC_UI_BOX_MAP_BUCKET_COUNT = 1024
}; };
typedef struct oc_ui_context typedef struct oc_ui_context
{ {
bool init; bool init;
oc_input_state input; oc_input_state input;
@ -415,104 +414,104 @@ extern "C"
i32 editFirstDisplayedChar; i32 editFirstDisplayedChar;
f64 editCursorBlinkStart; f64 editCursorBlinkStart;
} oc_ui_context; } oc_ui_context;
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// UI context initialization and frame cycle // UI context initialization and frame cycle
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
ORCA_API void oc_ui_init(oc_ui_context* context); ORCA_API void oc_ui_init(oc_ui_context* context);
ORCA_API oc_ui_context* oc_ui_get_context(void); 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_set_context(oc_ui_context* context);
ORCA_API void oc_ui_process_event(oc_event* event); 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_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_end_frame(void);
ORCA_API void oc_ui_draw(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()) #define oc_ui_frame(size, style, mask) oc_defer_loop(oc_ui_begin_frame((size), (style), (mask)), oc_ui_end_frame())
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Box keys // Box keys
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
ORCA_API oc_ui_key oc_ui_key_make_str8(oc_str8 string); 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_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_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_str8(oc_str8 string);
// C-string helper // C-string helper
#define oc_ui_key_make(s) oc_ui_key_make_str8(OC_STR8(s)) #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)) #define oc_ui_box_lookup(s) oc_ui_box_lookup_str8(OC_STR8(s))
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Box hierarchy building // 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_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_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(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()) #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_push(oc_ui_box* box);
ORCA_API void oc_ui_box_pop(void); ORCA_API void oc_ui_box_pop(void);
ORCA_API oc_ui_box* oc_ui_box_top(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 // C-string helpers
#define oc_ui_box_lookup(s) oc_ui_box_lookup_str8(OC_STR8(s)) #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_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) #define oc_ui_box_begin(s, flags) oc_ui_box_begin_str8(OC_STR8(s), flags)
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Box status and signals // Box status and signals
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
ORCA_API bool oc_ui_box_closed(oc_ui_box* box); 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 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 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_activate(oc_ui_box* box);
ORCA_API void oc_ui_box_deactivate(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 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 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 // Tagging
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
ORCA_API oc_ui_tag oc_ui_tag_make_str8(oc_str8 string); 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_box_str8(oc_ui_box* box, oc_str8 string);
ORCA_API void oc_ui_tag_next_str8(oc_str8 string); ORCA_API void oc_ui_tag_next_str8(oc_str8 string);
// C-string helpers // C-string helpers
#define oc_ui_tag_make(s) oc_ui_tag_make_str8(OC_STR8(s)) #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_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)) #define oc_ui_tag_next(s) oc_ui_tag_next_str8(OC_STR8(s))
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Styling // Styling
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
//NOTE: styling API //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, //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! // 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_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 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_all(void);
ORCA_API oc_ui_pattern oc_ui_pattern_owner(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_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_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_match_after(oc_ui_pattern pattern, oc_ui_style* style, oc_ui_style_mask mask);
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Basic widget helpers // Basic widget helpers
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
enum enum
{ {
OC_UI_STYLE_TAG_USER_MAX = 1 << 16, OC_UI_STYLE_TAG_USER_MAX = 1 << 16,
OC_UI_STYLE_TAG_LABEL, OC_UI_STYLE_TAG_LABEL,
OC_UI_STYLE_TAG_BUTTON, OC_UI_STYLE_TAG_BUTTON,
@ -520,52 +519,52 @@ extern "C"
OC_UI_STYLE_TAG_PANEL, OC_UI_STYLE_TAG_PANEL,
OC_UI_STYLE_TAG_TOOLTIP, OC_UI_STYLE_TAG_TOOLTIP,
OC_UI_STYLE_TAG_MENU OC_UI_STYLE_TAG_MENU
}; };
ORCA_API oc_ui_sig oc_ui_label(const char* 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_label_str8(oc_str8 label);
ORCA_API oc_ui_sig oc_ui_button(const char* 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_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_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_begin(const char* name, oc_ui_flags flags);
ORCA_API void oc_ui_panel_end(void); 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()) #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 oc_ui_sig oc_ui_tooltip_begin(const char* name);
ORCA_API void oc_ui_tooltip_end(void); 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()) #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_begin(const char* label);
ORCA_API void oc_ui_menu_bar_end(void); 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()) #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_begin(const char* label);
ORCA_API void oc_ui_menu_end(void); 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()) #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 typedef struct oc_ui_text_box_result
{ {
bool changed; bool changed;
bool accepted; bool accepted;
oc_str8 text; 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 typedef struct oc_ui_select_popup_info
{ {
bool changed; bool changed;
int selectedIndex; int selectedIndex;
int optionCount; int optionCount;
oc_str8* options; oc_str8* options;
} oc_ui_select_popup_info; } 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 #ifdef __cplusplus
} // extern "C" } // extern "C"