mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
ImGui sliders clamping:
ImGuiWrapper::slider_float now clamps the value returned by imgui by default. Bare ImGui::SliderFloat allows entering off-scale values when entered by keyboard, which is not nice. The protection can be turned off by the last optional parameter.
This commit is contained in:
parent
1f89b3638c
commit
e93c5d4f20
8 changed files with 41 additions and 36 deletions
|
@ -545,7 +545,7 @@ RENDER_AGAIN:
|
|||
m_imgui->text(m_desc.at("offset"));
|
||||
ImGui::SameLine(settings_sliders_left);
|
||||
ImGui::PushItemWidth(window_width - settings_sliders_left);
|
||||
ImGui::SliderFloat(" ", &offset, offset_min, offset_max, "%.1f mm");
|
||||
m_imgui->slider_float(" ", &offset, offset_min, offset_max, "%.1f mm");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(max_tooltip_width);
|
||||
|
@ -560,7 +560,7 @@ RENDER_AGAIN:
|
|||
if (current_mode >= quality_mode) {
|
||||
m_imgui->text(m_desc.at("quality"));
|
||||
ImGui::SameLine(settings_sliders_left);
|
||||
ImGui::SliderFloat(" ", &quality, quality_min, quality_max, "%.1f");
|
||||
m_imgui->slider_float(" ", &quality, quality_min, quality_max, "%.1f");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(max_tooltip_width);
|
||||
|
@ -576,7 +576,7 @@ RENDER_AGAIN:
|
|||
if (current_mode >= closing_d_mode) {
|
||||
m_imgui->text(m_desc.at("closing_distance"));
|
||||
ImGui::SameLine(settings_sliders_left);
|
||||
ImGui::SliderFloat(" ", &closing_d, closing_d_min, closing_d_max, "%.1f mm");
|
||||
m_imgui->slider_float(" ", &closing_d, closing_d_min, closing_d_max, "%.1f mm");
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(max_tooltip_width);
|
||||
|
@ -618,15 +618,19 @@ RENDER_AGAIN:
|
|||
|
||||
ImGui::Separator();
|
||||
|
||||
float diameter_upper_cap = 15.;
|
||||
if (m_new_hole_radius > diameter_upper_cap)
|
||||
m_new_hole_radius = diameter_upper_cap;
|
||||
float diameter_upper_cap = 60.;
|
||||
if (m_new_hole_radius * 2.f > diameter_upper_cap)
|
||||
m_new_hole_radius = diameter_upper_cap / 2.f;
|
||||
m_imgui->text(m_desc.at("hole_diameter"));
|
||||
ImGui::SameLine(diameter_slider_left);
|
||||
ImGui::PushItemWidth(window_width - diameter_slider_left);
|
||||
|
||||
float diam = 2.f * m_new_hole_radius;
|
||||
ImGui::SliderFloat("", &diam, 1.f, diameter_upper_cap, "%.1f mm");
|
||||
m_imgui->slider_float("", &diam, 1.f, 15.f, "%.1f mm", 1.f, false);
|
||||
// Let's clamp the value (which could have been entered by keyboard) to a larger range
|
||||
// than the slider. This allows entering off-scale values and still protects against
|
||||
//complete non-sense.
|
||||
diam = std::clamp(diam, 0.1f, diameter_upper_cap);
|
||||
m_new_hole_radius = diam / 2.f;
|
||||
bool clicked = ImGui::IsItemClicked();
|
||||
bool edited = ImGui::IsItemEdited();
|
||||
|
@ -634,7 +638,9 @@ RENDER_AGAIN:
|
|||
|
||||
m_imgui->text(m_desc["hole_depth"]);
|
||||
ImGui::SameLine(diameter_slider_left);
|
||||
ImGui::SliderFloat(" ", &m_new_hole_height, 0.f, 10.f, "%.1f mm");
|
||||
m_imgui->slider_float(" ", &m_new_hole_height, 0.f, 10.f, "%.1f mm", 1.f, false);
|
||||
// Same as above:
|
||||
m_new_hole_height = std::clamp(m_new_hole_height, 0.f, 100.f);
|
||||
|
||||
clicked |= ImGui::IsItemClicked();
|
||||
edited |= ImGui::IsItemEdited();
|
||||
|
@ -699,7 +705,7 @@ RENDER_AGAIN:
|
|||
ImGui::SameLine(clipping_slider_left);
|
||||
ImGui::PushItemWidth(window_width - clipping_slider_left);
|
||||
float clp_dist = m_c->object_clipper()->get_position();
|
||||
if (ImGui::SliderFloat(" ", &clp_dist, 0.f, 1.f, "%.2f"))
|
||||
if (m_imgui->slider_float(" ", &clp_dist, 0.f, 1.f, "%.2f"))
|
||||
m_c->object_clipper()->set_position(clp_dist, true);
|
||||
|
||||
// make sure supports are shown/hidden as appropriate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue