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

Notification delegates for individual Panels and Tabs #17

Open
FSanta opened this issue Jan 21, 2022 · 4 comments
Open

Notification delegates for individual Panels and Tabs #17

FSanta opened this issue Jan 21, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@FSanta
Copy link

FSanta commented Jan 21, 2022

OnPanelClosed and OnTabClosed works globally for all panels/tabs.
I would love to be able to define different delegate methods for different tabs. This way I could specify individual behavior on close or even make some tabs closeable and others not.
Sadly I'm not experienced with C# delegates so I'm having a hard time thinking of a workaround that works for me.

Thanks for this great Plugin!

@yasirkula yasirkula added the enhancement New feature or request label Jan 21, 2022
@yasirkula
Copy link
Owner

Thank you for the feature request! I probably won't be able to add this feature in the near future, though.

@FSanta
Copy link
Author

FSanta commented Jan 22, 2022

Thanks for the response!

Here is my current workaround - I had to make changes to the source of the plugin which could break the existing functionality:

PanelTab - Add a new Method:

public void AddCloseButtonListener( UnityAction call )
{
	closeButton.onClick.AddListener( call );
	Internal.ChangeCloseButtonVisibility( true );
}

PanelNotificationCenter#TabIDChanged
Disable the call to ChangeCloseButtonVisibility so it won't hide the close button again

An example listener that simply destroys the tab if the Button is Clicked:

panelTab.AddCloseButtonListener( () =>
{
	panelTab.Destroy();
});

For Panels the changes should be very similar

Obviously, this solution is quite flawed but it is a simple workaround that will do the trick for me :)

@yasirkula
Copy link
Owner

Looks neat! What are its known flaws?

@FSanta
Copy link
Author

FSanta commented Jan 22, 2022

I think it is quite "hacky" because it does not use the PanelNotificationCenter which was originally intended for this purpose.
An the behavior becomes unpredictable if used together with the PanelNotificationCenter.OnTabClosed.
For example if you happen to use both at some point:

PanelNotificationCenter.OnTabClosed += ( PanelTab tab ) => {
	tab.Destroy();
};
panelTab = PanelUtils.CreatePanelFor( scriptEditor, canvas ).GetTab( scriptEditor );
panelTab.AddCloseButtonListener( () =>
{
	scriptEditor.GetComponentInChildren<TMP_InputField>().SetTextWithoutNotify( "You can't close yet!" );
} );

The tab will always be closed and the text won't ever show. But the same unpredictability can happen if you register multiple Delegates so maybe this is simply the responsibility of the developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants