aboutsummaryrefslogtreecommitdiff
path: root/date_picker/value_picker.gd
diff options
context:
space:
mode:
Diffstat (limited to 'date_picker/value_picker.gd')
-rw-r--r--date_picker/value_picker.gd7
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()