Skip to content

Commit cd7d4f9

Browse files
fix(virtualhid_control): improve compact layout (#61)
1 parent 15e89d8 commit cd7d4f9

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

docs/usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ normalized gamepad output such as rumble, RGB LED, adaptive trigger, trigger
103103
rumble, and raw report events delivered through the normal callback path. Button
104104
controls are momentary by default so they behave like physical gamepad buttons;
105105
enable `Lock buttons` to keep the old click-to-toggle behavior for held inputs.
106+
The resizable window supports a compact width. Its device and control panels
107+
stack, and the button grid reflows, to keep controls usable when it is narrowed.
106108
The UI intentionally does not use gamepad navigation so virtual devices created
107109
by the tool cannot drive the tool's own controls.
108110

tools/virtualhid_control.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,15 @@ namespace {
271271
ImGui::Begin("libvirtualhid control", nullptr, window_flags);
272272

273273
const auto backend = backend_text(*runtime_);
274-
ImGui::TextUnformatted(backend.c_str());
274+
ImGui::TextWrapped("%s", backend.c_str());
275275
ImGui::Separator();
276276

277-
if (ImGui::BeginTable("control-layout", 2, ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersInnerV)) {
278-
ImGui::TableSetupColumn("Devices", ImGuiTableColumnFlags_WidthFixed, 330.0F);
277+
if (ImGui::GetContentRegionAvail().x < 760.0F) {
278+
render_device_panel(devices);
279+
ImGui::Separator();
280+
render_control_panel(selected);
281+
} else if (ImGui::BeginTable("control-layout", 2, ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersInnerV)) {
282+
ImGui::TableSetupColumn("Devices", ImGuiTableColumnFlags_WidthFixed, 220.0F);
279283
ImGui::TableSetupColumn("Controls", ImGuiTableColumnFlags_WidthStretch);
280284
ImGui::TableNextRow();
281285

@@ -459,7 +463,8 @@ namespace {
459463
button_active_.fill(false);
460464
}
461465

462-
if (ImGui::BeginTable("buttons", 4, ImGuiTableFlags_SizingStretchSame)) {
466+
const auto column_count = ImGui::GetContentRegionAvail().x < 480.0F ? 3 : 4;
467+
if (ImGui::BeginTable("buttons", column_count, ImGuiTableFlags_SizingStretchSame)) {
463468
for (std::size_t index = 0; index < button_choices.size(); ++index) {
464469
if (!visible_buttons[index]) {
465470
continue;
@@ -955,9 +960,9 @@ namespace {
955960
main_scale = 1.0F;
956961
}
957962

958-
constexpr auto base_width = 1120;
963+
constexpr auto base_width = 860;
959964
constexpr auto base_height = 760;
960-
constexpr auto minimum_width = 980;
965+
constexpr auto minimum_width = 600;
961966
constexpr auto minimum_height = 700;
962967
const auto window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
963968
auto *window = SDL_CreateWindow(

0 commit comments

Comments
 (0)