Skip to content

Commit

Permalink
CQ: set drag area in TabBar
Browse files Browse the repository at this point in the history
  • Loading branch information
XTorLukas committed Nov 30, 2024
1 parent d25fc8e commit a13dc4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
17 changes: 2 additions & 15 deletions src/Files.App/UserControls/TabBar/TabBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public GridLength TitleBarWidth

public static event EventHandler<TabBarItem?>? SelectedTabItemChanged;

public event EventHandler<SizeChangedEventArgs>? TabControlAreaSizeChanged;

// Constructor

public TabBar()
Expand Down Expand Up @@ -96,9 +94,6 @@ 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 @@ -383,17 +378,9 @@ 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);
}
=> HorizontalTabView.Measure(new(HorizontalTabView.ActualWidth - TabBarAddNewTabButton.Width - TitleBarWidth.Value, HorizontalTabView.ActualHeight));

private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
public int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
{
var height = (int)ActualHeight;
var width = (int)(ActualWidth - DragArea.ActualWidth);
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ private void UserSettingsService_OnSettingChangedEvent(object? sender, SettingCh
}

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

private void TabControlArea_SizeChanged(object sender, SizeChangedEventArgs e)
{
MainWindow.Instance.RaiseSetTitleBarDragRegion(TabControl.SetTitleBarDragRegion);
if (ViewModel.MultitaskingControl is not TabBar)
{
ViewModel.MultitaskingControl = TabControl;
Expand Down Expand Up @@ -274,6 +278,8 @@ protected override void OnLostFocus(RoutedEventArgs e)

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

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

0 comments on commit a13dc4c

Please sign in to comment.