Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Files.App/UserControls/TabBar/TabBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
xmlns:root="using:Files.App"
xmlns:uc="using:Files.App.UserControls"
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
Loaded="BaseTabBar_Loaded"
mc:Ignorable="d">

<local:BaseTabBar.Resources>
Expand Down Expand Up @@ -228,7 +229,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition x:Name="RightPaddingColumn" Width="0" />
<ColumnDefinition x:Name="RightPaddingColumn" Width="{x:Bind TitleBarWidth, Mode=OneWay}" />
</Grid.ColumnDefinitions>

<!-- Height is not divisble by four in order to properly align the button -->
Expand Down Expand Up @@ -260,7 +261,8 @@
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="Transparent" />
Fill="Transparent"
Loaded="DragAreaRectangle_Loaded" />

</Grid>
</TabView.TabStripFooter>
Expand Down
45 changes: 40 additions & 5 deletions src/Files.App/UserControls/TabBar/TabBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.WinUI.UI;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Shapes;
using Windows.ApplicationModel.DataTransfer;
using Windows.Graphics;
using Windows.Storage;
using Windows.Win32;

Expand All @@ -28,6 +30,8 @@ public sealed partial class TabBar : BaseTabBar, INotifyPropertyChanged

private bool _lockDropOperation = false;

private static int _gap = 6;

// Starting position when dragging a tab
private System.Drawing.Point dragStartPoint;

Expand All @@ -51,10 +55,20 @@ public bool AllowTabsDrag
public Rectangle DragArea
=> DragAreaRectangle;

private GridLength _titleBarWidth;

public GridLength TitleBarWidth
{
get => _titleBarWidth;
set => _titleBarWidth = new(value.Value + _gap);
}

// Events

public static event EventHandler<TabBarItem?>? SelectedTabItemChanged;

public event EventHandler<SizeChangedEventArgs>? TabControlAreaSizeChanged;

// Constructor

public TabBar()
Expand All @@ -66,12 +80,10 @@ public TabBar()

var appWindow = MainWindow.Instance.AppWindow;

double rightPaddingColumnWidth =
FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft
TitleBarWidth =
new(FilePropertiesHelpers.FlowDirectionSettingIsRightToLeft
? appWindow.TitleBar.LeftInset
: appWindow.TitleBar.RightInset;

RightPaddingColumn.Width = new(rightPaddingColumnWidth >= 0 ? rightPaddingColumnWidth : 0);
: appWindow.TitleBar.RightInset);

AppearanceSettingsService.PropertyChanged += (s, e) =>
{
Expand All @@ -84,6 +96,9 @@ public TabBar()
};
}

private void BaseTabBar_Loaded(object sender, RoutedEventArgs e)
=> MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);

private void TabView_TabItemsChanged(TabView sender, Windows.Foundation.Collections.IVectorChangedEventArgs args)
{
if (args.CollectionChange == Windows.Foundation.Collections.CollectionChange.ItemRemoved)
Expand Down Expand Up @@ -366,5 +381,25 @@ private void TabViewItem_Loaded(object sender, RoutedEventArgs e)
});
}
}

private void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
{
var width = HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - TitleBarWidth.Value;
var height = HorizontalTabView.ActualHeight;
HorizontalTabView.Measure(new(width >= 0 ? width : 0, height >= 0 ? height : 0));

MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
SizeChanged += (s, e) => TabControlAreaSizeChanged?.Invoke(s, e);
DragArea.SizeChanged += (s, e) => TabControlAreaSizeChanged?.Invoke(s, e);
}

private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
{
var height = (int)ActualHeight;
var width = (int)(ActualWidth - DragArea.ActualWidth);

source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, width, height))]);
return height;
}
}
}
13 changes: 3 additions & 10 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh
}

private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs e)
=> TabControl.TabControlAreaSizeChanged += TabControlArea_SizeChanged;

private void TabControlArea_SizeChanged(object sender, SizeChangedEventArgs e)
{
TabControl.DragArea.SizeChanged += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
if (ViewModel.MultitaskingControl is not TabBar)
{
ViewModel.MultitaskingControl = TabControl;
Expand All @@ -135,13 +137,6 @@ private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs
}
}

private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
{
var height = (int)TabControl.ActualHeight;
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, (int)(TabControl.ActualWidth + TabControl.Margin.Left - TabControl.DragArea.ActualWidth), height))]);
return height;
}

public async void TabItemContent_ContentChanged(object? sender, TabBarItemParameter e)
{
if (SidebarAdaptiveViewModel.PaneHolder is null)
Expand Down Expand Up @@ -279,8 +274,6 @@ protected override void OnLostFocus(RoutedEventArgs e)

private void Page_Loaded(object sender, RoutedEventArgs e)
{
MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);

// Defers the status bar loading until after the page has loaded to improve startup perf
FindName(nameof(StatusBar));
FindName(nameof(InnerNavigationToolbar));
Expand Down
Loading