| 144 | } |
| 145 | |
| 146 | bool AlienImGui::InputInt(InputIntParameters const& parameters, int& value, bool* enabled) |
| 147 | { |
| 148 | auto textWidth = scale(parameters._textWidth); |
| 149 | auto infinityButtonWidth = 30; |
| 150 | auto isInfinity = value == std::numeric_limits<int>::max(); |
| 151 | auto showInfinity = parameters._infinity && (!parameters._readOnly || isInfinity); |
| 152 | |
| 153 | auto result = false; |
| 154 | if (enabled) { |
| 155 | result |= ImGui::Checkbox(("##checkbox" + parameters._name).c_str(), enabled); |
| 156 | if (!(*enabled) && parameters._disabledValue) { |
| 157 | value = *parameters._disabledValue; |
| 158 | } |
| 159 | ImGui::BeginDisabled(!(*enabled)); |
| 160 | ImGui::SameLine(); |
| 161 | } |
| 162 | |
| 163 | auto inputWidth = ImGui::GetContentRegionAvail().x - textWidth; |
| 164 | if (showInfinity) { |
| 165 | inputWidth -= scale(infinityButtonWidth) + ImGui::GetStyle().FramePadding.x; |
| 166 | } |
| 167 | |
| 168 | if (!isInfinity) { |
| 169 | ImGui::SetNextItemWidth(inputWidth); |
| 170 | ImGuiInputTextFlags flags = parameters._readOnly ? ImGuiInputTextFlags_ReadOnly : ImGuiInputTextFlags_None; |
| 171 | result |= ImGui::InputInt(("##" + parameters._name).c_str(), &value, 1, 100, flags); |
| 172 | } else { |
| 173 | std::string text = "infinity"; |
| 174 | result |= InputText(InputTextParameters().readOnly(true).width(inputWidth).textWidth(0), text); |
| 175 | } |
| 176 | if (parameters._defaultValue) { |
| 177 | ImGui::SameLine(); |
| 178 | ImGui::BeginDisabled(value == *parameters._defaultValue); |
| 179 | if (RevertButton(parameters._name)) { |
| 180 | value = *parameters._defaultValue; |
| 181 | result = true; |
| 182 | } |
| 183 | ImGui::EndDisabled(); |
| 184 | } |
| 185 | if (showInfinity) { |
| 186 | ImGui::SameLine(); |
| 187 | ImGui::BeginDisabled(parameters._readOnly); |
| 188 | if (SelectableButton(SelectableButtonParameters().name(ICON_FA_INFINITY).tooltip(parameters._tooltip).width(infinityButtonWidth), isInfinity)) { |
| 189 | if (isInfinity) { |
| 190 | value = std::numeric_limits<int>::max(); |
| 191 | } else { |
| 192 | value = 1; |
| 193 | } |
| 194 | } |
| 195 | ImGui::EndDisabled(); |
| 196 | } |
| 197 | |
| 198 | ImGui::SameLine(); |
| 199 | if (enabled && parameters._keepTextEnabled) { |
| 200 | ImGui::EndDisabled(); |
| 201 | } |
| 202 | AlienImGui::Text(parameters._name); |
| 203 | if (enabled && !parameters._keepTextEnabled) { |
nothing calls this directly
no test coverage detected