mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
[Peek]FlowDirection.LeftToRight added to prevent RTL language mirroring (#27258)
* [Peek] FlowDirection.LeftToRight added to prevent RTL language mirroring. * [Peek] Dynamic layout updates applied to title bar for RTL/LTR language support
This commit is contained in:
@@ -149,6 +149,13 @@ namespace Peek.FilePreviewer
|
||||
BrowserPreview.Visibility = Visibility.Collapsed;
|
||||
ArchivePreview.Visibility = Visibility.Collapsed;
|
||||
UnsupportedFilePreview.Visibility = Visibility.Collapsed;
|
||||
|
||||
ImagePreview.FlowDirection = FlowDirection.LeftToRight;
|
||||
VideoPreview.FlowDirection = FlowDirection.LeftToRight;
|
||||
BrowserPreview.FlowDirection = FlowDirection.LeftToRight;
|
||||
ArchivePreview.FlowDirection = FlowDirection.LeftToRight;
|
||||
UnsupportedFilePreview.FlowDirection = FlowDirection.LeftToRight;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,13 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:Peek.UI.Views"
|
||||
FlowDirection="{x:Bind TitleBarFlowDirection, Mode=OneWay}"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="TitleBarRootContainer" Height="48">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition x:Name="SystemLeftPaddingColumn" Width="0" />
|
||||
<ColumnDefinition x:Name="DraggableColumn" Width="*" />
|
||||
<ColumnDefinition x:Name="LaunchAppButtonColumn" Width="Auto" />
|
||||
<ColumnDefinition x:Name="AppRightPaddingColumn" Width="65" />
|
||||
<ColumnDefinition x:Name="PinButtonColumn" Width="40" />
|
||||
<ColumnDefinition x:Name="SystemRightPaddingColumn" Width="0" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid
|
||||
x:Name="AppIconAndFileTitleContainer"
|
||||
Grid.Column="1"
|
||||
Margin="8,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
@@ -46,7 +37,6 @@
|
||||
<Grid
|
||||
x:Name="FileCountAndNameContainer"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
ColumnSpacing="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -76,7 +66,6 @@
|
||||
<Button
|
||||
x:Name="LaunchAppButton"
|
||||
x:Uid="LaunchAppButton"
|
||||
Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
Command="{x:Bind LaunchDefaultAppButtonAsyncCommand, Mode=OneWay}"
|
||||
ToolTipService.ToolTip="{x:Bind OpenWithAppToolTip, Mode=OneWay}"
|
||||
@@ -103,7 +92,6 @@
|
||||
<Button
|
||||
x:Name="PinButton"
|
||||
x:Uid="PinButton"
|
||||
Grid.Column="4"
|
||||
VerticalAlignment="Center"
|
||||
Command="{x:Bind PinCommand, Mode=OneWay}"
|
||||
ToolTipService.ToolTip="{x:Bind PinToolTip(Pinned), Mode=OneWay}">
|
||||
|
||||
@@ -71,6 +71,13 @@ namespace Peek.UI.Views
|
||||
[ObservableProperty]
|
||||
private bool pinned = false;
|
||||
|
||||
private ColumnDefinition systemLeftPaddingColumn = new() { Width = new GridLength(0) };
|
||||
private ColumnDefinition draggableColumn = new() { Width = new GridLength(1, GridUnitType.Star) };
|
||||
private ColumnDefinition launchAppButtonColumn = new() { Width = GridLength.Auto };
|
||||
private ColumnDefinition appRightPaddingColumn = new() { Width = new GridLength(65) };
|
||||
private ColumnDefinition pinButtonColumn = new() { Width = new GridLength(40) };
|
||||
private ColumnDefinition systemRightPaddingColumn = new() { Width = new GridLength(0) };
|
||||
|
||||
public TitleBar()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -184,6 +191,54 @@ namespace Peek.UI.Views
|
||||
Pinned = !Pinned;
|
||||
}
|
||||
|
||||
public FlowDirection TitleBarFlowDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
var direction = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ?
|
||||
FlowDirection.RightToLeft :
|
||||
FlowDirection.LeftToRight;
|
||||
SetupGridColumnDefinitions(direction);
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupGridColumnDefinitions(FlowDirection direction)
|
||||
{
|
||||
TitleBarRootContainer.ColumnDefinitions.Clear();
|
||||
|
||||
if (direction == FlowDirection.LeftToRight)
|
||||
{
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(systemLeftPaddingColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(draggableColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(launchAppButtonColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(appRightPaddingColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(pinButtonColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(systemRightPaddingColumn);
|
||||
|
||||
Grid.SetColumn(AppIconAndFileTitleContainer, 1);
|
||||
FileCountAndNameContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
Grid.SetColumn(LaunchAppButton, 2);
|
||||
Grid.SetColumn(PinButton, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(systemRightPaddingColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(pinButtonColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(appRightPaddingColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(launchAppButtonColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(draggableColumn);
|
||||
TitleBarRootContainer.ColumnDefinitions.Add(systemLeftPaddingColumn);
|
||||
|
||||
Grid.SetColumn(AppIconAndFileTitleContainer, 4);
|
||||
FileCountAndNameContainer.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
Grid.SetColumn(LaunchAppButton, 3);
|
||||
LaunchAppButton.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
Grid.SetColumn(PinButton, 1);
|
||||
PinButton.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
}
|
||||
}
|
||||
|
||||
private void TitleBarRootContainer_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
UpdateDragRegion();
|
||||
@@ -201,22 +256,37 @@ namespace Peek.UI.Views
|
||||
{
|
||||
var scale = MainWindow.GetMonitorScale();
|
||||
|
||||
SystemRightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scale);
|
||||
SystemLeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scale);
|
||||
systemRightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scale);
|
||||
systemLeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scale);
|
||||
|
||||
var dragRectsList = new List<RectInt32>();
|
||||
|
||||
RectInt32 dragRectangleLeft;
|
||||
dragRectangleLeft.X = (int)(SystemLeftPaddingColumn.ActualWidth * scale);
|
||||
dragRectangleLeft.Y = 0;
|
||||
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleLeft.Width = (int)(DraggableColumn.ActualWidth * scale);
|
||||
|
||||
RectInt32 dragRectangleRight;
|
||||
dragRectangleRight.X = (int)((SystemLeftPaddingColumn.ActualWidth + DraggableColumn.ActualWidth + LaunchAppButtonColumn.ActualWidth) * scale);
|
||||
dragRectangleRight.Y = 0;
|
||||
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleRight.Width = (int)(AppRightPaddingColumn.ActualWidth * scale);
|
||||
|
||||
if (TitleBarFlowDirection == FlowDirection.LeftToRight)
|
||||
{
|
||||
dragRectangleLeft.X = (int)(systemLeftPaddingColumn.ActualWidth * scale);
|
||||
dragRectangleLeft.Y = 0;
|
||||
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleLeft.Width = (int)(draggableColumn.ActualWidth * scale);
|
||||
|
||||
dragRectangleRight.X = (int)((systemLeftPaddingColumn.ActualWidth + draggableColumn.ActualWidth + launchAppButtonColumn.ActualWidth) * scale);
|
||||
dragRectangleRight.Y = 0;
|
||||
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleRight.Width = (int)(appRightPaddingColumn.ActualWidth * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
dragRectangleRight.X = (int)(pinButtonColumn.ActualWidth * scale);
|
||||
dragRectangleRight.Y = 0;
|
||||
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleRight.Width = (int)(appRightPaddingColumn.ActualWidth * scale);
|
||||
|
||||
dragRectangleLeft.X = (int)((pinButtonColumn.ActualWidth + appRightPaddingColumn.ActualWidth + launchAppButtonColumn.ActualWidth) * scale);
|
||||
dragRectangleLeft.Y = 0;
|
||||
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleLeft.Width = (int)(draggableColumn.ActualWidth * scale);
|
||||
}
|
||||
|
||||
dragRectsList.Add(dragRectangleLeft);
|
||||
dragRectsList.Add(dragRectangleRight);
|
||||
|
||||
Reference in New Issue
Block a user