diff --git a/CMakeLists.txt b/CMakeLists.txt index ccbfbb5..8333ca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.12) project(yarp-device-keyboard-joypad LANGUAGES C CXX - VERSION 0.0.1) + VERSION 0.0.2) # Defines the CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR and many other useful macros. # See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html diff --git a/README.md b/README.md index b3434b2..fe5aa6c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ The device can be configured using the following parameters. They are all option - ``window_width``: width of the window in pixels (default: 1280) - ``window_height``: height of the window in pixels (default: 720) - ``buttons_per_row``: number of buttons per row in the "Buttons" widget (default: 4) +- ``padding``: padding in pixels for the space between the widgets (default: 100) - ``allow_window_closing``: when specified or set to true, the window can be closed by pressing the "X" button in the title bar. Note: when using this as device, the parent might keep running anyway (default: false) - ``no_gui_thread``: when specified or set to true, the GUI will run in the same thread as the device. The GUI will be updated when calling ``updateService`` or when getting the values of axis/buttons (default: false, true on macOS) - ``axes``: definition of the list of axes. The allowed values are "ws", "ad", "up_down" and "left_right". It is possible to select the default sign for an axis prepending a "+" or a "-" to the axis name. For example, "+ws" will set the "ws" axis with the default sign, while "-ws" will set the "ws" axis with the inverted sign. It is also possible to repeat some axis, and use "none" or "" to have dummy axes with always zero value. The order matters. (default: ("ad", "ws", "left_right", "up_down")) @@ -50,4 +51,4 @@ The device can be configured using the following parameters. They are all option - ``up_down_joypad_axis_index``: index of the axis for the "up_down" axis in the joypad (default: 3) ## Maintainers -* Stefano Dafarra ([@S-Dafarra](https://github.com/S-Dafarra)) \ No newline at end of file +* Stefano Dafarra ([@S-Dafarra](https://github.com/S-Dafarra)) diff --git a/src/devices/keyboard-joypad/KeyboardJoypad.cpp b/src/devices/keyboard-joypad/KeyboardJoypad.cpp index 9d4cf4e..8ab03fd 100644 --- a/src/devices/keyboard-joypad/KeyboardJoypad.cpp +++ b/src/devices/keyboard-joypad/KeyboardJoypad.cpp @@ -239,6 +239,7 @@ struct Settings { float max_font_multiplier = 4.0; float gui_period = 0.033f; float deadzone = 0.1f; + float padding = 100; int window_width = 1280; int window_height = 720; int buttons_per_row = 3; @@ -288,6 +289,11 @@ struct Settings { return false; } + if (!parseFloat(cfg, "padding", 0.f, 1e5f, padding)) + { + return false; + } + if (!parseInt(cfg, "window_width", 1, static_cast(1e4), window_width)) { return false; @@ -948,17 +954,17 @@ class yarp::dev::KeyboardJoypad::Impl } } - ImVec2 position(this->settings.button_size, this->settings.button_size); + ImVec2 position(this->settings.padding, this->settings.padding); float button_table_height = position.y; for (auto& stick : this->sticks) { - position.y = this->settings.button_size; //Keep the sticks on the save level + position.y = this->settings.padding; //Keep the sticks on the save level this->prepareWindow(position, stick.name); this->renderButtonsTable(stick, false, this->settings.deadzone, this->joypad_axis_values, this->joypad_button_values,this->axes_values); ImGui::End(); - position.x += (stick.numberOfColumns + 1) * this->settings.button_size; // Move the next table to the right (n columns + 1 space) - position.y += (stick.rows.size() + 1) * this->settings.button_size; // Move the next table down (n rows + 1 space) + position.x += stick.numberOfColumns * this->settings.button_size + this->settings.padding; // Move the next table to the right (n columns + 1 space) + position.y += stick.rows.size() * this->settings.button_size + this->settings.padding; // Move the next table down (n rows + 1 space) button_table_height = std::max(button_table_height, position.y); } @@ -986,7 +992,7 @@ class yarp::dev::KeyboardJoypad::Impl if (!this->buttons.rows.empty()) { - position.y = this->settings.button_size; //Keep the buttons on the save level of the sticks + position.y = this->settings.padding; //Keep the buttons on the save level of the sticks this->prepareWindow(position, this->buttons.name); ImGui::BeginTable("Buttons_layout", 1, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_SizingMask_ | ImGuiTableFlags_BordersInner); ImGui::TableNextRow(); @@ -1015,7 +1021,7 @@ class yarp::dev::KeyboardJoypad::Impl } } - position.x = this->settings.button_size; //Reset the x position + position.x = this->settings.padding; //Reset the x position position.y = button_table_height; //Move the next table down this->prepareWindow(position, "Settings");