From 614b1581a662952d5d282427e6fd353b007d610f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 10 Oct 2022 09:46:12 +0200 Subject: [PATCH] Measuring - Gizmo measure - Auto-select text when opening imgui modal dialog to edit distance --- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 10 ++++++++++ src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 79a800bf2..b4c35b156 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -221,6 +221,7 @@ void GLGizmoMeasure::data_changed() m_selected_features.reset(); m_selection_raycasters.clear(); m_editing_distance = false; + m_is_editing_distance_first_frame = true; } bool GLGizmoMeasure::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) @@ -258,6 +259,7 @@ void GLGizmoMeasure::on_set_state() m_curr_point_on_feature_position.reset(); restore_scene_raycasters_state(); m_editing_distance = false; + m_is_editing_distance_first_frame = true; } else { m_mode = EMode::BasicSelection; @@ -904,6 +906,7 @@ void GLGizmoMeasure::render_dimensioning() }; auto action_exit = [this]() { m_editing_distance = false; + m_is_editing_distance_first_frame = true; ImGui::CloseCurrentPopup(); }; auto action_scale = [this, perform_scale, action_exit](double new_value, double old_value) { @@ -916,6 +919,13 @@ void GLGizmoMeasure::render_dimensioning() if (ImGui::InputDouble("##distance", &edit_value, 0.0f, 0.0f, "%.3f")) { } + // trick to auto-select text in the input widgets on 1st frame + if (m_is_editing_distance_first_frame) { + ImGui::SetKeyboardFocusHere(0); + m_is_editing_distance_first_frame = false; + m_imgui->set_requires_extra_frame(); + } + // handle keys input if (ImGui::IsKeyPressedMap(ImGuiKey_Enter) || ImGui::IsKeyPressedMap(ImGuiKey_KeyPadEnter)) action_scale(edit_value, curr_value); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index bba23fb6b..9db2a73aa 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -119,6 +119,7 @@ class GLGizmoMeasure : public GLGizmoBase SelectedFeatures m_selected_features; bool m_editing_distance{ false }; + bool m_is_editing_distance_first_frame{ true }; void update_if_needed();