Browse Source

Merge pull request #47360 from lupoDharkael/modal-close-click

[3.x] Control: Expose pass_on_modal_close_click
Rémi Verschelde 4 years ago
parent
commit
6d022f813f
4 changed files with 13 additions and 3 deletions
  1. 4 0
      doc/classes/Control.xml
  2. 7 1
      scene/gui/control.cpp
  3. 1 1
      scene/gui/control.h
  4. 1 1
      scene/main/viewport.cpp

+ 4 - 0
doc/classes/Control.xml

@@ -895,6 +895,10 @@
 		<member name="mouse_filter" type="int" setter="set_mouse_filter" getter="get_mouse_filter" enum="Control.MouseFilter" default="0">
 			Controls whether the control will be able to receive mouse button input events through [method _gui_input] and how these events should be handled. Also controls whether the control can receive the [signal mouse_entered], and [signal mouse_exited] signals. See the constants to learn what each does.
 		</member>
+		<member name="input_pass_on_modal_close_click" type="bool" setter="set_pass_on_modal_close_click" getter="get_pass_on_modal_close_click" default="true">
+			Enables whether input should propagate when you close the control as modal.
+			If [code]false[/code], stops event handling at the viewport input event handling. The viewport first hides the modal and after marks the input as handled.
+		</member>
 		<member name="rect_clip_content" type="bool" setter="set_clip_contents" getter="is_clipping_contents" default="false">
 			Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered.
 		</member>

+ 7 - 1
scene/gui/control.cpp

@@ -2613,7 +2613,7 @@ void Control::set_pass_on_modal_close_click(bool p_pass_on) {
 	data.pass_on_modal_close_click = p_pass_on;
 }
 
-bool Control::pass_on_modal_close_click() const {
+bool Control::get_pass_on_modal_close_click() const {
 
 	return data.pass_on_modal_close_click;
 }
@@ -2941,6 +2941,9 @@ void Control::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
 	ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
 
+	ClassDB::bind_method(D_METHOD("set_pass_on_modal_close_click", "enabled"), &Control::set_pass_on_modal_close_click);
+	ClassDB::bind_method(D_METHOD("get_pass_on_modal_close_click"), &Control::get_pass_on_modal_close_click);
+
 	ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
 	ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
 
@@ -3013,6 +3016,9 @@ void Control::_bind_methods() {
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,Ibeam,Pointing hand,Cross,Wait,Busy,Drag,Can drop,Forbidden,Vertical resize,Horizontal resize,Secondary diagonal resize,Main diagonal resize,Move,Vertical split,Horizontal split,Help"), "set_default_cursor_shape", "get_default_cursor_shape");
 
+	ADD_GROUP("Input", "input_");
+	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pass_on_modal_close_click"), "set_pass_on_modal_close_click", "get_pass_on_modal_close_click");
+
 	ADD_GROUP("Size Flags", "size_flags_");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");

+ 1 - 1
scene/gui/control.h

@@ -416,7 +416,7 @@ public:
 	MouseFilter get_mouse_filter() const;
 
 	void set_pass_on_modal_close_click(bool p_pass_on);
-	bool pass_on_modal_close_click() const;
+	bool get_pass_on_modal_close_click() const;
 
 	/* SKINNING */
 

+ 1 - 1
scene/main/viewport.cpp

@@ -1951,7 +1951,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
 						top->_modal_stack_remove();
 						top->hide();
 
-						if (!top->pass_on_modal_close_click()) {
+						if (!top->get_pass_on_modal_close_click()) {
 							is_handled = true;
 						}
 					} else {