| 75 | } |
| 76 | |
| 77 | bool input_int_field(const char* label, int& value) { |
| 78 | // Reflect the committed value into a fresh per-call text buffer: while |
| 79 | // the widget is focused, ImGui edits its own persistent (ID-keyed) |
| 80 | // buffer and ignores this one, only writing back into it (and returning |
| 81 | // true) when the text actually changes. So this does not clobber an |
| 82 | // in-progress edit like "-" on the frames before it parses. |
| 83 | std::string text = std::to_string(value); |
| 84 | if (!input_text_line(label, text)) { |
| 85 | return false; |
| 86 | } |
| 87 | if (const std::optional<int> parsed = parse_int_field(text)) { |
| 88 | value = *parsed; |
| 89 | return true; |
| 90 | } |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | std::optional<int> parse_int_field(std::string_view text) { |
| 95 | constexpr std::string_view whitespace = " \t\n\r\f\v"; |
no test coverage detected