Skip to content

Commit 6663b05

Browse files
fix(shell): submenu location with scroll
1 parent c80638c commit 6663b05

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/shell/contextmenu/menu_widget.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void mb_shell::mouse_menu_widget_main::update(ui::update_context &ctx) {
422422
if (ctx.hovered_widgets->empty()) {
423423
glfwSetWindowAttrib(ctx.rt.window, GLFW_MOUSE_PASSTHROUGH,
424424
using_touchscreen ? GLFW_FALSE : GLFW_TRUE);
425-
425+
426426
if ((ctx.mouse_clicked || ctx.right_mouse_clicked) ||
427427
GetAsyncKeyState(VK_LBUTTON) & 0x8000 ||
428428
GetAsyncKeyState(VK_RBUTTON) & 0x8000) {
@@ -772,6 +772,9 @@ void mb_shell::menu_item_normal_widget::show_submenu(ui::update_context &ctx) {
772772
auto [x, y] = mouse_menu_widget_main::calculate_position(
773773
submenu_wid.get(), ctx, anchor_x, anchor_y, direction);
774774

775+
if (auto parent = search_parent<menu_widget>())
776+
y += *parent->scroll_top * ctx.rt.dpi_scale;
777+
775778
x -= ctx.offset_x * ctx.rt.dpi_scale;
776779
y -= ctx.offset_y * ctx.rt.dpi_scale;
777780

src/ui/widget.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ struct widget : std::enable_shared_from_this<widget> {
138138
widget* parent = nullptr;
139139
render_target *owner_rt = nullptr;
140140

141+
template<typename T> inline T* search_parent() {
142+
auto p = parent;
143+
while (p) {
144+
if (auto t = dynamic_cast<T*>(p)) {
145+
return t;
146+
}
147+
p = p->parent;
148+
}
149+
return nullptr;
150+
}
141151
virtual void render(nanovg_context ctx);
142152
virtual void update(update_context &ctx);
143153
virtual ~widget() = default;

0 commit comments

Comments
 (0)