@@ -30,7 +30,9 @@ get_menu_bg_animation(const mb_shell::menu_widget *menu) {
3030
3131mb_shell::menu_animation_rect make_collapsed_rect (
3232 float target_x, float target_y, float target_width, float target_height,
33- const mb_shell::config::context_menu::theme::animation::bg &anim) {
33+ const mb_shell::config::context_menu::theme::animation::bg &anim,
34+ mb_shell::popup_direction direction =
35+ mb_shell::popup_direction::bottom_right) {
3436 if (target_width <= 0 || target_height <= 0 ) {
3537 return {.x = target_x,
3638 .y = target_y,
@@ -42,9 +44,19 @@ mb_shell::menu_animation_rect make_collapsed_rect(
4244 auto height_scale = std::clamp (anim.appear_h_scale , 0 .f , 1 .f );
4345 auto start_width = std::max (1 .f , target_width * width_scale);
4446 auto start_height = std::max (1 .f , target_height * height_scale);
45-
46- return {.x = target_x + (target_width - start_width) / 2 .f ,
47- .y = target_y + (target_height - start_height) / 2 .f ,
47+ const auto start_x =
48+ direction == mb_shell::popup_direction::top_left ||
49+ direction == mb_shell::popup_direction::bottom_left
50+ ? target_x + (target_width - start_width)
51+ : target_x;
52+ const auto start_y =
53+ direction == mb_shell::popup_direction::top_left ||
54+ direction == mb_shell::popup_direction::top_right
55+ ? target_y + (target_height - start_height)
56+ : target_y;
57+
58+ return {.x = start_x,
59+ .y = start_y,
4860 .width = start_width,
4961 .height = start_height};
5062}
@@ -58,6 +70,24 @@ make_bg_target_rect(const mb_shell::menu_widget *menu, float target_x,
5870 .height = target_height + menu->bg_padding_vertical * 2 };
5971}
6072
73+ mb_shell::popup_direction get_parent_menu_direction (
74+ const mb_shell::menu_item_widget *item) {
75+ if (auto menu =
76+ const_cast <mb_shell::menu_item_widget *>(item)
77+ ->search_parent <mb_shell::menu_widget>()) {
78+ return menu->direction ;
79+ }
80+ return mb_shell::popup_direction::bottom_right;
81+ }
82+
83+ float get_item_appear_offset_x (const mb_shell::menu_item_widget *item) {
84+ const auto direction = get_parent_menu_direction (item);
85+ return direction == mb_shell::popup_direction::top_left ||
86+ direction == mb_shell::popup_direction::bottom_left
87+ ? 20 .0f
88+ : -20 .0f ;
89+ }
90+
6191} // namespace
6292/*
6393| padding | icon_padding | icon | icon_padding | text_padding | text |
@@ -352,7 +382,7 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
352382 is_top_level_menu
353383 ? make_collapsed_rect (target_rect.x , target_rect.y ,
354384 target_rect.width , target_rect.height ,
355- get_menu_bg_animation (this ))
385+ get_menu_bg_animation (this ), direction )
356386 : target_rect);
357387 bg->x ->reset_to (start_rect.x );
358388 bg->y ->reset_to (start_rect.y );
@@ -648,7 +678,7 @@ void mb_shell::menu_item_normal_widget::reset_appear_animation(float delay) {
648678 this ->opacity ->set_delay (0 );
649679 };
650680 opacity->reset_to (0 );
651- this ->x ->reset_to (- 20 );
681+ this ->x ->reset_to (get_item_appear_offset_x ( this ) );
652682 text_blur->reset_to (
653683 config::current->context_menu .theme .animation .item .appear_blur );
654684
@@ -738,9 +768,6 @@ void mb_shell::menu_widget::reset_animation(bool reverse) {
738768 // the show duration for the menu should be within 200ms
739769 float delay = std::min (200 .f / children.size (), 30 .f );
740770
741- if (config::current->context_menu .reverse_if_open_to_up && reverse)
742- reverse = !reverse;
743-
744771 for (size_t i = 0 ; i < children.size (); i++) {
745772 auto child = children[i];
746773 child->reset_appear_animation (delay *
@@ -1015,7 +1042,7 @@ void mb_shell::menu_item_parent_widget::update(ui::update_context &ctx) {
10151042}
10161043void mb_shell::menu_item_parent_widget::reset_appear_animation (float delay) {
10171044 y->set_easing (ui::easing_type::mutation);
1018- x->reset_to (- 20 );
1045+ x->reset_to (get_item_appear_offset_x ( this ) );
10191046 x->animate_to (0 );
10201047 opacity->reset_to (0 );
10211048 opacity->animate_to (255 );
@@ -1088,7 +1115,7 @@ void mb_shell::menu_item_normal_widget::show_submenu(ui::update_context &ctx) {
10881115 submenu_wid->height ->dest ());
10891116 auto start_bg = make_collapsed_rect (
10901117 target_bg.x , target_bg.y , target_bg.width , target_bg.height ,
1091- config::current->context_menu .theme .animation .submenu_bg );
1118+ config::current->context_menu .theme .animation .submenu_bg , direction );
10921119 submenu_wid->x ->reset_to (target_x);
10931120 submenu_wid->y ->reset_to (target_y);
10941121
0 commit comments