Skip to content

Commit

Permalink
Merge pull request #6 from ami-iit/padding
Browse files Browse the repository at this point in the history
Add possibility to change the padding between widgets
  • Loading branch information
S-Dafarra authored May 21, 2024
2 parents 6a1d611 + 00b99f8 commit ad266c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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))
* Stefano Dafarra ([@S-Dafarra](https://github.com/S-Dafarra))
18 changes: 12 additions & 6 deletions src/devices/keyboard-joypad/KeyboardJoypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int>(1e4), window_width))
{
return false;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit ad266c1

Please sign in to comment.