mouse can now hit widget buttons
This commit is contained in:
parent
00995188aa
commit
dd3f253a76
1 changed files with 33 additions and 10 deletions
43
src/app.c
43
src/app.c
|
|
@ -660,20 +660,43 @@ void app_mouse_event_listener(int8_t mouse_dx, int8_t mouse_dy, uint8_t buttons)
|
|||
#endif
|
||||
if (mouse_y < 0) mouse_y = 0;
|
||||
if (mouse_y >= fb_height()) mouse_y = fb_height() - 1;
|
||||
|
||||
// button click
|
||||
// TODO for now, only the topmost window can be hit
|
||||
if (buttons & MOUSE_BUTTON_LEFT) {
|
||||
// search for element that was hit
|
||||
int mouse_rel_x = mouse_x - app_root->pos.x;
|
||||
int mouse_rel_y = mouse_y - app_root->pos.y;
|
||||
struct component_focus focus = { .root = app_root->focus.root, .it = { .cpnt = app_root->focus.root, .stack_depth = 0}};
|
||||
component_focus_cycle(&focus);
|
||||
struct Component *start = focus.curr;
|
||||
struct Component *found = NULL;
|
||||
do {
|
||||
if (RECT_CONTAINS(focus.curr->rect, mouse_rel_x, mouse_rel_y)) {
|
||||
found = focus.curr;
|
||||
break;
|
||||
}
|
||||
component_focus_cycle(&focus);
|
||||
} while (focus.curr != start);
|
||||
|
||||
if (found != NULL) {
|
||||
// re-focus to hit element
|
||||
app_component_redraw(app_root->app, app_root->focus.curr);
|
||||
app_root->focus = focus;
|
||||
draw_focus(app_root->app, app_root->focus.curr);
|
||||
|
||||
// if it was button, click directly
|
||||
if (found->type == CPNT_TYPE_BUTTON) {
|
||||
found->data.button.on_click(app_root->app, app_root->focus.curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw mouse
|
||||
struct tex fb_tex = fb_as_tex();
|
||||
struct rect r = RECT_XYWH(mouse_x, mouse_y, 5, 5);
|
||||
tex_fill_region(&fb_tex, COLOR_LUMA(20), &r);
|
||||
fb_damage(r);
|
||||
|
||||
// button click
|
||||
if (buttons & MOUSE_BUTTON_LEFT) {
|
||||
// search for element that was hit
|
||||
TODO();
|
||||
// re-focus to hit element
|
||||
TODO();
|
||||
// if it was button, click directly
|
||||
TODO();
|
||||
}
|
||||
}
|
||||
|
||||
extern struct app_template app_calculator_template;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue