mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 07:39:40 -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
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user