-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdrag_scroll.cpp
More file actions
38 lines (34 loc) · 1.08 KB
/
Copy pathdrag_scroll.cpp
File metadata and controls
38 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "drag_scroll.hpp"
namespace acecode::drag_scroll {
Phase classify(int mouse_y, int box_y_min, int box_y_max,
bool left_pressed, const Config& cfg) {
if (!left_pressed) {
return Phase::Idle;
}
// box 尚未填充(reflect 在首帧前) → 不进入任何滚动阶段
if (box_y_max <= box_y_min) {
return Phase::Idle;
}
if (mouse_y < box_y_min + cfg.top_edge_lines) {
return Phase::ScrollingUp;
}
if (mouse_y > box_y_max - cfg.bot_edge_lines) {
return Phase::ScrollingDown;
}
return Phase::Dragging;
}
bool should_tick(std::chrono::steady_clock::time_point now,
std::chrono::steady_clock::time_point& last_tick,
std::chrono::milliseconds interval) {
// 零值哨兵:从未触发过,直接放行并记录第一次时间戳
if (last_tick.time_since_epoch().count() == 0) {
last_tick = now;
return true;
}
if (now - last_tick >= interval) {
last_tick = now;
return true;
}
return false;
}
} // namespace acecode::drag_scroll