Skip to content

Commit

Permalink
Fix playtime stats flyout not showing/disappearing
Browse files Browse the repository at this point in the history
Using a rectangle to determine the position of the pointer is not appropriate, because our buttons have rounded corners.
  • Loading branch information
shatyuka committed Jan 6, 2025
1 parent d25afeb commit 6424ccc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
18 changes: 10 additions & 8 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2281,12 +2281,19 @@
Shadow="{ThemeResource SharedShadow}"
Tag="{x:Bind PlaytimeStatsFlyout}"
Translation="0,0,32">
<ToolTipService.ToolTip>
<ToolTip x:Name="PlaytimeStatsToolTip"
Opened="ShowPlaytimeStatsFlyout"
Tag="{x:Bind PlaytimeBtn}"
Visibility="Collapsed" />
</ToolTipService.ToolTip>
<FlyoutBase.AttachedFlyout>
<Flyout x:Name="PlaytimeStatsFlyout"
LightDismissOverlayMode="On"
LightDismissOverlayMode="Off"
OverlayInputPassThroughElement="{x:Bind PlaytimeBtn}"
Placement="Top">
<Grid ColumnSpacing="8">
Placement="Top"
Opened="PlaytimeStatsFlyout_OnOpened">
<Grid ColumnSpacing="8" Tag="PlaytimeStatsFlyoutGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
Expand Down Expand Up @@ -2534,11 +2541,6 @@
</StackPanel>
</Flyout>
</Button.Flyout>
<ToolTipService.ToolTip>
<ToolTip Opened="ShowPlaytimeStatsFlyout"
Tag="{x:Bind PlaytimeBtn}"
Visibility="Collapsed" />
</ToolTipService.ToolTip>
</Button>
</StackPanel>
</Grid>
Expand Down
33 changes: 12 additions & 21 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2563,33 +2563,24 @@ private void UpdatePlaytime(object sender, CollapsePlaytime playtime)

private void ShowPlaytimeStatsFlyout(object sender, RoutedEventArgs e)
{
ToolTip tooltip = sender as ToolTip;
FlyoutBase.ShowAttachedFlyout(tooltip!.Tag as FrameworkElement);
FlyoutBase.ShowAttachedFlyout(PlaytimeStatsToolTip.Tag as FrameworkElement);
}

private void HidePlaytimeStatsFlyout(object sender, PointerRoutedEventArgs e)
{
FrameworkElement senderAsFrameworkElement = sender as FrameworkElement;

/* This fix an issue where the flyout spawns right on top of the button
* instead of on top of the button in its 1st frame.
*
* If this method is called even within its button's range, then just
* ignore the call and do not hide the flyout.
*/
PointerPoint pointerPoint = e.GetCurrentPoint(senderAsFrameworkElement);
Point currentCursorPosition = pointerPoint.Position;
if (currentCursorPosition.X > 0
&& currentCursorPosition.Y > 0
&& currentCursorPosition.X <= senderAsFrameworkElement!.ActualWidth
&& currentCursorPosition.Y <= senderAsFrameworkElement!.ActualHeight)
PlaytimeStatsFlyout.Hide();
PlaytimeStatsToolTip.IsOpen = false;
}

private void PlaytimeStatsFlyout_OnOpened(object sender, object e)
{
// Match PlaytimeStatsFlyout and set it's transition animation offset to 0 (but keep animation itself)
var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(PlaytimeBtn.XamlRoot);
foreach (var popup in popups.Where(x => x.Child is FlyoutPresenter {Content: Grid {Tag: "PlaytimeStatsFlyoutGrid"}}))
{
return;
var transition = popup.ChildTransitions[0] as PopupThemeTransition;
transition!.FromVerticalOffset = 0;
}

// Otherwise, hide the flyout
Flyout flyout = senderAsFrameworkElement!.Tag as Flyout;
flyout!.Hide();
}
#nullable restore
#endregion
Expand Down

0 comments on commit 6424ccc

Please sign in to comment.