Skip to main content

GamepadSettingsWidget.ixx File

ImGui widget for configuring gamepad input settings. More...

Included Headers

#include <string> #include <format> #include "imgui.h" #include <helios.input.gamepad.GamepadSettings> #include <helios.input.types.Gamepad> #include <helios.input.InputAdapter> #include <helios.ext.imgui.ImGuiWidget>

Namespaces Index

namespacehelios
namespaceext

Platform-specific extensions and backend implementations. More...

namespaceimgui
namespacewidgets

Debug and developer widgets for ImGui overlays. More...

Classes Index

classGamepadSettingsWidget

A configuration widget for adjusting gamepad input settings. More...

Description

ImGui widget for configuring gamepad input settings.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file GamepadSettingsWidget.ixx
3 * @brief ImGui widget for configuring gamepad input settings.
4 */
5module;
6
7#include <string>
8#include <format>
9#include "imgui.h"
10
11export module helios.ext.imgui.widgets.GamepadSettingsWidget;
12
13import helios.ext.imgui.ImGuiWidget;
14import helios.input.InputAdapter;
15import helios.input.types.Gamepad;
16import helios.input.gamepad.GamepadSettings;
17
18export namespace helios::ext::imgui::widgets {
19
20 /**
21 * @brief A configuration widget for adjusting gamepad input settings.
22 *
23 * This widget provides interactive controls for configuring per-gamepad settings
24 * including deadzone thresholds and axis inversion options. Changes are applied
25 * in real-time to the underlying InputAdapter's GamepadSettings.
26 *
27 * **Features:**
28 * - **Gamepad Selection:** Switch between controllers (1-4) via dropdown.
29 * - **Deadzone Sliders:** Adjust left/right stick deadzone thresholds (0.0 to 0.9).
30 * - **Axis Inversion:** Toggle X/Y axis inversion for both sticks.
31 * - **Visual Feedback:** Deadzone values displayed as percentage.
32 *
33 * @note Changes are applied immediately to the InputAdapter. No explicit save required.
34 * @note This widget is not thread-safe. Use from the main/render thread only.
35 *
36 * @see GamepadSettings for the underlying configuration data.
37 * @see GamepadWidget for real-time input visualization.
38 */
40
41 private:
42 /**
43 * @brief Pointer to the InputAdapter used to access gamepad settings.
44 * Non-owning pointer; must be valid for the lifetime of this widget.
45 */
46 helios::input::InputAdapter* inputAdapter_ = nullptr;
47
48 /**
49 * @brief The currently selected gamepad index in the UI combo box (0-3).
50 */
51 int selectedGamepadIndex_ = 0;
52
53 /**
54 * @brief Helper to map an integer index (0-3) to a Gamepad enum ID.
55 *
56 * @param index The index selected in the UI.
57 *
58 * @return The corresponding Gamepad enum value.
59 */
60 [[nodiscard]] static helios::input::types::Gamepad indexToId(int index) noexcept {
61 switch (index) {
67 }
68 }
69
70 public:
71
72 /**
73 * @brief Constructs the GamepadSettingsWidget.
74 *
75 * @param inputAdapter Pointer to the InputAdapter to configure.
76 * Pass nullptr to render a disabled widget.
77 */
79 : inputAdapter_(inputAdapter) {}
80
81 /**
82 * @brief Renders the gamepad settings configuration interface.
83 */
84 void draw() override {
85 if (!inputAdapter_) return;
86
87 ImGui::SetNextWindowSize(ImVec2(350, 320), ImGuiCond_FirstUseEver);
88
89 if (ImGui::Begin("Gamepad Settings", nullptr, ImGuiWindowFlags_NoCollapse)) {
90
91 // --- Gamepad Selection ---
92 const char* items[] = { "Gamepad 1", "Gamepad 2", "Gamepad 3", "Gamepad 4" };
93 ImGui::Combo("Controller", &selectedGamepadIndex_, items, IM_ARRAYSIZE(items));
94
95 auto gamepadId = indexToId(selectedGamepadIndex_);
96 auto& settings = inputAdapter_->gamepadSettings(gamepadId);
97
98 ImGui::Separator();
99
100 // --- Deadzone Configuration ---
101 ImGui::Text("Deadzone Settings");
102 ImGui::Spacing();
103
104 // Left Stick Deadzone
105 float leftDeadzone = settings.leftStickDeadzone();
106 ImGui::Text("Left Stick");
107 if (ImGui::SliderFloat("##LeftDeadzone", &leftDeadzone, 0.0f, 0.9f, "%.2f")) {
108 settings.setLeftStickDeadzone(leftDeadzone);
109 }
110 ImGui::SameLine();
111 ImGui::TextDisabled("(%.0f%%)", leftDeadzone * 100.0f);
112
113 // Right Stick Deadzone
114 float rightDeadzone = settings.rightStickDeadzone();
115 ImGui::Text("Right Stick");
116 if (ImGui::SliderFloat("##RightDeadzone", &rightDeadzone, 0.0f, 0.9f, "%.2f")) {
117 settings.setRightStickDeadzone(rightDeadzone);
118 }
119 ImGui::SameLine();
120 ImGui::TextDisabled("(%.0f%%)", rightDeadzone * 100.0f);
121
122 ImGui::Separator();
123
124 // --- Axis Inversion ---
125 ImGui::Text("Axis Inversion");
126 ImGui::Spacing();
127
128 // Left Stick Inversion
129 ImGui::Text("Left Stick:");
130 ImGui::SameLine();
131
132 bool invertLeftX = settings.invertLeftX();
133 if (ImGui::Checkbox("Invert X##Left", &invertLeftX)) {
134 settings.setInvertLeftX(invertLeftX);
135 }
136 ImGui::SameLine();
137
138 bool invertLeftY = settings.invertLeftY();
139 if (ImGui::Checkbox("Invert Y##Left", &invertLeftY)) {
140 settings.setInvertLeftY(invertLeftY);
141 }
142
143 // Right Stick Inversion
144 ImGui::Text("Right Stick:");
145 ImGui::SameLine();
146
147 bool invertRightX = settings.invertRightX();
148 if (ImGui::Checkbox("Invert X##Right", &invertRightX)) {
149 settings.setInvertRightX(invertRightX);
150 }
151 ImGui::SameLine();
152
153 bool invertRightY = settings.invertRightY();
154 if (ImGui::Checkbox("Invert Y##Right", &invertRightY)) {
155 settings.setInvertRightY(invertRightY);
156 }
157
158 ImGui::Separator();
159
160 // --- Reset Button ---
161 if (ImGui::Button("Reset to Defaults")) {
162 settings.setLeftStickDeadzone(0.0f);
163 settings.setRightStickDeadzone(0.0f);
164 settings.setInvertLeftX(false);
165 settings.setInvertLeftY(false);
166 settings.setInvertRightX(false);
167 settings.setInvertRightY(false);
168 }
169
170 ImGui::SameLine();
171 ImGui::TextDisabled("(?)");
172 if (ImGui::IsItemHovered()) {
173 ImGui::SetTooltip(
174 "Deadzone: Input below this threshold is ignored.\n"
175 "Helps filter out stick drift when idle.\n\n"
176 "Invert: Reverses the axis direction.\n"
177 "Useful for flight-style controls."
178 );
179 }
180 }
181 ImGui::End();
182 }
183 };
184
185}
186

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.