|
2 | 2 | // Licensed under the MIT License. See the LICENSE. |
3 | 3 |
|
4 | 4 | using CommunityToolkit.WinUI.UI; |
| 5 | +using Microsoft.UI.Input; |
5 | 6 | using Microsoft.UI.Xaml; |
6 | 7 | using Microsoft.UI.Xaml.Controls; |
7 | 8 | using Microsoft.UI.Xaml.Input; |
8 | 9 | using Microsoft.UI.Xaml.Shapes; |
9 | 10 | using Windows.ApplicationModel.DataTransfer; |
| 11 | +using Windows.Graphics; |
10 | 12 | using Windows.Storage; |
11 | 13 | using Windows.Win32; |
12 | 14 |
|
@@ -65,6 +67,8 @@ public GridLength TitleBarWidth |
65 | 67 |
|
66 | 68 | public static event EventHandler<TabBarItem?>? SelectedTabItemChanged; |
67 | 69 |
|
| 70 | + public event EventHandler<SizeChangedEventArgs>? TabControlAreaSizeChanged; |
| 71 | + |
68 | 72 | // Constructor |
69 | 73 |
|
70 | 74 | public TabBar() |
@@ -92,6 +96,9 @@ public TabBar() |
92 | 96 | }; |
93 | 97 | } |
94 | 98 |
|
| 99 | + private void BaseTabBar_Loaded(object sender, RoutedEventArgs e) |
| 100 | + => MainWindow.Instance.AppWindow.Changed += (_, _) => MainWindow.Instance.RaiseSetTitleBarDragRegion(SetTitleBarDragRegion); |
| 101 | + |
95 | 102 | private void TabView_TabItemsChanged(TabView sender, Windows.Foundation.Collections.IVectorChangedEventArgs args) |
96 | 103 | { |
97 | 104 | if (args.CollectionChange == Windows.Foundation.Collections.CollectionChange.ItemRemoved) |
@@ -380,6 +387,19 @@ private void DragAreaRectangle_Loaded(object sender, RoutedEventArgs e) |
380 | 387 | var width = HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - TitleBarWidth.Value; |
381 | 388 | var height = HorizontalTabView.ActualHeight; |
382 | 389 | 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; |
383 | 403 | } |
384 | 404 | } |
385 | 405 | } |
0 commit comments