aboutsummaryrefslogtreecommitdiff
path: root/touch_vertical_container
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-02-18 01:34:43 +0000
committerdam <dam@gudinoff>2022-02-18 01:34:43 +0000
commit283c0f2d84420bd02550dd4404b306d427fd58af (patch)
tree3999ad958556bcccba63b5fca05880accdc827f3 /touch_vertical_container
parent48a26128f175047528fcc1c96590f1a7bbc281eb (diff)
downloadsurgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.tar.zst
surgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.zip
Implemented custom option set control. Fixed option sets text input zone being hidden below the button.
Diffstat (limited to 'touch_vertical_container')
-rw-r--r--touch_vertical_container/touch_vertical_container.gd71
1 files changed, 40 insertions, 31 deletions
diff --git a/touch_vertical_container/touch_vertical_container.gd b/touch_vertical_container/touch_vertical_container.gd
index 7c2ba84..1a7236c 100644
--- a/touch_vertical_container/touch_vertical_container.gd
+++ b/touch_vertical_container/touch_vertical_container.gd
@@ -26,9 +26,6 @@ func _ready():
sensor.connect("on_drag", self, "pointer_input_on_drag_handler")
sensor.connect("on_end_drag", self, "pointer_input_on_end_drag_handler")
sensor.connect("on_click", self, "pointer_input_on_click_handler")
-
-# it.connect("focus_entered", sensor, "set_visible", [false])
-# it.connect("focus_exited", sensor, "set_visible", [true])
func _process(delta: float):
@@ -54,33 +51,45 @@ func pointer_input_on_end_drag_handler(pointer: PointerInputSensor.PointerInputD
func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData):
- propagate_click(pointer.target.get_parent(), pointer)
-
-
-# @DAM Maybe replace this with a stack of next items to process approach.
-func propagate_click(control: Control, pointer: PointerInputSensor.PointerInputData) -> bool:
- if control is PointerInputSensor || control.mouse_filter == MOUSE_FILTER_IGNORE || control.visible == false:
- return false
- var click_processed := false
- if control.get_global_rect().has_point(pointer.current_position):
- var children = control.get_children()
- children.invert() # @DAM Use inverted index for loop to avoid invert() operation.
- for child in children:
- if child is Control:
- click_processed = click_processed || propagate_click(child, pointer)
- if click_processed == true:
- break
-
- if click_processed == false:
- if control is CheckBox || control is CheckButton:
- control.pressed = !control.pressed
- control.grab_focus()
- control.emit_signal("button_down")
- control.emit_signal("pressed")
- control.emit_signal("button_up")
- click_processed = true
- pointer.target.visible = false
- control.connect("focus_exited", pointer.target, "set_visible", [true])
+ # Get last leaf node.
+ var root := pointer.target.get_parent() as Control
+ var leaf := root as Node
+ while leaf.get_child_count() > 0:
+ leaf = leaf.get_child(leaf.get_child_count() - 1)
- return click_processed
+ # Navigate backwards from leaf to root until we find a node accepting the input.
+ var tried_leaf_as_root := false
+ while leaf != root || tried_leaf_as_root == false:
+ tried_leaf_as_root = leaf == root # Allow a final iteration cycle when leaf reaches root.
+ var node := leaf
+
+ if node is PointerInputSensor \
+ || node is Control == false \
+ || node.mouse_filter == MOUSE_FILTER_IGNORE \
+ || node.visible == false \
+ || node.get_global_rect().has_point(pointer.current_position) == false:
+ # Get next node to be processed.
+ var leaf_index_in_parent := leaf.get_position_in_parent()
+ var parent := leaf.get_parent()
+ if leaf_index_in_parent == 0:
+ leaf = parent
+ else:
+ leaf = parent.get_child(leaf_index_in_parent - 1)
+ # Drill down into the new tree branch.
+ while leaf.get_child_count() > 0:
+ leaf = leaf.get_child(leaf.get_child_count() - 1)
+ continue
+
+ var control: Control = node
+ if control is CheckBox || control is CheckButton:
+ control.pressed = !control.pressed
+
+ control.grab_focus()
+ control.emit_signal("button_down")
+ control.emit_signal("pressed")
+ control.emit_signal("button_up")
+ control.connect("focus_exited", pointer.target, "set_visible", [true], CONNECT_ONESHOT)
+ pointer.target.visible = false
+ break
+