Skip to content

Notification delegates for individual Panels and Tabs #17

Open

Description

@FSanta

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!

Activity

  1. yasirkula commented on Jan 21, 2022

    @yasirkula
    Owner

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

  2. FSanta commented on Jan 22, 2022

    @FSanta
    Author

    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 :)

  3. yasirkula commented on Jan 22, 2022

    @yasirkula
    Owner

    Looks neat! What are its known flaws?

  4. FSanta commented on Jan 22, 2022

    @FSanta
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions