Skip to content

Commit 12eaa6c

Browse files
refactor(menu_widget): separate scrollable_widget for handling scrolling
1 parent f3c02f2 commit 12eaa6c

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed

src/shell/contextmenu/menu_widget.cc

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "breeze_ui/nanovg_wrapper.h"
1111
#include "breeze_ui/ui.h"
1212
#include "breeze_ui/widget.h"
13+
#include "scrollable_widget.h"
1314
#include <algorithm>
1415
#include <iostream>
1516
#include <print>
@@ -302,20 +303,13 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
302303
bg_submenu->update(forkctx_1);
303304
}
304305

305-
if (ctx.hovered(this)) {
306-
scroll_top->animate_to(std::clamp(scroll_top->dest() + ctx.scroll_y * 100,
307-
height->dest() - actual_height, 0.f));
308-
}
309-
widget::update(ctx);
310-
ctx.hovered_hit(this);
311-
auto forkctx = ctx.with_offset(*x, *y + *scroll_top);
312-
update_children(forkctx, item_widgets);
313-
reposition_children_flex(forkctx, item_widgets);
306+
// Update scrollable children (item_widgets) through base class
307+
scrollable_widget::update(ctx);
308+
309+
// Set width for all items
314310
for (auto &item : item_widgets) {
315311
item->width->reset_to(*width);
316312
}
317-
actual_height = height->dest();
318-
height->reset_to(std::min(max_height, height->dest()));
319313

320314
if (bg) {
321315
bg->update(ctx);
@@ -526,33 +520,15 @@ void mb_shell::menu_widget::render(ui::nanovg_context ctx) {
526520
bg->render(ctx);
527521
}
528522

529-
ctx.transaction([&] {
530-
super::render(ctx);
531-
ctx.scissor(*x, *y, *width, *height);
532-
render_children(ctx.with_offset(*x, *y + *scroll_top), item_widgets);
533-
});
523+
// Render scrollable content (item_widgets) through base class
524+
scrollable_widget::render(ctx);
534525

535526
auto ctx2 = ctx.with_offset(*x, *y);
536527

537528
if (bg_submenu) {
538529
bg_submenu->render(ctx2);
539530
}
540531
render_children(ctx2, rendering_submenus);
541-
542-
// scrollbar
543-
if (height->dest() < actual_height) {
544-
auto scrollbar_width = config::current->context_menu.theme.scrollbar_width;
545-
auto scrollbar_height = height->dest() * height->dest() / actual_height;
546-
auto scrollbar_x = width->dest() - scrollbar_width - 2 + *x;
547-
auto scrollbar_y = *y - *scroll_top / (actual_height - height->dest()) *
548-
(height->dest() - scrollbar_height);
549-
550-
float c = menu_render::current.value()->light_color ? 0 : 1;
551-
ctx.fillColor(nvgRGBAf(c, c, c, 0.1));
552-
ctx.fillRoundedRect(scrollbar_x, scrollbar_y, scrollbar_width,
553-
scrollbar_height,
554-
config::current->context_menu.theme.scrollbar_radius);
555-
}
556532
}
557533
void mb_shell::menu_item_normal_widget::reset_appear_animation(float delay) {
558534
this->opacity->after_animate = [this](float dest) {

0 commit comments

Comments
 (0)