Browse Source

Sync BackgroundSizing in composition border visuals

pull/20647/head
Wiesław Šoltés 1 month ago
parent
commit
eca20327a6
  1. 5
      src/Avalonia.Controls/Border.cs
  2. 22
      src/Avalonia.Controls/BorderVisual.cs
  3. 5
      src/Avalonia.Controls/Presenters/ContentPresenter.cs

5
src/Avalonia.Controls/Border.cs

@ -81,6 +81,10 @@ namespace Avalonia.Controls
case nameof(BorderThickness):
_layoutThickness = null;
break;
case nameof(BackgroundSizing):
if (_borderVisual != null)
_borderVisual.BackgroundSizing = BackgroundSizing;
break;
case nameof(CornerRadius):
if (_borderVisual != null)
_borderVisual.CornerRadius = CornerRadius;
@ -215,6 +219,7 @@ namespace Avalonia.Controls
{
return _borderVisual = new CompositionBorderVisual(compositor, this)
{
BackgroundSizing = BackgroundSizing,
CornerRadius = CornerRadius
};
}

22
src/Avalonia.Controls/BorderVisual.cs

@ -15,6 +15,8 @@ class CompositionBorderVisual : CompositionDrawListVisual
private bool _cornerRadiusChanged;
private Thickness _borderThickness;
private bool _borderThicknessChanged;
private BackgroundSizing _backgroundSizing;
private bool _backgroundSizingChanged;
public CompositionBorderVisual(Compositor compositor, Visual visual) : base(compositor,
new ServerBorderVisual(compositor.Server, visual), visual)
@ -49,6 +51,20 @@ class CompositionBorderVisual : CompositionDrawListVisual
}
}
public BackgroundSizing BackgroundSizing
{
get => _backgroundSizing;
set
{
if (_backgroundSizing != value)
{
_backgroundSizingChanged = true;
_backgroundSizing = value;
RegisterForSerialization();
}
}
}
private protected override void SerializeChangesCore(BatchStreamWriter writer)
{
base.SerializeChangesCore(writer);
@ -58,12 +74,16 @@ class CompositionBorderVisual : CompositionDrawListVisual
writer.Write(_borderThicknessChanged);
if (_borderThicknessChanged)
writer.Write(_borderThickness);
writer.Write(_backgroundSizingChanged);
if (_backgroundSizingChanged)
writer.Write(_backgroundSizing);
}
class ServerBorderVisual : ServerCompositionDrawListVisual
{
private CornerRadius _cornerRadius;
private Thickness _borderThickness;
private BackgroundSizing _backgroundSizing;
public ServerBorderVisual(ServerCompositor compositor, Visual v) : base(compositor, v)
{
}
@ -79,6 +99,8 @@ class CompositionBorderVisual : CompositionDrawListVisual
_cornerRadius = reader.Read<CornerRadius>();
if (reader.Read<bool>())
_borderThickness = reader.Read<Thickness>();
if (reader.Read<bool>())
_backgroundSizing = reader.Read<BackgroundSizing>();
}

5
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@ -447,6 +447,10 @@ namespace Avalonia.Controls.Presenters
case nameof(BorderThickness):
_layoutThickness = null;
break;
case nameof(BackgroundSizing):
if (_borderVisual != null)
_borderVisual.BackgroundSizing = BackgroundSizing;
break;
case nameof(CornerRadius):
if (_borderVisual != null)
_borderVisual.CornerRadius = CornerRadius;
@ -587,6 +591,7 @@ namespace Avalonia.Controls.Presenters
{
return _borderVisual = new CompositionBorderVisual(compositor, this)
{
BackgroundSizing = BackgroundSizing,
CornerRadius = CornerRadius
};
}

Loading…
Cancel
Save