Browse Source

Merge pull request #5024 from AvaloniaUI/fixes/4944-combobox-visualbrush

Fix ComboBox with control items
pull/5056/head
Dan Walmsley 6 years ago
committed by GitHub
parent
commit
1c2d0d5e8b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      src/Avalonia.Controls/ComboBox.cs
  2. 9
      src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs
  3. 12
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  4. 3
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  5. 5
      src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs
  6. 1
      tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

32
src/Avalonia.Controls/ComboBox.cs

@ -173,11 +173,10 @@ namespace Avalonia.Controls
ComboBoxItem.ContentTemplateProperty);
}
/// <inheritdoc/>
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
this.UpdateSelectionBoxItem(this.SelectedItem);
base.OnAttachedToVisualTree(e);
this.UpdateSelectionBoxItem(SelectedItem);
}
/// <inheritdoc/>
@ -373,19 +372,22 @@ namespace Avalonia.Controls
if (control != null)
{
control.Measure(Size.Infinity);
SelectionBoxItem = new Rectangle
if (VisualRoot is object)
{
Width = control.DesiredSize.Width,
Height = control.DesiredSize.Height,
Fill = new VisualBrush
control.Measure(Size.Infinity);
SelectionBoxItem = new Rectangle
{
Visual = control,
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
}
};
Width = control.DesiredSize.Width,
Height = control.DesiredSize.Height,
Fill = new VisualBrush
{
Visual = control,
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
}
};
}
}
else
{

9
src/Avalonia.Visuals/Rendering/SceneGraph/SceneBuilder.cs

@ -24,7 +24,8 @@ namespace Avalonia.Rendering.SceneGraph
using (var impl = new DeferredDrawingContextImpl(this, scene.Layers))
using (var context = new DrawingContext(impl))
{
Update(context, scene, (VisualNode)scene.Root, scene.Root.Visual.Bounds, true);
var clip = new Rect(scene.Root.Visual.Bounds.Size);
Update(context, scene, (VisualNode)scene.Root, clip, true);
}
}
@ -77,7 +78,7 @@ namespace Avalonia.Rendering.SceneGraph
using (var impl = new DeferredDrawingContextImpl(this, scene.Layers))
using (var context = new DrawingContext(impl))
{
var clip = scene.Root.Visual.Bounds;
var clip = new Rect(scene.Root.Visual.Bounds.Size);
if (node.Parent != null)
{
@ -174,7 +175,9 @@ namespace Avalonia.Rendering.SceneGraph
if (visual.IsVisible)
{
var m = Matrix.CreateTranslation(visual.Bounds.Position);
var m = node != scene.Root ?
Matrix.CreateTranslation(visual.Bounds.Position) :
Matrix.Identity;
var renderTransform = Matrix.Identity;

12
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -434,7 +434,7 @@ namespace Avalonia.Skia
/// <inheritdoc />
public IDrawingContextLayerImpl CreateLayer(Size size)
{
return CreateRenderTarget( size);
return CreateRenderTarget(size, true);
}
/// <inheritdoc />
@ -673,7 +673,7 @@ namespace Avalonia.Skia
private void ConfigureTileBrush(ref PaintWrapper paintWrapper, Size targetSize, ITileBrush tileBrush, IDrawableBitmapImpl tileBrushImage)
{
var calc = new TileBrushCalculator(tileBrush, tileBrushImage.PixelSize.ToSizeWithDpi(_dpi), targetSize);
var intermediate = CreateRenderTarget(calc.IntermediateSize);
var intermediate = CreateRenderTarget(calc.IntermediateSize, false);
paintWrapper.AddDisposable(intermediate);
@ -748,7 +748,7 @@ namespace Avalonia.Skia
if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
{
var intermediate = CreateRenderTarget(intermediateSize);
var intermediate = CreateRenderTarget(intermediateSize, false);
using (var ctx = intermediate.CreateDrawingContext(visualBrushRenderer))
{
@ -978,9 +978,10 @@ namespace Avalonia.Skia
/// Create new render target compatible with this drawing context.
/// </summary>
/// <param name="size">The size of the render target in DIPs.</param>
/// <param name="isLayer">Whether the render target is being created for a layer.</param>
/// <param name="format">Pixel format.</param>
/// <returns></returns>
private SurfaceRenderTarget CreateRenderTarget(Size size, PixelFormat? format = null)
private SurfaceRenderTarget CreateRenderTarget(Size size, bool isLayer, PixelFormat? format = null)
{
var pixelSize = PixelSize.FromSizeWithDpi(size, _dpi);
var createInfo = new SurfaceRenderTarget.CreateInfo
@ -992,7 +993,8 @@ namespace Avalonia.Skia
DisableTextLcdRendering = !_canTextUseLcdRendering,
GrContext = _grContext,
Gpu = _gpu,
Session = _session
Session = _session,
DisableManualFbo = !isLayer,
};
return new SurfaceRenderTarget(createInfo);

3
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -124,7 +124,8 @@ namespace Avalonia.Skia
Width = size.Width,
Height = size.Height,
Dpi = dpi,
DisableTextLcdRendering = false
DisableTextLcdRendering = false,
DisableManualFbo = true,
};
return new SurfaceRenderTarget(createInfo);

5
src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs

@ -51,7 +51,8 @@ namespace Avalonia.Skia
_grContext = createInfo.GrContext;
_gpu = createInfo.Gpu;
_surface = _gpu?.TryCreateSurface(PixelSize, createInfo.Session);
if (!createInfo.DisableManualFbo)
_surface = _gpu?.TryCreateSurface(PixelSize, createInfo.Session);
if (_surface == null)
_surface = new SkiaSurfaceWrapper(CreateSurface(createInfo.GrContext, PixelSize.Width, PixelSize.Height,
createInfo.Format));
@ -220,6 +221,8 @@ namespace Avalonia.Skia
public ISkiaGpu Gpu;
public ISkiaGpuRenderSession Session;
public bool DisableManualFbo;
}
}
}

1
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

@ -40,6 +40,7 @@ namespace Avalonia.Controls.UnitTests
Items = items,
SelectedIndex = 0,
};
var root = new TestRoot(target);
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.NotNull(rectangle);

Loading…
Cancel
Save