| 6 | { |
| 7 | |
| 8 | bool inputTolerance( const char* label, ObjectComparableWithReference& object, std::size_t index ) |
| 9 | { |
| 10 | auto toleranceOpt = object.getComparisonTolerence( index ); |
| 11 | |
| 12 | ObjectComparableWithReference::ComparisonTolerance tolerance; |
| 13 | if ( toleranceOpt ) |
| 14 | tolerance = *toleranceOpt; |
| 15 | |
| 16 | UnitToStringParams<LengthUnit> unitParams; |
| 17 | if ( !toleranceOpt ) |
| 18 | unitParams.decorationFormatString = "\xE2\x80\x94"; // U+2014 EM DASH |
| 19 | |
| 20 | bool ret = false; |
| 21 | |
| 22 | if ( object.comparisonToleranceIsAlwaysOnlyPositive( index ) ) |
| 23 | { |
| 24 | if ( UI::input<LengthUnit>( fmt::format( "###{}", label ).c_str(), tolerance.positive, 0.f, FLT_MAX, unitParams, UI::defaultSliderFlags ) ) |
| 25 | { |
| 26 | assert( tolerance.negative == 0 ); |
| 27 | tolerance.negative = 0; |
| 28 | |
| 29 | object.setComparisonTolerance( index, tolerance ); |
| 30 | ret = true; |
| 31 | } |
| 32 | |
| 33 | ImGui::SameLine( 0, ImGui::GetStyle().ItemInnerSpacing.x ); |
| 34 | |
| 35 | // Draw the label separately to be able to color it separately. |
| 36 | ImGui::TextUnformatted( label ); |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | if ( UI::inputPlusMinus<LengthUnit>( label, tolerance.positive, tolerance.negative, 0.f, FLT_MAX, unitParams, UI::defaultSliderFlags, |
| 41 | [&]( const char* subLabel, float& value, auto&& f ) |
| 42 | { |
| 43 | (void)value; |
| 44 | |
| 45 | // Gray out this box if the input is nullopt. We also check that the current sub-input isn't focused; if it's focused, we always use the normal color. |
| 46 | ImGui::PushStyleColor( ImGuiCol_Text, ImGui::GetStyleColorVec4( toleranceOpt || UI::isItemActive( subLabel ) ? ImGuiCol_Text : ImGuiCol_TextDisabled ) ); |
| 47 | MR_FINALLY{ ImGui::PopStyleColor(); }; |
| 48 | return f(); |
| 49 | } |
| 50 | ) ) |
| 51 | { |
| 52 | object.setComparisonTolerance( index, tolerance ); |
| 53 | ret = true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | } |
no test coverage detected