Skip to content

Commit 21044e3

Browse files
fix: crash when press left key on main menu
1 parent a5ca4b8 commit 21044e3

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

scripts/rebuild.nu

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/rebuild.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ foreach ($pidx in $pids) {
33
Stop-Process -Id $pidx -Force
44
}
55

6-
xmake f --toolchain=clang-cl -m releasedbg -y -c
6+
xmake f --toolchain=clang-cl -m releasedbg -y
77
xmake b --yes inject
88
xmake b --yes shell
99
if ($LASTEXITCODE -ne 0) {

src/shell/contextmenu/menu_widget.cc

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#include "shell/config.h"
1212
#include "shell/utils.h"
1313
#include <algorithm>
14-
#include <iostream>
15-
#include <spdlog/spdlog.h>
1614
#include <fmt/format.h>
15+
#include <iostream>
1716
#include <ranges>
17+
#include <spdlog/spdlog.h>
1818
#include <vector>
1919

2020
#include "shell/logger.h"
@@ -380,33 +380,37 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
380380
};
381381
if (ctx.key_pressed(GLFW_KEY_UP)) {
382382
move_key(false, children);
383+
ctx.need_repaint = true;
383384
} else if (ctx.key_pressed(GLFW_KEY_DOWN)) {
384385
move_key(true, children);
386+
ctx.need_repaint = true;
385387
} else if (ctx.key_pressed(GLFW_KEY_LEFT)) {
386-
// close submenu on left key
387-
if (parent_menu) {
388-
parent_menu->current_submenu = nullptr;
389-
close();
390-
}
391-
392388
ctx.stop_key_propagation(GLFW_KEY_LEFT);
393389

394390
if (parent_item_widget) {
395391
parent_item_widget->lock()->set_focus();
396-
} else {
392+
} else if (parent_menu) {
397393
parent_menu->set_focus();
394+
parent_menu->current_submenu = nullptr;
395+
close();
396+
} else {
397+
close();
398398
}
399+
400+
ctx.need_repaint = true;
399401
} else if (ctx.key_pressed(GLFW_KEY_RIGHT)) {
400402
auto focused_item = std::ranges::find_if(
401403
children, [](const auto &item) { return item->focused(); });
402404
if (focused_item != children.end()) {
403405
if (auto wid =
404406
(*focused_item)->downcast<menu_item_normal_widget>())
405-
if (wid->item.submenu && !wid->submenu_wid) {
406-
wid->show_submenu(ctx);
407+
if (wid->item.submenu) {
408+
if (!wid->submenu_wid)
409+
wid->show_submenu(ctx);
407410
current_submenu->set_focus();
408411
}
409412
}
413+
ctx.need_repaint = true;
410414
} else if (ctx.key_pressed(GLFW_KEY_ENTER) ||
411415
ctx.key_pressed(GLFW_KEY_SPACE)) { // Enter or Space key
412416
auto focused_item = std::ranges::find_if(
@@ -426,6 +430,7 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
426430
}
427431
}
428432
}
433+
ctx.need_repaint = true;
429434
} else {
430435
auto menus_matching_key =
431436
children | std::views::filter([&](const auto &item) {
@@ -509,6 +514,9 @@ void mb_shell::menu_widget::update(ui::update_context &ctx) {
509514
}) |
510515
std::ranges::to<std::vector>();
511516

517+
if (menus_matching_key.size() > 0)
518+
ctx.need_repaint = true;
519+
512520
if (menus_matching_key.size() == 1) {
513521
auto wid = menus_matching_key.front()
514522
->downcast<mb_shell::menu_item_normal_widget>();
@@ -774,8 +782,8 @@ void mb_shell::mouse_menu_widget_main::calibrate_position(
774782
auto [x, y] =
775783
calculate_position(menu_wid.get(), ctx, anchor_x, anchor_y, direction);
776784

777-
spdlog::info("Calibrated position: {} {} in screen {} {}", x, y, ctx.screen.width,
778-
ctx.screen.height);
785+
spdlog::info("Calibrated position: {} {} in screen {} {}", x, y,
786+
ctx.screen.width, ctx.screen.height);
779787

780788
if (animated) {
781789
this->menu_wid->x->animate_to(x / ctx.rt.dpi_scale);
@@ -795,11 +803,11 @@ void mb_shell::mouse_menu_widget_main::calibrate_direction(
795803
direction == popup_direction::top_right);
796804

797805
spdlog::info("Calibrated direction: {}",
798-
direction == popup_direction::top_left ? "top_left"
799-
: direction == popup_direction::top_right ? "top_right"
800-
: direction == popup_direction::bottom_left ? "bottom_left"
801-
: direction == popup_direction::bottom_right ? "bottom_right"
802-
: "unknown");
806+
direction == popup_direction::top_left ? "top_left"
807+
: direction == popup_direction::top_right ? "top_right"
808+
: direction == popup_direction::bottom_left ? "bottom_left"
809+
: direction == popup_direction::bottom_right ? "bottom_right"
810+
: "unknown");
803811
}
804812

805813
bool mb_shell::menu_item_normal_widget::check_hit(

0 commit comments

Comments
 (0)