Skip to content

Commit 4017560

Browse files
feat(ui): hittest
1 parent ad72fff commit 4017560

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/shell/contextmenu/menu_widget.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,12 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
210210
bg->update(ctx);
211211

212212
ctx.mouse_clicked_on_hit(bg.get());
213+
ctx.hovered_hit(bg.get());
213214
}
214215
void mb_shell::menu_widget::render(ui::nanovg_context ctx) {
215216
std::lock_guard lock(data_lock);
216217
bg->render(ctx);
217218
super::render(ctx);
218-
219-
if (have_overlap) {
220-
std::println("Overlap detected");
221-
}
222219
}
223220
void mb_shell::menu_item_widget::reset_appear_animation(float delay) {
224221
this->opacity->after_animate = [this](float dest) {
@@ -267,7 +264,7 @@ void mb_shell::mouse_menu_widget_main::update(ui::update_context &ctx) {
267264

268265
menu_wid->update(ctx);
269266

270-
if (!ctx.hovered(menu_wid.get())) {
267+
if (!ctx.hovered(menu_wid.get(), false)) {
271268
glfwSetWindowAttrib(ctx.rt.window, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);
272269
if ((ctx.mouse_clicked || ctx.right_mouse_clicked) ||
273270
GetAsyncKeyState(VK_LBUTTON) & 0x8000 ||

src/ui/widget.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ void ui::widget::update(update_context &ctx) {
3838
anim->update(ctx.delta_t);
3939
}
4040
}
41-
bool ui::update_context::hovered(widget *w) const {
41+
bool ui::update_context::hovered(widget *w, bool hittest) const {
42+
if (hittest && !hovered_widgets.empty())
43+
return false;
44+
4245
return w->check_hit(*this);
4346
}
4447
float ui::widget::measure_height(update_context &ctx) { return height->dest(); }
@@ -87,10 +90,14 @@ void ui::widget_parent_flex::update(update_context &ctx) {
8790
void ui::update_context::set_hit_hovered(widget *w) {
8891
hovered_widgets.push_back(w->shared_from_this());
8992
}
90-
bool ui::update_context::mouse_clicked_on(widget *w) const {
93+
bool ui::update_context::mouse_clicked_on(widget *w, bool hittest) const {
94+
if (hittest && !clicked_widgets.empty())
95+
return false;
9196
return mouse_clicked && hovered(w);
9297
}
93-
bool ui::update_context::mouse_down_on(widget *w) const {
98+
bool ui::update_context::mouse_down_on(widget *w, bool hittest) const {
99+
if (hittest && !hovered_widgets.empty())
100+
return false;
94101
return mouse_down && hovered(w);
95102
}
96103
void ui::update_context::set_hit_clicked(widget *w) {
@@ -117,6 +124,4 @@ bool ui::widget::check_hit(const update_context &ctx) {
117124
ctx.mouse_y >= (y->dest() + ctx.offset_y) &&
118125
ctx.mouse_y <= (y->dest() + height->dest() + ctx.offset_y);
119126
}
120-
void ui::widget::render(nanovg_context ctx) {
121-
122-
}
127+
void ui::widget::render(nanovg_context ctx) {}

src/ui/widget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ struct update_context {
3131
void set_hit_hovered(widget *w);
3232
void set_hit_clicked(widget *w);
3333

34-
bool hovered(widget *w) const;
35-
bool mouse_clicked_on(widget *w) const;
36-
bool mouse_down_on(widget *w) const;
34+
bool hovered(widget *w, bool hittest = true) const;
35+
bool mouse_clicked_on(widget *w, bool hittest = true) const;
36+
bool mouse_down_on(widget *w, bool hittest = true) const;
3737

3838
bool mouse_clicked_on_hit(widget *w);
3939
bool hovered_hit(widget *w);

0 commit comments

Comments
 (0)