aboutsummaryrefslogtreecommitdiff
path: root/date_picker
diff options
context:
space:
mode:
authordam <dam@gudinoff>2021-12-03 17:37:45 +0000
committerdam <dam@gudinoff>2021-12-03 17:37:45 +0000
commit177a6fb778d620dd6ffd4a6bc437dd04a1127328 (patch)
treeb5c56d3a4d8b3e4fb5bdd36ed03a5d6ffbc75705 /date_picker
parent29dcd16f71fd49e43c8df14844e04be9d5745f54 (diff)
downloadsurgery-log-177a6fb778d620dd6ffd4a6bc437dd04a1127328.tar.zst
surgery-log-177a6fb778d620dd6ffd4a6bc437dd04a1127328.zip
Fixed rounding errors affecting binning of 'big' numbers (~9000).
Diffstat (limited to 'date_picker')
-rw-r--r--date_picker/scroll_picker.gd38
1 files changed, 19 insertions, 19 deletions
diff --git a/date_picker/scroll_picker.gd b/date_picker/scroll_picker.gd
index 02d5933..afbb02e 100644
--- a/date_picker/scroll_picker.gd
+++ b/date_picker/scroll_picker.gd
@@ -17,7 +17,7 @@ func set_max_value(value: int):
num_of_values = max_value - min_value + 1
var pointer: Dictionary
-var value: float = 0.0
+var value: float = 0.0 # @DAM TODO Maybe rename variable?
var anchor: float = 0.0
var current_value_base_position: float
@@ -27,11 +27,11 @@ var previous_value_base_position: float
func _ready():
pointer = {
- index = -1,
- initial_position = Vector2.ZERO,
- current_position = Vector2.ZERO,
- velocity = Vector2.ZERO,
- is_active = false,
+ index = -1,
+ initial_position = Vector2.ZERO,
+ current_position = Vector2.ZERO,
+ velocity = Vector2.ZERO,
+ is_active = false,
}
current_value_base_position = ($value as Label).rect_position.y
next_value_base_position = ($value_next as Label).rect_position.y
@@ -40,32 +40,31 @@ func _ready():
func _process(delta: float):
- # @DAM TODO It's weird that we use '-value'... check maths.
var scroll_unit_height := ($value as Label).rect_size.y
- var normalized_value := - value / scroll_unit_height
+ var normalized_value := value / scroll_unit_height
var normalized_int_value := round(normalized_value) as int
- # $debug.text = "%s | %s" % [normalized_value, normalized_int_value]
- pointer.velocity *= clamp((1.0 - VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
+ var normalized_displacement := normalized_value - normalized_int_value
+ var displacement := normalized_displacement * scroll_unit_height
+
if pointer.is_active:
- value = anchor + (pointer.current_position.y - pointer.initial_position.y)
- elif is_zero_approx(pointer.velocity.y) == false:
- value += pointer.velocity.y * delta
- if abs(pointer.velocity.y) < BINNING_THRESHOLD * scroll_unit_height:
- var fix := ((normalized_int_value as float) - normalized_value) * scroll_unit_height
- value -= fix * BINNING_ADJUST_P * delta
+ value = anchor - (pointer.current_position.y - pointer.initial_position.y)
+ else:
+ pointer.velocity *= clamp((1.0 - VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
+ value -= pointer.velocity.y * delta
+ if abs(pointer.velocity.y) < BINNING_THRESHOLD * scroll_unit_height && abs(displacement) > 0.5:
+ pointer.velocity.y = 0.0
+ value -= displacement * BINNING_ADJUST_P * delta
var logic_value := min_value + fposmod(normalized_int_value, num_of_values)
var logic_next_value := min_value + fposmod(normalized_int_value + 1, num_of_values)
var logic_previous_value := min_value + fposmod(normalized_int_value - 1, num_of_values)
+ # @DAM TODO Change all '$access' with variables set during on '_ready'.
$value.text = "%d" % logic_value
$value_next.text = "%d" % logic_next_value
$value_previous.text = "%d" % logic_previous_value
- var normalized_displacement := normalized_value - normalized_int_value
- var displacement := normalized_displacement * scroll_unit_height
-
($value as Label).rect_position.y = current_value_base_position - displacement
($value_previous as Label).rect_position.y = previous_value_base_position - displacement
($value_next as Label).rect_position.y = next_value_base_position - displacement
@@ -73,6 +72,7 @@ func _process(delta: float):
($value_next as Label).modulate.a = normalized_displacement + 0.5
($value_previous as Label).modulate.a = 0.5 - normalized_displacement
+ # @DAM TODO Rename these variables.
var current_pos := value
var turn_over := num_of_values * scroll_unit_height
if current_pos >= turn_over || current_pos < 0.0: