Skip to content

Commit

Permalink
Fix #11050: [Core][Windows] Close button visibility toggle causes a c…
Browse files Browse the repository at this point in the history
…rash
  • Loading branch information
sescalada committed Jul 25, 2024
1 parent a6edd82 commit 19a9d98
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,12 @@ public void GetButtonDescriptionByEntity()

Assert.Same(expectedDescription, foundDescription);
}

[Fact]
public void NotReturnCloseButtonEntityWhenNotIncluded()
{
this.organizer.IncludeCloseButton = false;
Assert.Null(this.organizer.CloseButtonEntity);
}
}
}
20 changes: 20 additions & 0 deletions src/core/Evergine.Xrv.Core/UI/Windows/ActionButtonsOrganizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,19 @@ private void UpdateOrganization()
{
this.CreateButtonInstanceForContainer(this.followButtonDescription, true);
}
else
{
this.RemoveButtonInstanceForContainer(this.followButtonDescription, true);
}

if (this.includeCloseButton)
{
this.CreateButtonInstanceForContainer(this.closeButtonDescription, true);
}
else
{
this.RemoveButtonInstanceForContainer(this.closeButtonDescription, true);
}

this.OrganizationUpdated?.Invoke(this, EventArgs.Empty);
this.organizerCallback?.AfterUpdatingLayout();
Expand Down Expand Up @@ -311,6 +319,18 @@ private void CreateButtonInstanceForContainer(ButtonDescription description, boo
}
}

private void RemoveButtonInstanceForContainer(ButtonDescription buttonDescription, bool isActionBarButton)
{
if (isActionBarButton)
{
this.instantiatedActionBarButtons.Remove(buttonDescription.Id);
}
else
{
this.instantiatedMoreActionButtons.Remove(buttonDescription.Id);
}
}

private void CreateOrDeleteMoreActionsDescriptionIfRequired()
{
bool shouldShowMoreActions = this.CalculateActionBarInitialFreeSlots() < this.extraButtonDescriptions.Count;
Expand Down
22 changes: 18 additions & 4 deletions src/core/Evergine.Xrv.Core/UI/Windows/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,25 @@ private void SubscribeBuiltInButtonEvents()
this.moreActionsButtonToggle = null;
}

this.followButtonToggle = this.buttonsOrganizer.FollowButtonEntity.FindComponentInChildren<ToggleButton>();
this.followButtonToggle.Toggled += this.FollowButtonToggled;
if (this.buttonsOrganizer.FollowButtonEntity != null)
{
this.followButtonToggle = this.buttonsOrganizer.FollowButtonEntity.FindComponentInChildren<ToggleButton>();
this.followButtonToggle.Toggled += this.FollowButtonToggled;
}
else
{
this.followButtonToggle = null;
}

this.closeButtonPressable = this.buttonsOrganizer.CloseButtonEntity.FindComponentInChildren<PressableButton>();
this.closeButtonPressable.ButtonReleased += this.CloseButtonReleased;
if (this.buttonsOrganizer.CloseButtonEntity != null)
{
this.closeButtonPressable = this.buttonsOrganizer.CloseButtonEntity.FindComponentInChildren<PressableButton>();
this.closeButtonPressable.ButtonReleased += this.CloseButtonReleased;
}
else
{
this.closeButtonPressable = null;
}
}

private void UnsubscribeBuiltInButtonEvents()
Expand Down

0 comments on commit 19a9d98

Please sign in to comment.