Skip to content

Commit f9c1570

Browse files
authored
Fixed incorrect opacity stack handling (#20730)
1 parent bdea1da commit f9c1570

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual/ServerCompositionVisual.Render.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ private bool HandlePreGraphTransformClipOpacity(ServerCompositionVisual visual)
9494

9595
if (visual.Opacity != 1)
9696
{
97-
_opacityStack.Push(effectiveOpacity);
97+
_opacityStack.Push(_opacity);
98+
_opacity = effectiveOpacity;
9899
_canvas.PushOpacity(visual.Opacity, visual._transformedSubTreeBounds.Value.ToRect());
99100
}
100101

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Controls.Shapes;
3+
using Avalonia.Layout;
4+
using Avalonia.Media;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Xunit;
8+
9+
namespace Avalonia.Skia.RenderTests;
10+
11+
public class BugRepros() : TestBase(nameof(BugRepros))
12+
{
13+
[Fact]
14+
public async Task Sibling_Visuals_With_Opacity_Should_Not_Affect_Each_Other()
15+
{
16+
var brushes = new IBrush[]
17+
{
18+
Brushes.Red,
19+
Brushes.Green,
20+
Brushes.Blue,
21+
Brushes.Yellow,
22+
Brushes.Magenta,
23+
Brushes.Cyan,
24+
Brushes.Orange,
25+
Brushes.Purple,
26+
Brushes.Pink,
27+
Brushes.Brown
28+
};
29+
30+
var stackPanel = new StackPanel
31+
{
32+
Orientation = Orientation.Vertical,
33+
Width = 300,
34+
Height = 500,
35+
Background = Brushes.White,
36+
};
37+
38+
for (int i = 0; i < brushes.Length; i++)
39+
{
40+
var border = new Border
41+
{
42+
Width = 280,
43+
Height = 40,
44+
BorderThickness = new Thickness(2),
45+
Margin = new Thickness(5),
46+
Background = brushes[i],
47+
Opacity = 0.3
48+
};
49+
stackPanel.Children.Add(border);
50+
}
51+
52+
await RenderToFile(stackPanel);
53+
CompareImages();
54+
}
55+
}
1.85 KB
Loading

0 commit comments

Comments
 (0)