mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-22 21:50:51 -05:00
Make gizmo +/- buttons repeat while held (#16525)
Holding a +/- step button on a gizmo input changed the value only once. ImGui repeats a held button only on new frames, and the canvas draws only when an event arrives, so a mouse held still produced no repeats. - Add ImGuiWrapper::request_frames_while_held() and call it after the Emboss Height and Depth, SVG Depth, and Cut groove Count inputs. - Set io.DeltaTime from a real clock in ImGuiWrapper::new_frame(), capped at 1/60 s, so the repeat rate does not depend on the frame rate. - Handle wxEVT_MOUSE_CAPTURE_LOST on the canvas, so a lost button-up does not leave an ImGui widget active. - Cut groove Count no longer rebuilds when the value is already at its limit.
This commit is contained in:
7 files changed
+55
-11
No files matched your search
@@ -3921,6 +3921,19 @@ void GLCanvas3D::bind_event_handlers()
|
||||
render();
|
||||
evt.Skip();
|
||||
});
|
||||
// ORCA If the mouse capture is lost while a button is held (Alt+Tab, dialog, lock screen), the button-up
|
||||
// never arrives and ImGui keeps the widget active. Cancel the interaction: clear the active widget
|
||||
// before releasing the buttons so the release is not taken as a click.
|
||||
m_canvas->Bind(wxEVT_MOUSE_CAPTURE_LOST, [this](wxMouseCaptureLostEvent&) {
|
||||
if (GImGui != nullptr) {
|
||||
ImGui::ClearActiveID();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
for (bool& down : io.MouseDown)
|
||||
down = false;
|
||||
}
|
||||
m_navigator_dragging = false;
|
||||
render();
|
||||
});
|
||||
m_event_handlers_bound = true;
|
||||
|
||||
m_canvas->Bind(wxEVT_GESTURE_PAN, &GLCanvas3D::on_gesture, this);
|
||||
|
||||
@@ -2762,11 +2762,16 @@ void GLGizmoCut3D::render_groove_int_input(const std::string& label, int& in_val
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::SameLine(m_label_width);
|
||||
ImGui::PushItemWidth(m_control_width);
|
||||
if (ImGui::InputInt("##int_input", &in_val, 1, 5)) {
|
||||
in_val = std::clamp(in_val, min_val, max_val);
|
||||
|
||||
is_changed = true;
|
||||
int val = in_val;
|
||||
if (ImGui::InputInt("##int_input", &val, 1, 5)) {
|
||||
val = std::clamp(val, min_val, max_val);
|
||||
// ORCA Holding +/- at the limit clamps back to the same value, don't rebuild for that.
|
||||
if (val != in_val) {
|
||||
in_val = val;
|
||||
is_changed = true;
|
||||
}
|
||||
}
|
||||
m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons
|
||||
|
||||
ImGui::SameLine();
|
||||
m_imgui->disabled_begin(in_val == init_val);
|
||||
|
||||
@@ -2642,12 +2642,14 @@ bool GLGizmoEmboss::rev_input(const std::string &name, T &value, const T *defaul
|
||||
const std::string &undo_tooltip, T step, T step_fast, const char *format, ImGuiInputTextFlags flags) const
|
||||
{
|
||||
// draw offseted input
|
||||
auto draw_offseted_input = [&offset = m_gui_cfg->input_offset, &width = m_gui_cfg->input_width,
|
||||
auto draw_offseted_input = [this, &offset = m_gui_cfg->input_offset, &width = m_gui_cfg->input_width,
|
||||
&name, &value, &step, &step_fast, format, flags](){
|
||||
ImGui::SameLine(offset);
|
||||
ImGui::SetNextItemWidth(width);
|
||||
return imgui_input(("##" + name).c_str(),
|
||||
bool changed = imgui_input(("##" + name).c_str(),
|
||||
&value, step, step_fast, format, flags);
|
||||
m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons
|
||||
return changed;
|
||||
};
|
||||
return revertible(name, value, default_value, undo_tooltip,
|
||||
0.0f, draw_offseted_input);
|
||||
|
||||
@@ -1689,7 +1689,9 @@ void GLGizmoSVG::draw_depth()
|
||||
result_scale = 1. / (*m_scale_depth);
|
||||
}
|
||||
|
||||
if (ImGui::InputDouble("##depth", &input, step, step_fast, size_format)) {
|
||||
const bool input_changed = ImGui::InputDouble("##depth", &input, step, step_fast, size_format);
|
||||
m_imgui->request_frames_while_held(); // ORCA auto-repeat of the +/- buttons
|
||||
if (input_changed) {
|
||||
if (result_scale.has_value())
|
||||
input *= (*result_scale);
|
||||
apply(input, limits.depth);
|
||||
|
||||
@@ -4056,10 +4056,11 @@ void GLGizmoTextureDisplacement::ensure_panel_icons()
|
||||
|
||||
// Seconds on a real clock, for the tooltips' own timing.
|
||||
//
|
||||
// Not ImGui::GetTime(): nothing in OrcaSlicer ever sets io.DeltaTime, so it keeps imgui's default of
|
||||
// 1/60 per frame and its clock counts frames rather than seconds. On a canvas that renders only when
|
||||
// something asks it to, that is not a clock at all - an animation driven by it crawled while the canvas
|
||||
// was idle and raced while a moving mouse was rendering it flat out.
|
||||
// Not ImGui::GetTime(): ImGuiWrapper::new_frame() feeds io.DeltaTime the real frame time but caps it
|
||||
// at 1/60 s, so the idle gaps of the event-driven canvas don't count as time a +/- button is held.
|
||||
// That cap also means ImGui's clock stalls while the canvas is idle - a pointer resting still on a
|
||||
// control renders nothing, so the tooltip delay would never run out on ImGui's clock. A real clock
|
||||
// keeps the tooltip timing and media playback independent of how often the canvas renders.
|
||||
static double tip_now()
|
||||
{
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <utility>
|
||||
#include <string_view>
|
||||
#include <cstring>
|
||||
#include <chrono>
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
@@ -588,6 +589,16 @@ void ImGuiWrapper::new_frame()
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// ORCA ImGui times button and key repeat with io.DeltaTime. At its default of 1/60 s per frame the clock
|
||||
// counts frames, so a held +/- button repeats as fast as the canvas renders. Feed it the real frame time,
|
||||
// capped at 1/60 s so the idle gaps of the event-driven canvas don't count as time held.
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (m_last_frame_time != std::chrono::steady_clock::time_point{}) {
|
||||
const float dt = std::chrono::duration<float>(now - m_last_frame_time).count();
|
||||
io.DeltaTime = std::clamp(dt, 1e-4f, 1.f / 60.f); // ImGui asserts a positive DeltaTime
|
||||
}
|
||||
m_last_frame_time = now;
|
||||
|
||||
ImGui::NewFrame();
|
||||
m_new_frame_open = true;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
@@ -68,6 +69,8 @@ class ImGuiWrapper
|
||||
unsigned m_mouse_buttons{ 0 };
|
||||
bool m_disabled{ false };
|
||||
bool m_new_frame_open{ false };
|
||||
// ORCA Start of the previous frame, see new_frame().
|
||||
std::chrono::steady_clock::time_point m_last_frame_time{};
|
||||
#if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
|
||||
bool m_requires_extra_frame{ false };
|
||||
#endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
|
||||
@@ -361,6 +364,13 @@ public:
|
||||
bool requires_extra_frame() const { return m_requires_extra_frame; }
|
||||
void set_requires_extra_frame() { m_requires_extra_frame = true; }
|
||||
void reset_requires_extra_frame() { m_requires_extra_frame = false; }
|
||||
// ORCA Call right after a widget with +/- buttons. ImGui repeats a held button only on new frames and the
|
||||
// canvas renders on events only, so keep frames coming while the widget is held.
|
||||
void request_frames_while_held()
|
||||
{
|
||||
if (ImGui::IsItemActive() && ImGui::IsMouseDown(ImGuiMouseButton_Left))
|
||||
set_requires_extra_frame();
|
||||
}
|
||||
|
||||
void disable_background_fadeout_animation();
|
||||
|
||||
|
||||
Reference in new issue
Block a user