From f002ccfa3a4fd93a82fbdcaf83266eb15b9ad17d Mon Sep 17 00:00:00 2001 From: Aleh Khantsevich Date: Mon, 26 Aug 2024 17:27:27 +0200 Subject: [PATCH] Replace WinoPivot with segmented --- Wino.Mail/Controls/WinoPivotControl.xaml | 123 ------------ Wino.Mail/Controls/WinoPivotControl.xaml.cs | 195 -------------------- Wino.Mail/Views/MailListPage.xaml | 43 ++--- Wino.Mail/Wino.Mail.csproj | 10 +- 4 files changed, 25 insertions(+), 346 deletions(-) delete mode 100644 Wino.Mail/Controls/WinoPivotControl.xaml delete mode 100644 Wino.Mail/Controls/WinoPivotControl.xaml.cs diff --git a/Wino.Mail/Controls/WinoPivotControl.xaml b/Wino.Mail/Controls/WinoPivotControl.xaml deleted file mode 100644 index a524e6d3..00000000 --- a/Wino.Mail/Controls/WinoPivotControl.xaml +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Wino.Mail/Controls/WinoPivotControl.xaml.cs b/Wino.Mail/Controls/WinoPivotControl.xaml.cs deleted file mode 100644 index 975871bc..00000000 --- a/Wino.Mail/Controls/WinoPivotControl.xaml.cs +++ /dev/null @@ -1,195 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Threading.Tasks; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI; -using Windows.UI.Composition; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; -using Wino.Extensions; - -namespace Wino.Controls -{ - // TODO: Memory leak with FolderPivot bindings. - public sealed partial class WinoPivotControl : UserControl - { - private Compositor _compositor; - private ShapeVisual _shapeVisual; - private CompositionSpriteShape _spriteShape; - private CompositionRoundedRectangleGeometry _roundedRectangle; - - public event EventHandler SelectionChanged; - - public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(WinoPivotControl), new PropertyMetadata(null)); - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(WinoPivotControl), new PropertyMetadata(null)); - public static readonly DependencyProperty SelectorPipeColorProperty = DependencyProperty.Register(nameof(SelectorPipeColor), typeof(SolidColorBrush), typeof(WinoPivotControl), new PropertyMetadata(Colors.Transparent, OnSelectorPipeColorChanged)); - public static readonly DependencyProperty DataTemplateProperty = DependencyProperty.Register(nameof(DataTemplate), typeof(DataTemplate), typeof(WinoPivotControl), new PropertyMetadata(null)); - - public DataTemplate DataTemplate - { - get { return (DataTemplate)GetValue(DataTemplateProperty); } - set { SetValue(DataTemplateProperty, value); } - } - - public SolidColorBrush SelectorPipeColor - { - get { return (SolidColorBrush)GetValue(SelectorPipeColorProperty); } - set { SetValue(SelectorPipeColorProperty, value); } - } - - public object SelectedItem - { - get { return (object)GetValue(SelectedItemProperty); } - set { SetValue(SelectedItemProperty, value); } - } - - public object ItemsSource - { - get { return (object)GetValue(ItemsSourceProperty); } - set { SetValue(ItemsSourceProperty, value); } - } - - private static void OnSelectorPipeColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) - { - if (obj is WinoPivotControl control) - { - control.UpdateSelectorPipeColor(); - } - } - - private void UpdateSelectorPipeColor() - { - if (_spriteShape != null && _compositor != null) - { - _spriteShape.FillBrush = _compositor.CreateColorBrush(SelectorPipeColor.Color); - } - } - - private void CreateSelectorVisuals() - { - _compositor = this.Visual().Compositor; - - _roundedRectangle = _compositor.CreateRoundedRectangleGeometry(); - _roundedRectangle.CornerRadius = new Vector2(3, 3); - - _spriteShape = _compositor.CreateSpriteShape(_roundedRectangle); - _spriteShape.CenterPoint = new Vector2(100, 100); - - _shapeVisual = _compositor.CreateShapeVisual(); - - _shapeVisual.Shapes.Clear(); - _shapeVisual.Shapes.Add(_spriteShape); - - SelectorPipe.SetChildVisual(_shapeVisual); - - _shapeVisual.EnableImplicitAnimation(VisualPropertyType.Size, 400); - } - - public WinoPivotControl() - { - this.InitializeComponent(); - - CreateSelectorVisuals(); - } - - private bool IsContainerPresent() - { - return SelectedItem != null && PivotHeaders.ContainerFromItem(SelectedItem) != null; - } - - private void PivotHeaders_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - UpdateVisuals(); - - SelectionChanged?.Invoke(sender, e); - } - - private void UpdateVisuals() - { - MoveSelector(); - } - - private void UpdateSelectorVisibility() - { - SelectorPipe.Visibility = IsContainerPresent() ? Visibility.Visible : Visibility.Collapsed; - } - - private async void MoveSelector() - { - if (PivotHeaders.SelectedItem != null) - { - // Get selected item container position - // TODO: It's bad... - while(PivotHeaders.ContainerFromItem(PivotHeaders.SelectedItem) == null) - { - await Task.Delay(100); - } - - UpdateSelectorVisibility(); - - var container = PivotHeaders.ContainerFromItem(PivotHeaders.SelectedItem) as FrameworkElement; - - if (container != null) - { - var transformToVisual = container.TransformToVisual(this); - Point screenCoords = transformToVisual.TransformPoint(new Point(0, 0)); - - float actualWidth = 0, leftMargin = 0, translateX = 0; - - leftMargin = (float)(screenCoords.X); - - if (PivotHeaders.Items.Count > 1) - { - // Multiple items, pipe is centered. - - actualWidth = (float)(container.ActualWidth + 12) / 2; - translateX = leftMargin - 10 + (actualWidth / 2); - } - else - { - actualWidth = (float)(container.ActualWidth) - 12; - translateX = leftMargin + 4; - } - - SelectorPipe.Width = actualWidth; - SelectorPipe.Translation = new Vector3(translateX, 0, 0); - } - else - { - Debug.WriteLine("Container null"); - } - } - } - - private void SelectorPipeSizeChanged(object sender, SizeChangedEventArgs e) - { - _roundedRectangle.Size = e.NewSize.ToVector2(); - _shapeVisual.Size = e.NewSize.ToVector2(); - } - - private void ControlUnloaded(object sender, RoutedEventArgs e) - { - //PivotHeaders.SelectionChanged -= PivotHeaders_SelectionChanged; - //PivotHeaders.SelectedItem = null; - - //SelectedItem = null; - //ItemsSource = null; - } - - private void ControlLoaded(object sender, RoutedEventArgs e) - { - // Bindings.Update(); - } - } -} diff --git a/Wino.Mail/Views/MailListPage.xaml b/Wino.Mail/Views/MailListPage.xaml index 61328647..cf76ea7e 100644 --- a/Wino.Mail/Views/MailListPage.xaml +++ b/Wino.Mail/Views/MailListPage.xaml @@ -5,7 +5,6 @@ xmlns:abstract="using:Wino.Views.Abstract" xmlns:collections="using:CommunityToolkit.Mvvm.Collections" xmlns:controls="using:Wino.Controls" - xmlns:controls1="using:CommunityToolkit.WinUI.Controls" xmlns:converters="using:Wino.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:domain="using:Wino.Core.Domain" @@ -18,6 +17,7 @@ xmlns:menuflyouts="using:Wino.MenuFlyouts" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:selectors="using:Wino.Selectors" + xmlns:toolkit="using:CommunityToolkit.WinUI.Controls" xmlns:ui="using:Microsoft.Toolkit.Uwp.UI" xmlns:viewModelData="using:Wino.Mail.ViewModels.Data" xmlns:wino="using:Wino" @@ -45,19 +45,6 @@ - - - - - - - - - - + Style="{StaticResource PivotSegmentedStyle}"> + + + + + + + + + + + + + + - 8.1.240821 + + 8.1.240821 + 8.1.240821 @@ -265,9 +268,6 @@ - - WinoPivotControl.xaml - AccountCreationDialog.xaml @@ -456,10 +456,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile