|
10 | 10 | #include "breeze_ui/nanovg_wrapper.h" |
11 | 11 | #include "breeze_ui/ui.h" |
12 | 12 | #include "breeze_ui/widget.h" |
| 13 | +#include "scrollable_widget.h" |
13 | 14 | #include <algorithm> |
14 | 15 | #include <iostream> |
15 | 16 | #include <print> |
@@ -302,20 +303,13 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) { |
302 | 303 | bg_submenu->update(forkctx_1); |
303 | 304 | } |
304 | 305 |
|
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 |
314 | 310 | for (auto &item : item_widgets) { |
315 | 311 | item->width->reset_to(*width); |
316 | 312 | } |
317 | | - actual_height = height->dest(); |
318 | | - height->reset_to(std::min(max_height, height->dest())); |
319 | 313 |
|
320 | 314 | if (bg) { |
321 | 315 | bg->update(ctx); |
@@ -526,33 +520,15 @@ void mb_shell::menu_widget::render(ui::nanovg_context ctx) { |
526 | 520 | bg->render(ctx); |
527 | 521 | } |
528 | 522 |
|
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); |
534 | 525 |
|
535 | 526 | auto ctx2 = ctx.with_offset(*x, *y); |
536 | 527 |
|
537 | 528 | if (bg_submenu) { |
538 | 529 | bg_submenu->render(ctx2); |
539 | 530 | } |
540 | 531 | 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 | | - } |
556 | 532 | } |
557 | 533 | void mb_shell::menu_item_normal_widget::reset_appear_animation(float delay) { |
558 | 534 | this->opacity->after_animate = [this](float dest) { |
|
0 commit comments