Skip to content

Commit

Permalink
Fixed title bar when Windows language is set to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed May 8, 2023
1 parent 162db0c commit 837592e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
22 changes: 22 additions & 0 deletions Telegram/Controls/NavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using Telegram.Converters;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand All @@ -29,6 +31,26 @@ protected override void OnApplyTemplate()

RootSplitView.PaneOpening += OnPaneOpening;
RootSplitView.PaneClosing += OnPaneClosing;

var sender = CoreApplication.GetCurrentView().TitleBar;
sender.IsVisibleChanged += OnLayoutMetricsChanged;
sender.LayoutMetricsChanged += OnLayoutMetricsChanged;

OnLayoutMetricsChanged(sender, null);
}

private void OnLayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
if (sender.SystemOverlayLeftInset > 0)
{
TogglePaneButton.Glyph = Icons.ArrowRight;
TogglePaneButton.HorizontalAlignment = HorizontalAlignment.Right;
}
else
{
TogglePaneButton.Glyph = Icons.ArrowLeft;
TogglePaneButton.HorizontalAlignment = HorizontalAlignment.Left;
}
}

private void Toggle_Click(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public class Icons
public const string Bookmark = "\uE907";
public const string BookmarkFilled = "\uEA0F";
public const string ArrowRight = "\uE72A";
public const string ArrowLeft = "\uE72B";
public const string Channel = "\uEC42";
public const string Speaker = "\uE995";
public const string Speaker1 = "\uE993";
Expand Down
2 changes: 1 addition & 1 deletion Telegram/Telegram.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@
<Compile Include="Converters\FileSizeConverter.cs" />
<Compile Include="Converters\InitialNameStringConverter.cs" />
<Compile Include="Converters\NullToVisibilityConverter.cs" />
<Compile Include="Converters\ReplyInfoToGlyphConverter.cs" />
<Compile Include="Converters\Icons.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Selectors\MessageStyleSelector.cs" />
<Compile Include="Themes\Messages.xaml.cs">
Expand Down
7 changes: 4 additions & 3 deletions Telegram/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,25 @@
Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="52" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border x:Name="TitleBarHandle"
Background="Transparent"
Grid.ColumnSpan="2"
Grid.Column="2" />

<muxc:ProgressBar x:Name="State"
VerticalAlignment="Top"
Background="Transparent"
IsHitTestVisible="False"
Grid.ColumnSpan="4" />
Grid.ColumnSpan="5" />

<HyperlinkButton x:Name="TitleBarLogo"
Click="Status_Click"
Style="{StaticResource EmptyHyperlinkButtonStyle}"
Margin="6,0"
Width="40"
Height="40"
Grid.Column="1">
Expand Down
27 changes: 14 additions & 13 deletions Telegram/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,21 @@ public void Dispose()
private void InitializeTitleBar()
{
var sender = CoreApplication.GetCurrentView().TitleBar;
sender.IsVisibleChanged += OnLayoutMetricsChanged;
sender.LayoutMetricsChanged += OnLayoutMetricsChanged;

TitleBarrr.ColumnDefinitions[0].Width = new GridLength(Math.Max(sender.SystemOverlayLeftInset, 0), GridUnitType.Pixel);
TitleBarrr.ColumnDefinitions[3].Width = new GridLength(Math.Max(sender.SystemOverlayRightInset, 6), GridUnitType.Pixel);

StateLabel.FlowDirection = sender.SystemOverlayLeftInset > 0 ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

sender.IsVisibleChanged += CoreTitleBar_LayoutMetricsChanged;
sender.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;
OnLayoutMetricsChanged(sender, null);
}

private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
private void OnLayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
TitleBarrr.ColumnDefinitions[0].Width = new GridLength(Math.Max(sender.SystemOverlayLeftInset, 0), GridUnitType.Pixel);
TitleBarrr.ColumnDefinitions[3].Width = new GridLength(Math.Max(sender.SystemOverlayRightInset, 6), GridUnitType.Pixel);
TitleBarrr.ColumnDefinitions[4].Width = new GridLength(Math.Max(sender.SystemOverlayRightInset, 0), GridUnitType.Pixel);

StateLabel.FlowDirection = sender.SystemOverlayLeftInset > 0 ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
Grid.SetColumn(TitleBarLogo, sender.SystemOverlayLeftInset > 0 ? 3 : 1);
StateLabel.FlowDirection = sender.SystemOverlayLeftInset > 0
? FlowDirection.RightToLeft
: FlowDirection.LeftToRight;
}

private void InitializeLocalization()
Expand Down Expand Up @@ -1007,8 +1006,8 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
WindowContext.Current.InputListener.KeyDown -= OnAcceleratorKeyActivated;

var titleBar = CoreApplication.GetCurrentView().TitleBar;
titleBar.IsVisibleChanged -= CoreTitleBar_LayoutMetricsChanged;
titleBar.LayoutMetricsChanged -= CoreTitleBar_LayoutMetricsChanged;
titleBar.IsVisibleChanged -= OnLayoutMetricsChanged;
titleBar.LayoutMetricsChanged -= OnLayoutMetricsChanged;

Bindings.StopTracking();

Expand Down Expand Up @@ -1534,12 +1533,14 @@ private void SetPaneToggleButtonVisibility(bool visible)
var logo = ElementCompositionPreview.GetElementVisual(TitleBarLogo);
var label = ElementCompositionPreview.GetElementVisual(StateLabel);

var offset = StateLabel.FlowDirection == FlowDirection.RightToLeft ? -36 : +36;

ElementCompositionPreview.SetIsTranslationEnabled(TitleBarLogo, true);
ElementCompositionPreview.SetIsTranslationEnabled(StateLabel, true);

var anim = logo.Compositor.CreateVector3KeyFrameAnimation();
anim.InsertKeyFrame(visible ? 0 : 1, new Vector3(0, 0, 0));
anim.InsertKeyFrame(visible ? 1 : 0, new Vector3(36, 0, 0));
anim.InsertKeyFrame(visible ? 1 : 0, new Vector3(offset, 0, 0));

logo.StartAnimation("Translation", anim);
label.StartAnimation("Translation", anim);
Expand Down

0 comments on commit 837592e

Please sign in to comment.