Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs node's right_button_pressed signal doesn't fire #64498

Closed
Aratch opened this issue Aug 16, 2022 · 5 comments · Fixed by #64707
Closed

Tabs node's right_button_pressed signal doesn't fire #64498

Aratch opened this issue Aug 16, 2022 · 5 comments · Fixed by #64707
Milestone

Comments

@Aratch
Copy link

Aratch commented Aug 16, 2022

Godot version

3.4.2-stable, 3.4.4-stable, 3.5-stable

System information

Ubuntu 22.04

Issue description

I'm posting this there since I'm assuming this isn't intended behaviour for the 3.x branch, and it appears this hasn't been reported as an issue yet. I'm aware this is probably fixed by #58687 in 4.0. The only other reference I've found is an old Q&A post where OP states the signal is there for internal reasons.

The issue at hand: After connecting a method to the Tabs node's right_button_pressed signal, the method bound to the signal is not triggered when right-clicking on a tab, which would be necessary to intercept right mouse button clicks to individual tabs. I've noticed this while trying to figure out how to add a GUI feature to an open-source application.

A partial workaround could be using gui_input() instead (though without easily accessible info on tabs). Variously querying Input for mouse button presses or releases within a method connected to the tab_clicked does not yield any positive results.

Steps to reproduce

  1. Create a Tabs node in a new scene with a rect_min_size large enough to display at least two tabs.
  2. Add a minimum of two tabs to the node by calling add_tab("..") twice in _ready.
  3. Connect the right_button_pressed signal to a method.
  4. Run the scene and right-click on tabs. Nothing happens.
extends Tabs

func _ready() -> void:
	self.connect("right_button_pressed", self, "_on_Tabs_right_button_pressed")
	self.add_tab("foo")
	self.add_tab("bar")

func _on_Tabs_right_button_pressed(tab: int) -> void:
	# This callback is never actually called.
	print("RIGHT BUTTON PRESSED")

Minimal reproduction project

Tabs_RMBSignal_Reproduction.zip

@Calinou Calinou added this to the 3.x milestone Aug 16, 2022
@heppocogne
Copy link
Contributor

"right button" does not mean right-click but "button on the right side of the text" which is only used in godot editor gui and not accessible from gdscript. This feature is used as ThemeEditor's close button for example:
image

In my opinion, the behavior mentioned in the documentation would be more natural:

Signals

  • right_button_pressed ( int tab )
    Emitted when a tab is right-clicked.

@Aratch
Copy link
Author

Aratch commented Aug 17, 2022

I see now where the Q&A's OP got the impression that the signal is only used internally in the engine. In other words, this issue is based on a misunderstanding.

I suppose, then, there is no ready-to-use solution to check for right mouse-button clicks on a tab.

@heppocogne
Copy link
Contributor

right-click detection example (might not work if tabs are scaled or rotated):

extends Tabs

signal tab_right_clicked(tab)

func _input(event:InputEvent):
	if event is InputEventMouseButton:
		var mb:=event as InputEventMouseButton
		if !mb.pressed or mb.button_index!=BUTTON_RIGHT:
			return
		var w:=0.0
		var w_limit:=get_rect().size.x
		for i in get_tab_count():
			if i<get_tab_offset():
				continue
			w+=get_tab_rect(i).size.x
			if w_limit<w:
				return
			if get_tab_rect(i).has_point(mb.position):
				emit_signal("tab_right_clicked",i)
				return

@Aratch
Copy link
Author

Aratch commented Aug 17, 2022

Thank you, @heppocogne! I've tried your solution and it works!

I suppose this issue can be closed due to it not actually being a bug but more of a documentation mix-up. Whether this warrants a change in the docs is a different question.

@akien-mga
Copy link
Member

Fixed by #64707.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants