2023-08-24 22:30:20 +00:00
|
|
|
/************************************************************/ /**
|
|
|
|
*
|
|
|
|
* @file: main.cpp
|
|
|
|
* @author: Martin Fouilleul
|
|
|
|
* @date: 30/07/2022
|
|
|
|
* @revision:
|
|
|
|
*
|
2023-08-19 12:49:23 +00:00
|
|
|
*****************************************************************/
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
|
|
|
#include <math.h>
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
#include "orca.h"
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
void debug_print_indent(int indent)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < indent; i++)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info(" ");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
void debug_print_rule(oc_ui_style_rule* rule)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_list_for(&rule->pattern.l, selector, oc_ui_selector, listElt)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
switch(selector->kind)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_ANY:
|
|
|
|
oc_log_info("any: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_OWNER:
|
|
|
|
oc_log_info("owner: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_TEXT:
|
|
|
|
oc_log_info("text='%.*s': ", (int)selector->text.len, selector->text.ptr);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_TAG:
|
|
|
|
oc_log_info("tag=0x%llx: ", selector->tag.hash);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_STATUS:
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
if(selector->status & OC_UI_HOVER)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("hover: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
if(selector->status & OC_UI_ACTIVE)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("active: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
if(selector->status & OC_UI_DRAGGING)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("dragging: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SEL_KEY:
|
|
|
|
oc_log_info("key=0x%llx: ", selector->key.hash);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("unknown: ");
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("=> font size = %f\n", rule->style->fontSize);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
void debug_print_size(oc_ui_box* box, oc_ui_axis axis, int indent)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("size %s: ", axis == OC_UI_AXIS_X ? "x" : "y");
|
2023-08-19 12:49:23 +00:00
|
|
|
f32 value = box->targetStyle->size.c[axis].value;
|
|
|
|
switch(box->targetStyle->size.c[axis].kind)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SIZE_TEXT:
|
|
|
|
oc_log_info("text\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SIZE_CHILDREN:
|
|
|
|
oc_log_info("children\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SIZE_PARENT:
|
|
|
|
oc_log_info("parent: %f\n", value);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SIZE_PARENT_MINUS_PIXELS:
|
|
|
|
oc_log_info("parent minus pixels: %f\n", value);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_UI_SIZE_PIXELS:
|
|
|
|
oc_log_info("pixels: %f\n", value);
|
2023-08-19 12:49:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
void debug_print_styles(oc_ui_box* box, int indent)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("### box '%.*s'\n", (int)box->string.len, box->string.ptr);
|
2023-08-19 12:49:23 +00:00
|
|
|
indent++;
|
|
|
|
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("font size: %f\n", box->targetStyle->fontSize);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
debug_print_size(box, OC_UI_AXIS_X, indent);
|
|
|
|
debug_print_size(box, OC_UI_AXIS_Y, indent);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(!oc_list_empty(&box->beforeRules))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("before rules:\n");
|
|
|
|
oc_list_for(&box->beforeRules, rule, oc_ui_style_rule, boxElt)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent + 1);
|
|
|
|
debug_print_rule(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(!oc_list_empty(&box->afterRules))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("after rules:\n");
|
|
|
|
oc_list_for(&box->afterRules, rule, oc_ui_style_rule, boxElt)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent + 1);
|
|
|
|
debug_print_rule(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(!oc_list_empty(&box->children))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_indent(indent);
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("children:\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
indent++;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_list_for(&box->children, child, oc_ui_box, listElt)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
debug_print_styles(child, indent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_font create_font()
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
//NOTE(martin): create font
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_str8 fontPath = oc_path_executable_relative(oc_scratch(), OC_STR8("../../resources/OpenSansLatinSubset.ttf"));
|
|
|
|
char* fontPathCString = oc_str8_to_cstring(oc_scratch(), fontPath);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
FILE* fontFile = fopen(fontPathCString, "r");
|
|
|
|
if(!fontFile)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_error("Could not load font file '%s': %s\n", fontPathCString, strerror(errno));
|
|
|
|
return (oc_font_nil());
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
unsigned char* fontData = 0;
|
|
|
|
fseek(fontFile, 0, SEEK_END);
|
|
|
|
u32 fontDataSize = ftell(fontFile);
|
|
|
|
rewind(fontFile);
|
|
|
|
fontData = (unsigned char*)malloc(fontDataSize);
|
|
|
|
fread(fontData, 1, fontDataSize, fontFile);
|
|
|
|
fclose(fontFile);
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_unicode_range ranges[5] = { OC_UNICODE_BASIC_LATIN,
|
|
|
|
OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
|
|
|
|
OC_UNICODE_LATIN_EXTENDED_A,
|
|
|
|
OC_UNICODE_LATIN_EXTENDED_B,
|
|
|
|
OC_UNICODE_SPECIALS };
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_font font = oc_font_create_from_memory(oc_str8_from_buffer(fontDataSize, (char*)fontData), 5, ranges);
|
2023-08-19 12:49:23 +00:00
|
|
|
free(fontData);
|
|
|
|
|
|
|
|
return (font);
|
|
|
|
}
|
|
|
|
|
|
|
|
void widget_begin_view(char* str)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_Y,
|
|
|
|
.layout.spacing = 10,
|
|
|
|
.layout.margin.x = 10,
|
|
|
|
.layout.margin.y = 10,
|
|
|
|
.layout.align.x = OC_UI_ALIGN_CENTER,
|
|
|
|
.layout.align.y = OC_UI_ALIGN_START },
|
|
|
|
OC_UI_STYLE_LAYOUT);
|
|
|
|
|
|
|
|
oc_ui_box_begin(str, OC_UI_FLAG_DRAW_BORDER);
|
|
|
|
oc_ui_label(str);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void widget_end_view(void)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_box_end();
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
#define widget_view(s) oc_defer_loop(widget_begin_view(s), widget_end_view())
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_init();
|
|
|
|
oc_clock_init(); //TODO put that in oc_init()?
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_context context;
|
|
|
|
oc_ui_init(&context);
|
|
|
|
oc_ui_set_context(&context);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_rect windowRect = { .x = 100, .y = 100, .w = 810, .h = 610 };
|
|
|
|
oc_window window = oc_window_create(windowRect, OC_STR8("test"), 0);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_rect contentRect = oc_window_get_content_rect(window);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
//NOTE: create surface
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface surface = oc_surface_create_for_window(window, OC_CANVAS);
|
|
|
|
oc_surface_swap_interval(surface, 0);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
//TODO: create canvas
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_canvas canvas = oc_canvas_create();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_canvas_is_nil(canvas))
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_error("Error: couldn't create canvas\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_font font = create_font();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_arena textArena = { 0 };
|
|
|
|
oc_arena_init(&textArena);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
// start app
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_window_bring_to_front(window);
|
|
|
|
oc_window_focus(window);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
while(!oc_should_quit())
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_arena* scratch = oc_scratch();
|
|
|
|
|
2023-08-19 12:49:23 +00:00
|
|
|
bool printDebugStyle = false;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
f64 startTime = oc_clock_time(OC_CLOCK_MONOTONIC);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_pump_events(0);
|
|
|
|
oc_event* event = 0;
|
|
|
|
while((event = oc_next_event(scratch)) != 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_process_event(event);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
switch(event->type)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_EVENT_WINDOW_CLOSE:
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_request_quit();
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
case OC_EVENT_KEYBOARD_KEY:
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
if(event->key.action == OC_KEY_PRESS && event->key.code == OC_KEY_P)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
printDebugStyle = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TEST UI
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style defaultStyle = { .bgColor = { 0 },
|
|
|
|
.color = { 1, 1, 1, 1 },
|
|
|
|
.font = font,
|
|
|
|
.fontSize = 16,
|
|
|
|
.borderColor = { 1, 0, 0, 1 },
|
|
|
|
.borderSize = 2 };
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_mask defaultMask = OC_UI_STYLE_BG_COLOR
|
|
|
|
| OC_UI_STYLE_COLOR
|
|
|
|
| OC_UI_STYLE_BORDER_COLOR
|
|
|
|
| OC_UI_STYLE_BORDER_SIZE
|
|
|
|
| OC_UI_STYLE_FONT
|
|
|
|
| OC_UI_STYLE_FONT_SIZE;
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_flags debugFlags = OC_UI_FLAG_DRAW_BORDER;
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_box* root = 0;
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_vec2 frameSize = oc_surface_get_size(surface);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_frame(frameSize, &defaultStyle, defaultMask)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
root = oc_ui_box_top();
|
|
|
|
oc_ui_style_match_before(oc_ui_pattern_all(), &defaultStyle, defaultMask);
|
|
|
|
|
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.layout.axis = OC_UI_AXIS_Y,
|
|
|
|
.layout.align.x = OC_UI_ALIGN_CENTER,
|
|
|
|
.layout.align.y = OC_UI_ALIGN_START,
|
|
|
|
.layout.spacing = 10,
|
|
|
|
.layout.margin.x = 10,
|
|
|
|
.layout.margin.y = 10,
|
|
|
|
.bgColor = { 0.11, 0.11, 0.11, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE
|
|
|
|
| OC_UI_STYLE_LAYOUT
|
|
|
|
| OC_UI_STYLE_BG_COLOR);
|
|
|
|
|
|
|
|
oc_ui_container("background", OC_UI_FLAG_DRAW_BACKGROUND)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_CHILDREN },
|
|
|
|
.layout.align.x = OC_UI_ALIGN_CENTER },
|
|
|
|
OC_UI_STYLE_SIZE
|
|
|
|
| OC_UI_STYLE_LAYOUT_ALIGN_X);
|
|
|
|
oc_ui_container("title", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .fontSize = 26 }, OC_UI_STYLE_FONT_SIZE);
|
|
|
|
oc_ui_label("Orca UI Demo");
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_ui_box_sig(oc_ui_box_top()).hovering)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_tooltip("tooltip")
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .bgColor = { 1, 0.99, 0.82, 1 } },
|
|
|
|
OC_UI_STYLE_BG_COLOR);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_container("background", OC_UI_FLAG_DRAW_BACKGROUND)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .color = { 0, 0, 0, 1 } },
|
|
|
|
OC_UI_STYLE_COLOR);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_label("That is a tooltip!");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu_bar("Menu bar")
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu("Menu 1")
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_ui_menu_button("Option 1.1").pressed)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("Pressed option 1.1\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu_button("Option 1.2");
|
|
|
|
oc_ui_menu_button("Option 1.3");
|
|
|
|
oc_ui_menu_button("Option 1.4");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu("Menu 2")
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu_button("Option 2.1");
|
|
|
|
oc_ui_menu_button("Option 2.2");
|
|
|
|
oc_ui_menu_button("Option 2.3");
|
|
|
|
oc_ui_menu_button("Option 2.4");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu("Menu 3")
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_menu_button("Option 3.1");
|
|
|
|
oc_ui_menu_button("Option 3.2");
|
|
|
|
oc_ui_menu_button("Option 3.3");
|
|
|
|
oc_ui_menu_button("Option 3.4");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X }, OC_UI_STYLE_LAYOUT_AXIS);
|
|
|
|
oc_ui_container("contents", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.borderColor = { 0, 0, 1, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE
|
|
|
|
| OC_UI_STYLE_BORDER_COLOR);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_container("left", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
|
|
|
|
.layout.spacing = 10,
|
|
|
|
.layout.margin.x = 10,
|
|
|
|
.layout.margin.y = 10,
|
|
|
|
.size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.5 } },
|
|
|
|
OC_UI_STYLE_LAYOUT_AXIS
|
|
|
|
| OC_UI_STYLE_LAYOUT_SPACING
|
|
|
|
| OC_UI_STYLE_LAYOUT_MARGIN_X
|
|
|
|
| OC_UI_STYLE_LAYOUT_MARGIN_Y
|
|
|
|
| OC_UI_STYLE_SIZE);
|
|
|
|
|
|
|
|
oc_ui_container("up", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
widget_view("Buttons")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_ui_button("Test Dialog").clicked)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
static oc_str8 options_strings[] = {
|
|
|
|
OC_STR8_LIT("Accept"),
|
|
|
|
OC_STR8_LIT("Reject"),
|
|
|
|
};
|
|
|
|
|
|
|
|
oc_str8_list options = { 0 };
|
|
|
|
oc_str8_list_push(scratch, &options, options_strings[0]);
|
|
|
|
oc_str8_list_push(scratch, &options, options_strings[1]);
|
|
|
|
|
|
|
|
int res = oc_alert_popup(OC_STR8("test dialog"), OC_STR8("dialog message"), options);
|
2023-08-19 12:49:23 +00:00
|
|
|
if(res >= 0)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("selected options %i: %s\n", res, options_strings[res].ptr);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_log_info("no options selected\n");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_ui_button("Open").clicked)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_str8_list filters = { 0 };
|
|
|
|
oc_str8_list_push(scratch, &filters, OC_STR8("md"));
|
|
|
|
|
|
|
|
oc_str8 file = oc_open_dialog(scratch, OC_STR8("Open File"), OC_STR8("C:\\Users"), filters, false);
|
|
|
|
oc_log_info("selected file %.*s\n", (int)file.len, file.ptr);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
if(oc_ui_button("Save").clicked)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_str8_list filters = { 0 };
|
|
|
|
|
|
|
|
oc_str8 file = oc_save_dialog(scratch, OC_STR8("Save File"), OC_STR8("C:\\Users"), filters);
|
|
|
|
oc_log_info("selected file %.*s\n", (int)file.len, file.ptr);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_pattern pattern = { 0 };
|
|
|
|
oc_ui_pattern_push(scratch, &pattern, (oc_ui_selector){ .kind = OC_UI_SEL_TAG, .tag = oc_ui_tag_make("checkbox") });
|
|
|
|
oc_ui_style_match_after(pattern,
|
|
|
|
&(oc_ui_style){ .bgColor = { 0, 1, 0, 1 },
|
|
|
|
.color = { 1, 1, 1, 1 } },
|
|
|
|
OC_UI_STYLE_COLOR | OC_UI_STYLE_BG_COLOR);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
widget_view("checkboxes")
|
|
|
|
{
|
|
|
|
static bool check1 = true;
|
|
|
|
static bool check2 = false;
|
|
|
|
static bool check3 = false;
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_checkbox("check1", &check1);
|
|
|
|
oc_ui_checkbox("check2", &check2);
|
|
|
|
oc_ui_checkbox("check3", &check3);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
|
|
|
|
.size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.5 } },
|
|
|
|
OC_UI_STYLE_LAYOUT_AXIS
|
|
|
|
| OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_container("down", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
widget_view("Vertical Sliders")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
|
|
|
|
.layout.spacing = 10 },
|
|
|
|
OC_UI_STYLE_LAYOUT_AXIS
|
|
|
|
| OC_UI_STYLE_LAYOUT_SPACING);
|
|
|
|
oc_ui_container("contents", 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 200 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider1 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider1", 0.2, &slider1);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 200 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider2 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider2", 0.2, &slider2);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 20 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 200 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider3 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider3", 0.2, &slider3);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_view("Horizontal Sliders")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 20 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider1 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider1", 0.2, &slider1);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 20 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider2 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider2", 0.2, &slider2);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 200 },
|
|
|
|
.size.height = { OC_UI_SIZE_PIXELS, 20 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
static f32 slider3 = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_slider("slider3", 0.2, &slider3);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 0.5 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 1 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_container("right", debugFlags)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.33 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
widget_view("Text box")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PIXELS, 300 },
|
|
|
|
.size.height = { OC_UI_SIZE_TEXT } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
|
|
|
static oc_str8 text = { 0 };
|
|
|
|
oc_ui_text_box_result res = oc_ui_text_box("textbox", oc_scratch(), text);
|
2023-08-19 12:49:23 +00:00
|
|
|
if(res.changed)
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_arena_clear(&textArena);
|
|
|
|
text = oc_str8_push_copy(&textArena, res.text);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.33 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
widget_view("Test")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_pattern pattern = { 0 };
|
|
|
|
oc_ui_pattern_push(oc_scratch(), &pattern, (oc_ui_selector){ .kind = OC_UI_SEL_TEXT, .text = OC_STR8("panel") });
|
|
|
|
oc_ui_style_match_after(pattern, &(oc_ui_style){ .bgColor = { 0.3, 0.3, 1, 1 } }, OC_UI_STYLE_BG_COLOR);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
static int selected = 0;
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_str8 options[] = { OC_STR8("option 1"),
|
|
|
|
OC_STR8("option 2"),
|
|
|
|
OC_STR8("long option 3"),
|
|
|
|
OC_STR8("option 4"),
|
|
|
|
OC_STR8("option 5") };
|
|
|
|
oc_ui_select_popup_info info = { .selectedIndex = selected,
|
|
|
|
.optionCount = 5,
|
|
|
|
.options = options };
|
|
|
|
|
|
|
|
oc_ui_select_popup_info result = oc_ui_select_popup("popup", &info);
|
2023-08-19 12:49:23 +00:00
|
|
|
selected = result.selectedIndex;
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.33 } },
|
|
|
|
OC_UI_STYLE_SIZE);
|
2023-08-19 12:49:23 +00:00
|
|
|
widget_view("Color")
|
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .size.width = { OC_UI_SIZE_PARENT, 1 },
|
|
|
|
.size.height = { OC_UI_SIZE_PARENT, 0.7 },
|
|
|
|
.layout.axis = OC_UI_AXIS_X },
|
|
|
|
OC_UI_STYLE_SIZE
|
|
|
|
| OC_UI_STYLE_LAYOUT_AXIS);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_panel("Panel", OC_UI_FLAG_DRAW_BORDER)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X },
|
|
|
|
OC_UI_STYLE_LAYOUT_AXIS);
|
|
|
|
oc_ui_container("contents", 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.spacing = 20 },
|
|
|
|
OC_UI_STYLE_LAYOUT_SPACING);
|
|
|
|
oc_ui_container("buttons", 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_button("Button A");
|
|
|
|
oc_ui_button("Button B");
|
|
|
|
oc_ui_button("Button C");
|
|
|
|
oc_ui_button("Button D");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_style_next(&(oc_ui_style){ .layout.axis = OC_UI_AXIS_X,
|
|
|
|
.layout.spacing = 20 },
|
|
|
|
OC_UI_STYLE_LAYOUT_SPACING
|
|
|
|
| OC_UI_STYLE_LAYOUT_AXIS);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_container("buttons2", 0)
|
2023-08-19 12:49:23 +00:00
|
|
|
{
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_button("Button A");
|
|
|
|
oc_ui_button("Button B");
|
|
|
|
oc_ui_button("Button C");
|
|
|
|
oc_ui_button("Button D");
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(printDebugStyle)
|
|
|
|
{
|
|
|
|
debug_print_styles(root, 0);
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_select(surface);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_ui_draw();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_render(surface, canvas);
|
|
|
|
oc_surface_present(surface);
|
2023-08-19 12:49:23 +00:00
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_arena_clear(scratch);
|
2023-08-19 12:49:23 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 22:30:20 +00:00
|
|
|
oc_surface_destroy(surface);
|
|
|
|
oc_terminate();
|
2023-08-19 12:49:23 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|