fix FadeOutTextBlock.cs... though it became kinda ugly code-wise...
MODIFY
WalletWasabi.Fluent/Controls/FadeOutTextBlock.cs
WalletWasabi.Fluent/Controls/FadeOutTextBlock.cs
+using System.Linq;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Data;
+using Avalonia.Layout;
+using Avalonia.LogicalTree;
using Avalonia.Media;
+using Avalonia.Media.TextFormatting;
+using Avalonia.Metadata;
using Avalonia.Styling;
namespace WalletWasabi.Fluent.Controls;
@@ -21,38 +29,127 @@ public class FadeOutTextBlock : TextBlock, IStyleable
GradientStops =
{
new GradientStop {Color = Colors.White, Offset = 0},
- new GradientStop {Color = Colors.White, Offset = 0.7},
- new GradientStop {Color = Colors.Transparent, Offset = 1}
+ new GradientStop {Color = Colors.White, Offset = 0.5},
+ new GradientStop {Color = Colors.Transparent, Offset = 0.8}
}
}.ToImmutable();
+ private TextLayout? _trimmedLayout;
+ private Size _constraint;
+ private bool _cutOff;
+ private TextLayout? _noTrimLayout;
+
public override void Render(DrawingContext context)
{
var background = Background;
+ Rect bounds;
+
if (background != null)
{
- context.FillRectangle(background, new Rect(Bounds.Size));
+ var drawingContext = context;
+ var brush = background;
+ bounds = Bounds;
+ var rect = new Rect(bounds.Size);
+ drawingContext.FillRectangle(brush, rect);
}
- if (TextLayout == null)
+ if (_trimmedLayout is null || _noTrimLayout is null)
{
return;
}
- var textWidth = TextLayout.Size.Width;
- var constraints = Bounds.Deflate(Padding);
- var constraintsWidth = constraints.Width;
- var isConstrained = textWidth >= constraintsWidth;
+ var textAlignment = TextAlignment;
+ bounds = Bounds;
+ var width = bounds.Size.Width;
+ var num1 = 0.0;
+ switch (textAlignment)
+ {
+ case TextAlignment.Center:
+ num1 = (width - _trimmedLayout.Size.Width) / 2.0;
+ break;
+ case TextAlignment.Right:
+ num1 = width - _trimmedLayout.Size.Width;
+ break;
+ }
- if (isConstrained)
+ var padding = Padding;
+ var yPosition = padding.Top;
+ var size = _trimmedLayout.Size;
+ bounds = Bounds;
+ if (bounds.Height < size.Height)
+ {
+ switch (VerticalAlignment)
{
- using var sd = context.PushOpacityMask(FadeoutOpacityMask, constraints);
- TextLayout.Draw(context);
+ case VerticalAlignment.Center:
+ var num2 = yPosition;
+ bounds = Bounds;
+ var num3 = (bounds.Height - size.Height) / 2.0;
+ yPosition = num2 + num3;
+ break;
+ case VerticalAlignment.Bottom:
+ var num4 = yPosition;
+ bounds = Bounds;
+ var num5 = bounds.Height - size.Height;
+ yPosition = num4 + num5;
+ break;
+ }
}
- else
+
+ using var a =
+ context.PushPostTransform(Matrix.CreateTranslation(padding.Left + num1, yPosition));
+ using var b = _cutOff ? context.PushOpacityMask(FadeoutOpacityMask, Bounds) : Disposable.Empty;
+ _noTrimLayout.Draw(context);
+ }
+
+ private void NewCreateTextLayout(Size constraint, string text)
{
- TextLayout.Draw(context);
+ if (constraint == Size.Empty)
+ {
+ _trimmedLayout = null;
}
+
+ var text1 = text ?? string.Empty;
+ var typeface = new Typeface(FontFamily, FontStyle, FontWeight);
+ var fontSize = FontSize;
+ var foreground = Foreground;
+ var textAlignment = (int) TextAlignment;
+ var textWrapping = (int) TextWrapping;
+ var textTrimming = (int) TextTrimming;
+ var textDecorations = TextDecorations;
+ var width = constraint.Width;
+ var height = constraint.Height;
+ var maxLines1 = 1;
+ var lineHeight = LineHeight;
+ var maxLines2 = maxLines1;
+
+ _noTrimLayout = new TextLayout(text1, typeface, fontSize, foreground, (TextAlignment) textAlignment,
+ (TextWrapping) textWrapping, TextTrimming.None, textDecorations, width, height, lineHeight,
+ maxLines2);
+
+ _trimmedLayout = new TextLayout(text1, typeface, fontSize, foreground, (TextAlignment) textAlignment,
+ (TextWrapping) textWrapping, TextTrimming.CharacterEllipsis, textDecorations, width, height, lineHeight,
+ maxLines2);
+
+ _cutOff = (_trimmedLayout.TextLines.Any(x => x.HasCollapsed));
+ }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ if (string.IsNullOrEmpty(Text))
+ {
+ return new Size();
+ }
+
+ var padding = Padding;
+ availableSize = availableSize.Deflate(padding);
+ if (_constraint != availableSize)
+ {
+ _constraint = availableSize;
+ NewCreateTextLayout(_constraint, Text);
+ }
+
+ var textLayout = _trimmedLayout;
+ return (textLayout != null ? textLayout.Size : Size.Empty).Inflate(padding);
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
<Style Selector="c|NavBarItem :is(Panel).NavBarItemPanel DockPanel LayoutTransformControl">
<Setter Property="LayoutTransform" Value="scaleY(1)" />
<Setter Property="Opacity" Value="1" />
- <Setter Property="Margin" Value="10, 0" />
+ <Setter Property="Margin" Value="2, 0" />
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Property="LayoutTransform" Duration="0:0:0.175" />
</Style>
<Style Selector=":is(Panel).NavBarItemPanel DockPanel TextBlock">
- <Setter Property="TextWrapping" Value="NoWrap" />
- <Setter Property="TextTrimming" Value="None" />
- <Setter Property="HorizontalAlignment" Value="Center" />
+ <Setter Property="TextAlignment" Value="Center"></Setter>
+ <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
</Style>
<Style Selector="c|NavBarItem:selected :is(Panel).NavBarItemPanel DockPanel LayoutTransformControl">

fix FadeOutTextBlock.cs... though it became kinda ugly code-wise...