diff options
| author | dam <dam@gudinoff> | 2021-12-18 03:14:52 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2021-12-18 03:14:52 +0000 |
| commit | a2af4c7d07259a091deabdceaa5da1a2f7757c5e (patch) | |
| tree | fd630b7fd6f1de2ac6a285271a202eb84aeda5eb /date_picker | |
| parent | 3f29bb41d713240eb7ba831f68981674d4db9eb9 (diff) | |
| download | surgery-log-a2af4c7d07259a091deabdceaa5da1a2f7757c5e.tar.zst surgery-log-a2af4c7d07259a091deabdceaa5da1a2f7757c5e.zip | |
Add drag detection threshold to date picker.
Prototype touch drag on database screen.
Diffstat (limited to 'date_picker')
| -rw-r--r-- | date_picker/value_picker.gd | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/date_picker/value_picker.gd b/date_picker/value_picker.gd index 5e77294..fcd7dff 100644 --- a/date_picker/value_picker.gd +++ b/date_picker/value_picker.gd @@ -5,6 +5,7 @@ class_name ValuePicker const VELOCITY_DECAYING_FACTOR: float = 5.5 const BINNING_THRESHOLD: float = 0.75 const BINNING_ADJUST_P: float = 5.0 +const DRAG_THRESHOLD_CM: float = 0.250 export var min_value: int export var max_value: int @@ -19,6 +20,7 @@ var anchor: float var value: int var offset: float +var screen_dpcm: float var scroll_unit_height: float var label_previous_base_position: float var label_current_base_position: float @@ -39,6 +41,7 @@ func _ready(): input.connect("focus_entered", self, "input_focus_entered") input.connect("focus_exited", self, "input_focus_exited") + screen_dpcm = float(OS.get_screen_dpi()) / 2.54 scroll_unit_height = label_current.rect_size.y label_previous_base_position = label_previous.rect_position.y label_current_base_position = label_current.rect_position.y @@ -105,7 +108,8 @@ func _gui_input(event: InputEvent): var drag := event as InputEventScreenDrag pointer.current_position = drag.position pointer.velocity = drag.speed - pointer.was_dragged = true + if pointer.current_position.distance_to(pointer.initial_position) / screen_dpcm > DRAG_THRESHOLD_CM: + pointer.was_dragged = true func input_text_entered(new_text: String): @@ -113,6 +117,7 @@ func input_text_entered(new_text: String): func input_focus_entered(): + pointer.velocity = Vector2.ZERO # Avoid changing to other value once entering input. input.text = "%d" % value input.visible = true input.select_all() |
