Fix clipping by emulating it :)
MODIFY
WalletWasabi.Fluent/Behaviors/NavBarSelectedIndicatorChildBehavior.cs
WalletWasabi.Fluent/Behaviors/NavBarSelectedIndicatorChildBehavior.cs
@@ -3,6 +3,7 @@ using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
+using Avalonia.Threading;
using WalletWasabi.Logging;
namespace WalletWasabi.Fluent.Behaviors;
@@ -69,9 +70,12 @@ public class NavBarSelectedIndicatorChildBehavior : AttachedToVisualTreeBehavior
return;
}
+ Dispatcher.UIThread.Post(() =>
+ {
if (parent.Classes.Contains(":selected"))
{
GetSharedState.PreviousIndicator = AssociatedObject;
+ GetSharedState.AdornerControl.InitialFix(AssociatedObject);
}
AssociatedObject.GetPropertyChangedObservable(IsSelectedProperty)
@@ -80,12 +84,14 @@ public class NavBarSelectedIndicatorChildBehavior : AttachedToVisualTreeBehavior
{
var parent = GetNavBarItemParent(AssociatedObject);
- if ((bool)x.NewValue && (GetNavBarItemParent(AssociatedObject)?.Classes.Contains(":selected") ?? false))
+ if ((bool)x.NewValue &&
+ (GetNavBarItemParent(AssociatedObject)?.Classes.Contains(":selected") ?? false))
{
GetSharedState.Animate(AssociatedObject);
}
});
AssociatedObject.Opacity = 0;
+ }, DispatcherPriority.Loaded);
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Behaviors/NavBarSelectedIndicatorState.cs
WalletWasabi.Fluent/Behaviors/NavBarSelectedIndicatorState.cs
@@ -48,11 +48,8 @@ public class NavBarSelectedIndicatorState : IDisposable
var root = PreviousIndicator.GetVisualAncestors().OfType<VisualLayerManager>().FirstOrDefault();
- var prevVector = PreviousIndicator.TranslatePoint(new Point(), root) ?? new Point();
- var nextVector = NextIndicator.TranslatePoint(new Point(), root) ?? new Point();
-
_currentAnimationCts?.Cancel();
- AdornerControl.AnimateIndicators(PreviousIndicator, prevVector, NextIndicator, nextVector,
+ AdornerControl.AnimateIndicators(PreviousIndicator, NextIndicator,
_currentAnimationCts.Token, NavItemsOrientation);
_currentAnimationCts = new();

MODIFY
WalletWasabi.Fluent/Behaviors/NavBarSelectionIndicatorAdorner.cs
WalletWasabi.Fluent/Behaviors/NavBarSelectionIndicatorAdorner.cs
using System;
+using System.Linq;
+using System.Reactive.Disposables;
using System.Threading;
using Avalonia;
using Avalonia.Animation;
@@ -9,18 +11,21 @@ using Avalonia.Controls.Shapes;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
+using Avalonia.VisualTree;
+using ReactiveUI;
+using WalletWasabi.Helpers.PowerSaving;
namespace WalletWasabi.Fluent.Behaviors;
-public class NavBarSelectionIndicatorAdorner : Control, IDisposable
+public class NavBarSelectionIndicatorAdorner : Canvas, IDisposable
{
- private readonly AdornerLayer _layer;
+ private CompositeDisposable disposables = new();
+ private readonly Canvas _layer;
private readonly Control _target;
private readonly NavBarSelectedIndicatorState _sharedState;
private bool _isDispose;
private Rectangle newRect = new Rectangle();
-
public NavBarSelectionIndicatorAdorner(Control element, NavBarSelectedIndicatorState sharedState)
{
_target = element;
@@ -28,73 +33,72 @@ public class NavBarSelectionIndicatorAdorner : Control, IDisposable
_layer = AdornerLayer.GetAdornerLayer(_target);
IsHitTestVisible = false;
- IsVisible = false;
if (_layer is null)
{
return;
}
+ var root = _target.GetVisualRoot();
+
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Loaded);
_sharedState.AdornerControl = this;
+
_layer.Children.Add(this);
- _layer.Children.Add(newRect);
+ Children.Add(newRect);
newRect.VerticalAlignment = VerticalAlignment.Top;
newRect.HorizontalAlignment = HorizontalAlignment.Left;
+ VerticalAlignment = VerticalAlignment.Top;
+ HorizontalAlignment = HorizontalAlignment.Left;
- if (Application.Current.Styles.TryGetResource("FluentEasing", out object? resource) &&
- resource is Easing outEasing)
- {
- newRect.Transitions = new Transitions()
+ _target.WhenAnyValue(x => x.Bounds)
+ .Subscribe(x =>
{
- new ThicknessTransition()
- {
- Property = Rectangle.MarginProperty,
- Duration = TimeSpan.FromSeconds(0.30),
- Easing = outEasing
- }
- };
+ var prevVector = _target.TranslatePoint(new Point(), VisualRoot) ?? new Point();
+ Width = x.Width;
+ Height = x.Height;
+ Margin = new Thickness(prevVector.X, prevVector.Y, 0, 0);
+ })
+ .DisposeWith(disposables);
+
+ ClipToBounds = true;
+ Background = new SolidColorBrush(new Color(100, 100, 0, 0));
}
- }
-
-#if DEBUG
- public override void Render(DrawingContext context)
- {
- Rect adornedElementRect = _target.Bounds;
-
- var renderBrush = new SolidColorBrush(Colors.Green)
- {
- Opacity = 0.2
- };
- var renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
- var renderRadius = 5.0;
-
- context.DrawRectangle(renderBrush, renderPen, adornedElementRect);
- }
+ private Rect bounds;
-#endif
public void Dispose()
{
_isDispose = true;
_layer?.Children.Remove(this);
- _layer?.Children.Remove(newRect);
}
- public void AnimateIndicators(Rectangle previousIndicator, Point prevVector, Rectangle nextIndicator,
- Point nextVector, CancellationToken token, Orientation navItemsOrientation)
+ public void AnimateIndicators(Rectangle previousIndicator, Rectangle nextIndicator, CancellationToken token,
+ Orientation navItemsOrientation)
{
if (_isDispose)
{
return;
}
+ var nextVector = nextIndicator.TranslatePoint(new Point(), this) ?? new Point();
newRect.Width = previousIndicator.Bounds.Width;
newRect.Height = previousIndicator.Bounds.Height;
newRect.Fill = previousIndicator.Fill;
- newRect.Margin = new Thickness(nextVector.X, nextVector.Y, 0, 0);
+ Canvas.SetLeft(newRect, nextVector.X);
+ Canvas.SetTop(newRect, nextVector.Y);
+ }
+
+ public void InitialFix(Rectangle initial)
+ {
+ var prevVector = initial.TranslatePoint(new Point(), this) ?? new Point();
+ newRect.Width = initial.Bounds.Width;
+ newRect.Height = initial.Bounds.Height;
+ newRect.Fill = initial.Fill;
+ Canvas.SetLeft(newRect, prevVector.X);
+ Canvas.SetTop(newRect, prevVector.Y);
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
</StackPanel>
<!-- Items List -->
<DockPanel Background="Transparent">
- <i:Interaction.Behaviors>
- <behaviors:NavBarSelectedIndicatorParentBehavior/>
- </i:Interaction.Behaviors>
<TextBlock Classes="headerText" DockPanel.Dock="Top" Text="Wallets" IsVisible="{Binding IsOpen}" />
<c:NavBarListBox Items="{Binding Wallets}"
RenderTransformOrigin="0%,50%"
VerticalAlignment="Stretch">
+ <i:Interaction.Behaviors>
+ <behaviors:NavBarSelectedIndicatorParentBehavior/>
+ </i:Interaction.Behaviors>
+
<c:NavBarListBox.DataTemplates>
<DataTemplate DataType="vmw:WalletViewModelBase">

Fix clipping by emulating it :)