-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathdrag.h
64 lines (44 loc) · 1.35 KB
/
drag.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "anim.h"
#include "input.h"
#include "layout.h"
#include "view.h"
namespace Karm::Ui {
// MARK: Drag Event ------------------------------------------------------------
struct DragEvent {
enum {
START,
DRAG,
END
} type;
Math::Vec2i delta{};
};
// MARK: Dismisable ------------------------------------------------------------
enum struct DismisDir {
LEFT = 1 << 0,
RIGHT = 1 << 1,
TOP = 1 << 2,
DOWN = 1 << 3,
HORIZONTAL = LEFT | RIGHT,
VERTICAL = TOP | DOWN,
};
FlagsEnum$(DismisDir);
using OnDismis = Func<void(Node&)>;
Child dismisable(OnDismis onDismis, DismisDir dir, f64 threshold, Ui::Child child);
inline auto dismisable(OnDismis onDismis, DismisDir dir, f64 threshold) {
return [=, onDismis = std::move(onDismis)](Ui::Child child) mutable {
return dismisable(std::move(onDismis), dir, threshold, child);
};
}
// MARK: Drag Region -----------------------------------------------------------
Child dragRegion(Child child, Math::Vec2i dir = {1, 1});
inline auto dragRegion(Math::Vec2i dir = {1, 1}) {
return [dir](Child child) {
return dragRegion(child, dir);
};
}
// MARK: Handle ----------------------------------------------------------------
Child handle();
Child dragHandle();
Child buttonHandle(OnPress press);
} // namespace Karm::Ui