Skip to content

Commit d25fc8e

Browse files
committed
CQ: Move to TabBar
1 parent 9918dfb commit d25fc8e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/Files.App/UserControls/TabBar/TabBar.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
xmlns:root="using:Files.App"
1212
xmlns:uc="using:Files.App.UserControls"
1313
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
14+
Loaded="BaseTabBar_Loaded"
1415
mc:Ignorable="d">
1516

1617
<local:BaseTabBar.Resources>

src/Files.App/UserControls/TabBar/TabBar.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI.UI;
5+
using Microsoft.UI.Input;
56
using Microsoft.UI.Xaml;
67
using Microsoft.UI.Xaml.Controls;
78
using Microsoft.UI.Xaml.Input;
89
using Microsoft.UI.Xaml.Shapes;
910
using Windows.ApplicationModel.DataTransfer;
11+
using Windows.Graphics;
1012
using Windows.Storage;
1113
using Windows.Win32;
1214

@@ -65,6 +67,8 @@ public GridLength TitleBarWidth
6567

6668
public static event EventHandler<TabBarItem?>? SelectedTabItemChanged;
6769

70+
public event EventHandler<SizeChangedEventArgs>? TabControlAreaSizeChanged;
71+
6872
// Constructor
6973

7074
public TabBar()
@@ -92,6 +96,9 @@ public TabBar()
9296
};
9397
}
9498

99+
private void BaseTabBar_Loaded(object sender, RoutedEventArgs e)
100+
=> MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
101+
95102
private void TabView_TabItemsChanged(TabView sender, Windows.Foundation.Collections.IVectorChangedEventArgs args)
96103
{
97104
if (args.CollectionChange == Windows.Foundation.Collections.CollectionChange.ItemRemoved)
@@ -380,6 +387,19 @@ private void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e)
380387
var width = HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - TitleBarWidth.Value;
381388
var height = HorizontalTabView.ActualHeight;
382389
HorizontalTabView.Measure(new(width >= 0 ? width : 0, height >= 0 ? height : 0));
390+
391+
MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
392+
SizeChanged += (s, e) => TabControlAreaSizeChanged?.Invoke(s, e);
393+
DragArea.SizeChanged += (s, e) => TabControlAreaSizeChanged?.Invoke(s, e);
394+
}
395+
396+
private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
397+
{
398+
var height = (int)ActualHeight;
399+
var width = (int)(ActualWidth - DragArea.ActualWidth);
400+
401+
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, width, height))]);
402+
return height;
383403
}
384404
}
385405
}

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,10 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh
125125
}
126126

127127
private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs e)
128-
{
129-
TabControl.SizeChanged += TabControlArea_SizeChanged;
130-
TabControl.DragArea.SizeChanged += TabControlArea_SizeChanged;
131-
}
128+
=> TabControl.TabControlAreaSizeChanged += TabControlArea_SizeChanged;
132129

133130
private void TabControlArea_SizeChanged(object sender, SizeChangedEventArgs e)
134131
{
135-
MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
136132
if (ViewModel.MultitaskingControl is not TabBar)
137133
{
138134
ViewModel.MultitaskingControl = TabControl;
@@ -141,15 +137,6 @@ private void TabControlArea_SizeChanged(object sender, SizeChangedEventArgs e)
141137
}
142138
}
143139

144-
private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
145-
{
146-
var height = (int)TabControl.ActualHeight;
147-
var width = (int)(TabControl.ActualWidth - TabControl.DragArea.ActualWidth);
148-
149-
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, width, height))]);
150-
return height;
151-
}
152-
153140
public async void TabItemContent_ContentChanged(object? sender, TabBarItemParameter e)
154141
{
155142
if (SidebarAdaptiveViewModel.PaneHolder is null)
@@ -287,8 +274,6 @@ protected override void OnLostFocus(RoutedEventArgs e)
287274

288275
private void Page_Loaded(object sender, RoutedEventArgs e)
289276
{
290-
MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion);
291-
292277
// Defers the status bar loading until after the page has loaded to improve startup perf
293278
FindName(nameof(StatusBar));
294279
FindName(nameof(InnerNavigationToolbar));

0 commit comments

Comments
 (0)