Skip to content

Commit

Permalink
small refactoring + adding validation for manual values inhection
Browse files Browse the repository at this point in the history
  • Loading branch information
ev-mp committed Apr 8, 2021
1 parent ac9596e commit f7960ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
26 changes: 22 additions & 4 deletions common/realsense-ui-advanced-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,17 @@ inline void slider_int(std::string& error_message, const char* id, T* val, S T::
}
else
{
val->*field = static_cast<S>(new_value);
to_set = true;
if ((new_value > max) || (new_value < min))
{
std::stringstream ss;
ss << "New value " << new_value << " to be within [" << min << ", " << max << "] range";
error_message = ss.str().c_str();
}
else
{
val->*field = static_cast<S>(new_value);
to_set = true;
}
}

*edit_mode = false;
Expand Down Expand Up @@ -158,8 +167,17 @@ inline void slider_float(std::string& error_message, const char* id, T* val, S T
}
else
{
val->*field = static_cast<S>(new_value);
to_set = true;
if ((new_value > max) || (new_value<min))
{
std::stringstream ss;
ss << "New value " << new_value << " to be within [" << min << ", " << max << "] range";
error_message = ss.str().c_str();
}
else
{
val->*field = static_cast<S>(new_value);
to_set = true;
}
}

*edit_mode = false;
Expand Down
5 changes: 3 additions & 2 deletions third-party/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6457,10 +6457,11 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v

// Round past decimal precision, verify that it remains within min/max range
new_value = RoundScalar(new_value, decimal_precision);
if (new_value > v_max) new_value = v_max;
if (new_value < v_min) new_value = v_min;

if (*v != new_value)
{
if (new_value >v_max ) new_value = v_max;
if (new_value < v_min) new_value = v_min;
*v = new_value;
value_changed = true;
}
Expand Down

0 comments on commit f7960ff

Please sign in to comment.