Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui - clamp slider rounding operations to keep ranged values #8525

Merged
merged 5 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6023,7 +6023,7 @@ namespace rs2
model.add_log(to_string() << "Setting " << opt_model.opt << " to "
<< new_val << " (" << labels[selected] << ")");

opt_model.set_option(opt_model.opt, new_val, error_message);
opt_model.set_option(opt_model.opt, static_cast<float>(new_val), error_message);

// Only apply preset to GUI if set_option was succesful
selected_file_preset = "";
Expand Down
2 changes: 1 addition & 1 deletion common/output-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void output_model::open(ux_window& win)
{
is_output_open = true;
config_file::instance().set(configurations::viewer::output_open, true);
default_log_h = (int)((win.height() - 100) / 2);
default_log_h = static_cast<int>((win.height() - 100) / 2);
new_log = true;
}

Expand Down
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 << " must be within [" << min << ", " << max << "] range";
error_message = ss.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 << " must be within [" << min << ", " << max << "] range";
error_message = ss.str();
}
else
{
val->*field = static_cast<S>(new_value);
to_set = true;
}
}

*edit_mode = false;
Expand Down
2 changes: 1 addition & 1 deletion common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace rs2

for (auto& option : curr_exporter->second.options)
{
exporter->set_option(option.first, option.second);
exporter->set_option(option.first, static_cast<float>(option.second));
}

export_frame(fname, std::move(exporter), *not_model, data);
Expand Down
2 changes: 1 addition & 1 deletion src/gl/yuy2rgb-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#ifndef NOMINMAX
#define NOMINMAX
#endif
#endif // NOMINMAX

#include <glad/glad.h>

Expand Down
5 changes: 4 additions & 1 deletion third-party/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6455,8 +6455,11 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
new_value = ImLerp(v_min, v_max, normalized_pos);
}

// Round past decimal precision
// 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)
{
*v = new_value;
Expand Down
2 changes: 1 addition & 1 deletion tools/realsense-viewer/realsense-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ int main(int argc, const char** argv) try

auto output_rect = rect{ viewer_model.panel_width,
window.height() - viewer_model.get_output_height(),
window.width() - viewer_model.panel_width, viewer_model.get_output_height() };
window.width() - viewer_model.panel_width, float(viewer_model.get_output_height()) };

viewer_model.not_model->output.draw(window, output_rect, *device_models);

Expand Down
2 changes: 1 addition & 1 deletion unit-tests/LRS_windows_compile_pipeline.stats
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
warnings 342
warnings 340