1 /// Implementation of `PreferenceIO`, providing values that depend on the system and the user.
2 module fluid.preference_chain;
3 
4 import core.time;
5 
6 import fluid.node;
7 import fluid.types;
8 import fluid.utils;
9 import fluid.node_chain;
10 
11 import fluid.io.preference;
12 
13 @safe:
14 
15 alias preferenceChain = nodeBuilder!PreferenceChain;
16 
17 /// PreferenceChain implements `PreferenceIO`, accessing crucial, low-level user preferences that affect their usage
18 /// of Fluid programs.
19 ///
20 /// Currently, `PreferenceChain` does *not* communicate with the system, and instead assumes a default value of 400
21 /// milliseconds for the double-click interval, and 6 pixels for the maximum double click distance. Communicating
22 /// with the system will be enabled in a future update through a `version` flag. See
23 /// [issue #295](https://git.samerion.com/Samerion/Fluid/issues/295) for more details.
24 class PreferenceChain : NodeChain, PreferenceIO {
25 
26     mixin controlIO;
27 
28     this(Node next = null) {
29         super(next);
30     }
31 
32     override void beforeResize(Vector2) {
33         startIO();
34     }
35 
36     override void afterResize(Vector2) {
37         stopIO();
38     }
39 
40     override Duration doubleClickInterval() const nothrow {
41         return 400.msecs;
42     }
43 
44     override float maximumDoubleClickDistance() const nothrow {
45         return 6;
46     }
47 
48     override Vector2 scrollSpeed() const nothrow {
49 
50         // Normalize the value: Linux and Windows provide trinary values (-1, 0, 1) but macOS gives analog that often
51         // goes far higher than that. This is currently a rough guess of the proportions based on feeling.
52         // See
53         version (OSX)
54             return Vector2(65 / 4, 65 / 4);
55         else
56             return Vector2(65, 65);
57 
58     }
59 
60 }