[ui, logging]
- Changed workings of ui_panel() and scrolling to make it easier for usage code to control scrolling. - Renamed logging functions
This commit is contained in:
parent
bb6b68ad73
commit
7c273f494b
|
@ -1990,47 +1990,6 @@ void mp_pump_events(f64 timeout)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void mp_run_loop()
|
||||
{@autoreleasepool {
|
||||
|
||||
//CVDisplayLinkStart(__mpApp.displayLink);
|
||||
|
||||
while(!__mpApp.shouldQuit)
|
||||
{
|
||||
mp_event event;
|
||||
while(mp_next_event(&event))
|
||||
{
|
||||
//send pending event that might have accumulated before we started run loop
|
||||
if(__mpApp.eventCallback)
|
||||
{
|
||||
__mpApp.eventCallback(event, __mpApp.eventData);
|
||||
}
|
||||
}
|
||||
|
||||
NSEvent* nsEvent = [NSApp nextEventMatchingMask: NSEventMaskAny
|
||||
untilDate:[NSDate distantFuture]
|
||||
inMode: NSDefaultRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
if(nsEvent != nil)
|
||||
{
|
||||
[NSApp sendEvent:nsEvent];
|
||||
}
|
||||
}
|
||||
|
||||
//CVDisplayLinkStop(__mpApp.displayLink);
|
||||
}}
|
||||
*/
|
||||
void mp_end_input_frame()
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//TODO: make sure we call arena clear once per event frame, even when using runloop etc...
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mem_arena_clear(&__mpApp.eventArena);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// app resources
|
||||
//--------------------------------------------------------------------
|
||||
|
|
|
@ -24,14 +24,14 @@ typedef struct log_output
|
|||
static log_output _logDefaultOutput = {.kind = ORCA_LOG_OUTPUT_CONSOLE};
|
||||
log_output* LOG_DEFAULT_OUTPUT = &_logDefaultOutput;
|
||||
|
||||
extern void orca_log_entry(log_level level,
|
||||
int fileLen,
|
||||
const char* file,
|
||||
int functionLen,
|
||||
const char* function,
|
||||
int line,
|
||||
int msgLen,
|
||||
const char* msg);
|
||||
extern void orca_log(log_level level,
|
||||
int fileLen,
|
||||
const char* file,
|
||||
int functionLen,
|
||||
const char* function,
|
||||
int line,
|
||||
int msgLen,
|
||||
const char* msg);
|
||||
|
||||
typedef struct orca_log_context
|
||||
{
|
||||
|
@ -49,13 +49,13 @@ char* log_stbsp_callback(char const* buf, void* user, int len)
|
|||
return((char*)buf);
|
||||
}
|
||||
|
||||
void platform_log_entry(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap)
|
||||
void platform_log_push(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap)
|
||||
{
|
||||
mem_arena* scratch = mem_scratch();
|
||||
mem_arena_marker marker = mem_arena_mark(scratch);
|
||||
|
@ -68,7 +68,7 @@ void platform_log_entry(log_output* output,
|
|||
|
||||
str8 string = str8_list_join(scratch, ctx.list);
|
||||
|
||||
orca_log_entry(level, str8_ip(function), str8_ip(file), line, str8_ip(string));
|
||||
orca_log(level, str8_ip(function), str8_ip(file), line, str8_ip(string));
|
||||
|
||||
mem_arena_clear_to(scratch, marker);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ typedef struct log_config
|
|||
log_level level;
|
||||
} log_config;
|
||||
|
||||
//TODO: make default output a compile-time constant to avoid check in log_entry()?
|
||||
//TODO: make default output a compile-time constant to avoid check in log_push()?
|
||||
static log_config __logConfig = {0, LOG_LEVEL_INFO};
|
||||
|
||||
void log_set_output(log_output* output)
|
||||
|
@ -26,15 +26,15 @@ void log_set_level(log_level level)
|
|||
__logConfig.level = level;
|
||||
}
|
||||
|
||||
void platform_log_entry(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap);
|
||||
void platform_log_push(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap);
|
||||
|
||||
void log_entry(log_level level,
|
||||
void log_push(log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
|
@ -50,7 +50,7 @@ void log_entry(log_level level,
|
|||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
platform_log_entry(__logConfig.output, level, function, file, line, fmt, ap);
|
||||
platform_log_push(__logConfig.output, level, function, file, line, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ extern log_output* LOG_DEFAULT_OUTPUT;
|
|||
|
||||
MP_API void log_set_level(log_level level);
|
||||
MP_API void log_set_output(log_output* output);
|
||||
MP_API void log_entry(log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
...);
|
||||
MP_API void log_push(log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
...);
|
||||
|
||||
#define log_generic(level, msg, ...) log_entry(level, STR8(__FUNCTION__), STR8(__FILE__), __LINE__, msg, ##__VA_ARGS__)
|
||||
#define log_generic(level, msg, ...) log_push(level, STR8(__FUNCTION__), STR8(__FILE__), __LINE__, msg, ##__VA_ARGS__)
|
||||
|
||||
#define log_error(msg, ...) log_generic(LOG_LEVEL_ERROR, msg, ##__VA_ARGS__)
|
||||
|
||||
|
|
|
@ -36,13 +36,13 @@ typedef struct log_output
|
|||
static log_output _logDefaultOutput = {0};
|
||||
log_output* LOG_DEFAULT_OUTPUT = &_logDefaultOutput;
|
||||
|
||||
void platform_log_entry(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap)
|
||||
void platform_log_push(log_output* output,
|
||||
log_level level,
|
||||
str8 function,
|
||||
str8 file,
|
||||
int line,
|
||||
const char* fmt,
|
||||
va_list ap)
|
||||
{
|
||||
if(output == LOG_DEFAULT_OUTPUT && output->f == 0)
|
||||
{
|
||||
|
|
43
src/ui.c
43
src/ui.c
|
@ -447,6 +447,18 @@ ui_box* ui_box_make_str8(str8 string, ui_flags flags)
|
|||
}
|
||||
ui->nextBoxAfterRules = (list_info){0};
|
||||
|
||||
|
||||
//NOTE: set scroll
|
||||
vec2 wheel = ui_mouse_wheel();
|
||||
if(box->flags & UI_FLAG_SCROLL_WHEEL_X)
|
||||
{
|
||||
box->scroll.x += wheel.x;
|
||||
}
|
||||
if(box->flags & UI_FLAG_SCROLL_WHEEL_Y)
|
||||
{
|
||||
box->scroll.y += wheel.y;
|
||||
}
|
||||
|
||||
return(box);
|
||||
}
|
||||
|
||||
|
@ -1155,6 +1167,9 @@ void ui_layout_compute_rect(ui_context* ui, ui_box* box, vec2 pos)
|
|||
- (box->childrenSum[layoutAxis] + box->spacing[layoutAxis]));
|
||||
}
|
||||
|
||||
currentPos.x -= box->scroll.x;
|
||||
currentPos.y -= box->scroll.y;
|
||||
|
||||
for_list(&box->children, child, ui_box, listElt)
|
||||
{
|
||||
if(align[secondAxis] == UI_ALIGN_CENTER)
|
||||
|
@ -1796,29 +1811,22 @@ ui_box* ui_slider(const char* label, f32 thumbRatio, f32* scrollValue)
|
|||
//------------------------------------------------------------------------------
|
||||
void ui_panel_begin(const char* str, ui_flags flags)
|
||||
{
|
||||
ui_box* box = ui_box_begin(str, flags | UI_FLAG_CLIP | UI_FLAG_BLOCK_MOUSE);
|
||||
flags = flags
|
||||
| UI_FLAG_CLIP
|
||||
| UI_FLAG_BLOCK_MOUSE
|
||||
| UI_FLAG_ALLOW_OVERFLOW_X
|
||||
| UI_FLAG_ALLOW_OVERFLOW_Y;
|
||||
|
||||
ui_style contentsStyle = {
|
||||
.size.width = {UI_SIZE_CHILDREN},
|
||||
.size.height = {UI_SIZE_CHILDREN},
|
||||
.floating.x = true,
|
||||
.floating.y = true,
|
||||
.floatTarget = {-box->scroll.x, -box->scroll.y}};
|
||||
|
||||
ui_style_next(&contentsStyle, UI_STYLE_FLOAT);
|
||||
ui_box_begin("contents", 0);
|
||||
ui_box_begin(str, flags);
|
||||
}
|
||||
|
||||
void ui_panel_end(void)
|
||||
{
|
||||
ui_box* contents = ui_box_top();
|
||||
ui_box_end();
|
||||
|
||||
ui_box* panel = ui_box_top();
|
||||
ui_sig sig = ui_box_sig(panel);
|
||||
|
||||
f32 contentsW = ClampLowBound(contents->rect.w, panel->rect.w);
|
||||
f32 contentsH = ClampLowBound(contents->rect.h, panel->rect.h);
|
||||
f32 contentsW = ClampLowBound(panel->childrenSum[0], panel->rect.w);
|
||||
f32 contentsH = ClampLowBound(panel->childrenSum[1], panel->rect.h);
|
||||
|
||||
contentsW = ClampLowBound(contentsW, 1);
|
||||
contentsH = ClampLowBound(contentsH, 1);
|
||||
|
@ -1847,7 +1855,6 @@ void ui_panel_end(void)
|
|||
panel->scroll.x = sliderX * (contentsW - panel->rect.w);
|
||||
if(sig.hovering)
|
||||
{
|
||||
panel->scroll.x += sig.wheel.x;
|
||||
ui_box_activate(scrollBarX);
|
||||
}
|
||||
}
|
||||
|
@ -1872,7 +1879,6 @@ void ui_panel_end(void)
|
|||
panel->scroll.y = sliderY * (contentsH - panel->rect.h);
|
||||
if(sig.hovering)
|
||||
{
|
||||
panel->scroll.y += sig.wheel.y;
|
||||
ui_box_activate(scrollBarY);
|
||||
}
|
||||
}
|
||||
|
@ -2645,8 +2651,7 @@ ui_text_box_result ui_text_box(const char* name, mem_arena* arena, str8 text)
|
|||
| UI_FLAG_DRAW_BACKGROUND
|
||||
| UI_FLAG_DRAW_BORDER
|
||||
| UI_FLAG_CLIP
|
||||
| UI_FLAG_DRAW_PROC
|
||||
| UI_FLAG_SCROLLABLE;
|
||||
| UI_FLAG_DRAW_PROC;
|
||||
|
||||
ui_box* frame = ui_box_make(name, frameFlags);
|
||||
ui_style* style = &frame->style;
|
||||
|
|
33
src/ui.h
33
src/ui.h
|
@ -131,6 +131,9 @@ enum
|
|||
UI_STYLE_SIZE = UI_STYLE_SIZE_WIDTH
|
||||
| UI_STYLE_SIZE_HEIGHT,
|
||||
|
||||
UI_STYLE_LAYOUT_MARGINS = UI_STYLE_LAYOUT_MARGIN_X
|
||||
| UI_STYLE_LAYOUT_MARGIN_Y,
|
||||
|
||||
UI_STYLE_LAYOUT = UI_STYLE_LAYOUT_AXIS
|
||||
| UI_STYLE_LAYOUT_ALIGN_X
|
||||
| UI_STYLE_LAYOUT_ALIGN_Y
|
||||
|
@ -249,22 +252,23 @@ typedef void(*ui_box_draw_proc)(ui_box* box, void* data);
|
|||
typedef enum
|
||||
{
|
||||
UI_FLAG_CLICKABLE = (1<<0),
|
||||
UI_FLAG_SCROLLABLE = (1<<1),
|
||||
UI_FLAG_BLOCK_MOUSE = (1<<2),
|
||||
UI_FLAG_HOT_ANIMATION = (1<<3),
|
||||
UI_FLAG_ACTIVE_ANIMATION = (1<<4),
|
||||
UI_FLAG_SCROLL_WHEEL_X = (1<<1),
|
||||
UI_FLAG_SCROLL_WHEEL_Y = (1<<2),
|
||||
UI_FLAG_BLOCK_MOUSE = (1<<3),
|
||||
UI_FLAG_HOT_ANIMATION = (1<<4),
|
||||
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
|
||||
UI_FLAG_ALLOW_OVERFLOW_X = (1<<5),
|
||||
UI_FLAG_ALLOW_OVERFLOW_Y = (1<<6),
|
||||
UI_FLAG_CLIP = (1<<7),
|
||||
UI_FLAG_DRAW_BACKGROUND = (1<<8),
|
||||
UI_FLAG_DRAW_FOREGROUND = (1<<9),
|
||||
UI_FLAG_DRAW_BORDER = (1<<10),
|
||||
UI_FLAG_DRAW_TEXT = (1<<11),
|
||||
UI_FLAG_DRAW_PROC = (1<<12),
|
||||
UI_FLAG_ALLOW_OVERFLOW_X = (1<<6),
|
||||
UI_FLAG_ALLOW_OVERFLOW_Y = (1<<7),
|
||||
UI_FLAG_CLIP = (1<<8),
|
||||
UI_FLAG_DRAW_BACKGROUND = (1<<9),
|
||||
UI_FLAG_DRAW_FOREGROUND = (1<<10),
|
||||
UI_FLAG_DRAW_BORDER = (1<<11),
|
||||
UI_FLAG_DRAW_TEXT = (1<<12),
|
||||
UI_FLAG_DRAW_PROC = (1<<13),
|
||||
|
||||
UI_FLAG_OVERLAY = (1<<13),
|
||||
UI_FLAG_OVERLAY = (1<<14),
|
||||
} ui_flags;
|
||||
|
||||
struct ui_box
|
||||
|
@ -423,6 +427,7 @@ MP_API ui_box* ui_box_begin_str8(str8 string, ui_flags flags);
|
|||
|
||||
MP_API ui_box* ui_box_end(void);
|
||||
#define ui_container(name, flags) defer_loop(ui_box_begin(name, flags), ui_box_end())
|
||||
#define ui_container_str8(name, flags) defer_loop(ui_box_begin_str8(name, flags), ui_box_end())
|
||||
|
||||
MP_API void ui_box_push(ui_box* box);
|
||||
MP_API void ui_box_pop(void);
|
||||
|
@ -492,6 +497,8 @@ enum {
|
|||
};
|
||||
|
||||
MP_API ui_sig ui_label(const char* label);
|
||||
MP_API ui_sig ui_label_str8(str8 label);
|
||||
|
||||
MP_API ui_sig ui_button(const char* label);
|
||||
MP_API ui_sig ui_checkbox(const char* name, bool* checked);
|
||||
MP_API ui_box* ui_slider(const char* label, f32 thumbRatio, f32* scrollValue);
|
||||
|
|
Loading…
Reference in New Issue