diff options
| author | dam <dam@gudinoff> | 2021-12-03 15:07:09 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2021-12-03 15:07:09 +0000 |
| commit | 4faf8bb004dbb2161e736028469333b9b6c99775 (patch) | |
| tree | f5ff8521482a7671697d55f4c1b1a523446890da | |
| parent | 7d515712404db480b6ba6eb45576ecc74988acd3 (diff) | |
| download | surgery-log-4faf8bb004dbb2161e736028469333b9b6c99775.tar.zst surgery-log-4faf8bb004dbb2161e736028469333b9b6c99775.zip | |
Remove datepicker hardcoded dimensions.
| -rw-r--r-- | date_picker/date_picker.tscn | 167 | ||||
| -rw-r--r-- | date_picker/scroll_picker.gd | 28 | ||||
| -rw-r--r-- | main.tscn | 36 |
3 files changed, 160 insertions, 71 deletions
diff --git a/date_picker/date_picker.tscn b/date_picker/date_picker.tscn index 88f98d8..84b2089 100644 --- a/date_picker/date_picker.tscn +++ b/date_picker/date_picker.tscn @@ -2,146 +2,225 @@ [ext_resource path="res://date_picker/scroll_picker.gd" type="Script" id=1] -[node name="date_picker" type="HBoxContainer"] +[node name="date_picker" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 mouse_filter = 2 -alignment = 1 __meta__ = { "_edit_use_anchors_": false } [node name="day_scroll" type="Control" parent="."] -margin_left = 5.0 -margin_right = 239.0 -margin_bottom = 1280.0 -rect_min_size = Vector2( 234, 0 ) +anchor_right = 0.333 +anchor_bottom = 1.0 script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -[node name="label" type="Label" parent="day_scroll"] +[node name="value_previous" type="Label" parent="day_scroll"] anchor_right = 1.0 -text = "day" +anchor_bottom = 0.333 +mouse_filter = 1 align = 1 +valign = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="value_previous" type="Label" parent="day_scroll"] +[node name="ColorRect" type="ColorRect" parent="day_scroll/value_previous"] anchor_right = 1.0 -margin_bottom = 80.0 -mouse_filter = 1 -align = 1 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 0, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value" type="Label" parent="day_scroll"] +anchor_top = 0.333 anchor_right = 1.0 -margin_top = 80.0 -margin_bottom = 160.0 +anchor_bottom = 0.666 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="day_scroll/value"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value_next" type="Label" parent="day_scroll"] +anchor_top = 0.666 anchor_right = 1.0 -margin_top = 160.0 -margin_bottom = 240.0 +anchor_bottom = 1.0 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="day_scroll/value_next"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 0, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="month_scroll" type="Control" parent="."] -margin_left = 243.0 -margin_right = 477.0 -margin_bottom = 1280.0 -rect_min_size = Vector2( 234, 0 ) +anchor_left = 0.333 +anchor_right = 0.666 +anchor_bottom = 1.0 script = ExtResource( 1 ) -[node name="label" type="Label" parent="month_scroll"] +[node name="value_previous" type="Label" parent="month_scroll"] anchor_right = 1.0 -text = "month" +anchor_bottom = 0.333 +mouse_filter = 1 align = 1 +valign = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="value_previous" type="Label" parent="month_scroll"] +[node name="ColorRect" type="ColorRect" parent="month_scroll/value_previous"] anchor_right = 1.0 -margin_bottom = 80.0 -mouse_filter = 1 -align = 1 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 0, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value" type="Label" parent="month_scroll"] +anchor_top = 0.333 anchor_right = 1.0 -margin_top = 80.0 -margin_bottom = 160.0 +anchor_bottom = 0.666 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="month_scroll/value"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value_next" type="Label" parent="month_scroll"] +anchor_top = 0.666 anchor_right = 1.0 -margin_top = 160.0 -margin_bottom = 240.0 +anchor_bottom = 1.0 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="month_scroll/value_next"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 0, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="year_scroll" type="Control" parent="."] -margin_left = 481.0 -margin_right = 715.0 -margin_bottom = 1280.0 -rect_min_size = Vector2( 234, 0 ) +anchor_left = 0.666 +anchor_right = 1.0 +anchor_bottom = 1.0 script = ExtResource( 1 ) -[node name="label" type="Label" parent="year_scroll"] +[node name="value_previous" type="Label" parent="year_scroll"] anchor_right = 1.0 -text = "year" +anchor_bottom = 0.333 +mouse_filter = 1 align = 1 +valign = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="value_previous" type="Label" parent="year_scroll"] +[node name="ColorRect" type="ColorRect" parent="year_scroll/value_previous"] anchor_right = 1.0 -margin_bottom = 80.0 -mouse_filter = 1 -align = 1 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 0, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value" type="Label" parent="year_scroll"] +anchor_top = 0.333 anchor_right = 1.0 -margin_top = 80.0 -margin_bottom = 160.0 +anchor_bottom = 0.666 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="year_scroll/value"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 1, 0.0980392 ) __meta__ = { "_edit_use_anchors_": false } [node name="value_next" type="Label" parent="year_scroll"] +anchor_top = 0.666 anchor_right = 1.0 -margin_top = 160.0 -margin_bottom = 240.0 +anchor_bottom = 1.0 mouse_filter = 1 align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ColorRect" type="ColorRect" parent="year_scroll/value_next"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 1, 1, 0, 0.0980392 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="split_previous" type="ColorRect" parent="."] +anchor_top = 0.333 +anchor_right = 1.0 +anchor_bottom = 0.343 +color = Color( 1, 1, 1, 0.25 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="split_next" type="ColorRect" parent="."] +anchor_top = 0.666 +anchor_right = 1.0 +anchor_bottom = 0.676 +color = Color( 1, 1, 1, 0.25 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/date_picker/scroll_picker.gd b/date_picker/scroll_picker.gd index ba70084..1d184b9 100644 --- a/date_picker/scroll_picker.gd +++ b/date_picker/scroll_picker.gd @@ -9,6 +9,10 @@ var pointer_id: int = -1 var start_pos: float = 0.0 var pos: float = 0.0 +var value_base_position: float +var value_next_base_position: float +var value_previous_base_position: float + func _ready(): pointer = { @@ -20,19 +24,23 @@ func _ready(): is_active = false, timestamp = 0 } + value_base_position = ($value as Label).rect_position.y + value_next_base_position = ($value_next as Label).rect_position.y + value_previous_base_position = ($value_previous as Label).rect_position.y func _process(delta: float): -# $label.text = "%s" % pointer.index - pointer.velocity *= clamp((1.0 - 5.5 * delta), 0.0, 1.0) # pow(1.0-0.995, delta) + + var max_value := 10 + var scroll_unit_height := ($value as Label).rect_size.y + + pointer.velocity *= clamp((1.0 - 5.5 * delta), 0.0, 1.0) 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) < 50.0: - var max_value := 10 - var scroll_unit_height := 80 var normalized_value := -value / scroll_unit_height var normalized_int_value := round(normalized_value) as int var logic_value := fposmod(normalized_int_value, max_value) @@ -43,24 +51,22 @@ func _process(delta: float): # ($test as TextureRect).rect_global_position.y = value # $debug.text = "value: %s\nvelocity: %s\n%s" % [value, pointer.velocity, pointer.relative] var current_pos = value - var turn_over := 800 + var turn_over := scroll_unit_height * max_value if current_pos >= turn_over || current_pos < 0.0: value = fposmod(current_pos, turn_over) # elif current_pos < 0: # value = 800 - current_pos - var max_value := 10 - var scroll_unit_height := 40 var normalized_value := -value / scroll_unit_height var normalized_int_value := round(normalized_value) as int var logic_value := fposmod(normalized_int_value, max_value) var logic_next_value := fposmod(normalized_int_value + 1, max_value) var logic_previous_value := fposmod(normalized_int_value - 1, max_value) - var value_base_position := 140.0 # 180.0 - var value_next_base_position := 180.0 # 260.0 - var value_previous_base_position := 100.0 +# var value_base_position := ($value_previous as Label).rect_position.y # 140.0 # 180.0 +# var value_next_base_position := ($value_next as Label).rect_position.y #180.0 # 260.0 +# var value_previous_base_position := ($value as Label).rect_position.y #100.0 $value.text = "%d" % logic_value $value_next.text = "%d" % logic_next_value @@ -106,7 +112,7 @@ func _gui_input(event: InputEvent): # if pointer.is_active == false: # $output.text += "%10d: touch %d\n" % [abs(pointer.timestamp - time), touch.index] - if event is InputEventScreenDrag: # && pointer.index == event.index: + if event is InputEventScreenDrag && event.index == pointer.index: var drag := event as InputEventScreenDrag pointer.current_position = drag.position pointer.velocity = drag.speed @@ -12,7 +12,27 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="ScrollContainer2" type="ScrollContainer" parent="TabContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/ScrollContainer2"] +margin_right = 400.0 +margin_bottom = 200.0 + +[node name="date_picker" parent="TabContainer/ScrollContainer2/VBoxContainer" instance=ExtResource( 2 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_right = 400.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 400, 200 ) + [node name="ScrollContainer" type="ScrollContainer" parent="TabContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -151,19 +171,3 @@ rect_min_size = Vector2( 0, 50 ) __meta__ = { "_edit_use_anchors_": false } - -[node name="ScrollContainer2" type="ScrollContainer" parent="TabContainer"] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_left = 4.0 -margin_top = 32.0 -margin_right = -4.0 -margin_bottom = -4.0 - -[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/ScrollContainer2"] -margin_right = 710.0 - -[node name="date_picker" parent="TabContainer/ScrollContainer2/VBoxContainer" instance=ExtResource( 2 )] -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 710.0 |
