begin context menu
This commit is contained in:
63
src/ui/ui.c
63
src/ui/ui.c
@@ -279,6 +279,16 @@ fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn void ui_set_to_be_determined(ui_box_t *box, ui_axis2_t axis) {
|
||||
if (axis == ui_axis2_x) {
|
||||
box->full_rect.min.x = box->rect.max.x;
|
||||
box->full_rect.max.x = box->rect.min.x;
|
||||
} else if (axis == ui_axis2_y) {
|
||||
box->full_rect.min.y = box->rect.max.y;
|
||||
box->full_rect.max.y = box->rect.min.y;
|
||||
} else_is_invalid;
|
||||
}
|
||||
|
||||
fn v2f32_t ui_aligned_text_pos(f32 offset, ui_text_align_t text_align, r2f32_t rect, s8_t string) {
|
||||
v2f32_t string_size = rn_measure_string(rn->main_font, string);
|
||||
v2f32_t rect_size = r2f32_get_size(rect);
|
||||
@@ -305,7 +315,7 @@ fn ui_draw_compute_t ui_draw_compute(ui_box_t *box) {
|
||||
ui_draw_compute_t co = {0};
|
||||
|
||||
co.rect = box->full_rect;
|
||||
f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 6), 10);
|
||||
f32 appear_t = f32_ease_out_n(f32_clamp01(box->appear_t * 2), 10);
|
||||
if (!ui_id_is_null(box->id)) {
|
||||
v2f32_t size = v2f32_muls(r2f32_get_size(co.rect), 0.15f);
|
||||
r2f32_t smaller_rect = r2f32_shrink(co.rect, size);
|
||||
@@ -931,6 +941,7 @@ fn void ui_end_reversal(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(connected);
|
||||
|
||||
ui_box_t *first2 = NULL;
|
||||
@@ -950,7 +961,7 @@ fn void ui_end_reversal(void) {
|
||||
|
||||
|
||||
gb app_event_t ui_test_event;
|
||||
gb i32 ui_g_panel = 2;
|
||||
gb i32 ui_g_panel = 3;
|
||||
fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) {
|
||||
ui_begin_frame(frame);
|
||||
rn_begin_frame(frame);
|
||||
@@ -971,6 +982,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
ui_set_top(top_box) {
|
||||
ui_radio_button(&ui_g_panel, 1, "data");
|
||||
ui_radio_button(&ui_g_panel, 2, "log");
|
||||
ui_radio_button(&ui_g_panel, 3, "menus");
|
||||
}
|
||||
|
||||
ui->top->rect = r2f32_shrinks(ui->top->rect, ui_em(1));
|
||||
@@ -1273,6 +1285,51 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
}
|
||||
}
|
||||
|
||||
if (ui_g_panel == 3) {
|
||||
ui_box_t *item_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "item_box");
|
||||
ui_set_rect(item_box, r2f32_cut_left(&ui->top->rect, ui_max));
|
||||
ui_set_top(item_box) {
|
||||
ui_label("right click to bring up the context menu!");
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// context menu
|
||||
{
|
||||
|
||||
locl b32 context_menu_open;
|
||||
locl v2f32_t menu_pos;
|
||||
if (ev_right_down(ev)) {
|
||||
context_menu_open = 1;
|
||||
menu_pos = ev->mouse_pos;
|
||||
}
|
||||
|
||||
if (context_menu_open) {
|
||||
ui_box_t *menu = ui_boxf((ui_box_flags_t){.draw_border = true, .draw_rect = true}, "context_menu");
|
||||
ui_set_rect(menu, r2f32_min_dim(menu_pos, v2f32(ui_em(10), ui_to_be_determined)));
|
||||
|
||||
ui_set_top(menu)
|
||||
ui_set_text_align(ui_text_align_left)
|
||||
ui_set_string_pos_offset(ui_em(1))
|
||||
ui_set_padding(ui_em(0.2f)) {
|
||||
ui_label_button("file");
|
||||
ui_label_button("memes");
|
||||
}
|
||||
ui_set_to_be_determined(menu, ui_axis2_y);
|
||||
|
||||
|
||||
if (ev_left_down(ev) && !r2f32_contains(menu->full_rect, ev->mouse_pos)) {
|
||||
context_menu_open = 0;
|
||||
}
|
||||
if (ev_right_down(ev)) {
|
||||
menu->appear_t = 0;
|
||||
for (ui_box_t *it = menu->first; it; it = it->next) {
|
||||
it->appear_t = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ui_id_t lister_id = ui_id_from_loc(UILOC);
|
||||
locl b32 lister_open;
|
||||
@@ -1314,8 +1371,6 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ui_end_build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user