Skip to content

Commit 2b88b72

Browse files
refactor(ui): address remaining Sonar findings
1 parent 35fdc51 commit 2b88b72

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

tools/virtualhid_control.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,7 @@ namespace {
575575
void render_device_type_selector() {
576576
ImGui::TextUnformatted("Device type");
577577
const auto *choice = current_device_type_choice();
578-
const auto preview = choice == nullptr ? std::string {"Select device type"} : to_utf8(choice->label);
579-
if (!ImGui::BeginCombo("##device-type", preview.c_str())) {
578+
if (const auto preview = choice == nullptr ? std::string {"Select device type"} : to_utf8(choice->label); !ImGui::BeginCombo("##device-type", preview.c_str())) {
580579
return;
581580
}
582581

@@ -605,8 +604,7 @@ namespace {
605604
}
606605

607606
const auto *choice = current_profile_choice();
608-
const auto preview = choice == nullptr ? std::string {"Select profile"} : to_utf8(choice->label);
609-
if (!ImGui::BeginCombo("##profile", preview.c_str())) {
607+
if (const auto preview = choice == nullptr ? std::string {"Select profile"} : to_utf8(choice->label); !ImGui::BeginCombo("##profile", preview.c_str())) {
610608
return;
611609
}
612610

@@ -1001,25 +999,30 @@ namespace {
1001999
ImGui::TextWrapped("%s", backend.c_str());
10021000
ImGui::Separator();
10031001

1004-
const auto render_devices = [this, &devices] {
1002+
const auto create_device = [this] {
1003+
create_selected_device();
1004+
};
1005+
const auto reset_device = [this] {
1006+
reset_selected_device();
1007+
};
1008+
const auto remove_device = [this] {
1009+
remove_selected_device();
1010+
};
1011+
const auto remove_all = [this] {
1012+
remove_all_devices();
1013+
};
1014+
const auto show_error = [this](std::string_view message) {
1015+
error_panel_.show(message);
1016+
};
1017+
const auto render_devices = [this, &devices, &create_device, &reset_device, &remove_device, &remove_all, &show_error] {
10051018
device_panel_.render(
10061019
devices,
10071020
selected_id_,
1008-
[this] {
1009-
create_selected_device();
1010-
},
1011-
[this] {
1012-
reset_selected_device();
1013-
},
1014-
[this] {
1015-
remove_selected_device();
1016-
},
1017-
[this] {
1018-
remove_all_devices();
1019-
},
1020-
[this](std::string_view message) {
1021-
error_panel_.show(message);
1022-
}
1021+
create_device,
1022+
reset_device,
1023+
remove_device,
1024+
remove_all,
1025+
show_error
10231026
);
10241027
};
10251028

0 commit comments

Comments
 (0)