begin context menu
This commit is contained in:
@@ -175,6 +175,7 @@ const wasm_app_imports = {
|
||||
|
||||
addEventListener("resize", (event) => { wake_up(); });
|
||||
addEventListener("keydown", (event) => {
|
||||
event.preventDefault();
|
||||
wasm_exports["wasm_key_down"](mem.write_string_to_cglobal("wasm_temp_buff1", event.key), event.ctrlKey, event.shiftKey, event.altKey, event.metaKey);
|
||||
wake_up();
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ fn f64 f64_exp2(f64 x) {
|
||||
b * (U64_TO_F64(0x3F242C003E4A2000) +
|
||||
b * U64_TO_F64(0x3EF0B291F6C00000)))))));
|
||||
|
||||
const f64 m[8] = {
|
||||
f64 m[8] = {
|
||||
U64_TO_F64(0x3FF0000000000000),
|
||||
U64_TO_F64(0x3FF172B83C7D517B),
|
||||
U64_TO_F64(0x3FF306FE0A31B715),
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,11 +155,17 @@ fn b32 ui_is_focused_box(ui_box_t *box) { return !ui_is_null_box(box) && box->id
|
||||
#define ev_left_up(ev) ((ev)->kind == app_event_kind_mouse_up && ev_left(ev))
|
||||
#define ev_left_down(ev) ((ev)->kind == app_event_kind_mouse_down && ev_left(ev))
|
||||
|
||||
#define ev_right(ev) ((ev)->mouse_button == app_mouse_button_right)
|
||||
#define ev_right_up(ev) ((ev)->kind == app_event_kind_mouse_up && ev_right(ev))
|
||||
#define ev_right_down(ev) ((ev)->kind == app_event_kind_mouse_down && ev_right(ev))
|
||||
|
||||
|
||||
fn void ui_set_rect(ui_box_t *box, r2f32_t rect) { box->rect = box->full_rect = rect; }
|
||||
|
||||
#define UILOC (ui_code_loc_t){.file = __FILE__, .line = __LINE__, .counter = __COUNTER__}
|
||||
#define ui_em(x) ((x) * rn->main_font->size)
|
||||
#define ui_max 200000000.f
|
||||
#define ui_to_be_determined 0
|
||||
#define ui_box_flags(...) (ui_box_flag_t){__VA_ARGS__}
|
||||
|
||||
fn ui_id_t ui_id(s8_t string);
|
||||
|
||||
Reference in New Issue
Block a user