Browse Source

naming more like wpf

pull/7810/head
daniel mayost 5 years ago
parent
commit
61ffbcc687
  1. 4
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 16
      src/Avalonia.Controls/ComboBox.cs
  3. 42
      src/Avalonia.Controls/Control.cs
  4. 4
      src/Avalonia.Controls/Image.cs
  5. 4
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  6. 4
      src/Avalonia.Controls/TextBlock.cs
  7. 12
      src/Avalonia.Controls/TopLevel.cs

4
samples/ControlCatalog/Pages/ScreenPage.cs

@ -13,6 +13,8 @@ namespace ControlCatalog.Pages
{
private double _leftMost;
protected override bool BypassFlowDirectionPolicies => true;
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
@ -78,7 +80,5 @@ namespace ControlCatalog.Pages
return new FormattedText(textToFormat, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
Typeface.Default, 12, Brushes.Green);
}
protected override bool ShouldPresentMirrored() => false;
}
}

16
src/Avalonia.Controls/ComboBox.cs

@ -183,12 +183,24 @@ namespace Avalonia.Controls
this.UpdateSelectionBoxItem(SelectedItem);
}
// Because the SelectedItem isn't connected to the visual tree
// Because the SelectedItem and his children sometimes isn't connected
// to the visual tree and sometimes not to logical tree
public override void InvalidateFlowDirection()
{
base.InvalidateFlowDirection();
if (SelectedItem is Control selectedControl)
{
selectedControl.InvalidateFlowDirection();
foreach (var visual in selectedControl.GetVisualDescendants())
{
if (visual is Control childControl)
{
childControl.InvalidateFlowDirection();
}
}
foreach (var logical in selectedControl.GetLogicalDescendants())
{
if (logical is Control childControl)
@ -197,8 +209,6 @@ namespace Avalonia.Controls
}
}
}
base.InvalidateFlowDirection();
}
/// <inheritdoc/>

42
src/Avalonia.Controls/Control.cs

@ -140,6 +140,17 @@ namespace Avalonia.Controls
/// <inheritdoc/>
bool IDataTemplateHost.IsDataTemplatesInitialized => _dataTemplates != null;
/// <summary>
/// Gets a value indicating whether control bypass FlowDirecton policies.
/// </summary>
/// <remarks>
/// Related to FlowDirection system and returns false as default, so if
/// <see cref="FlowDirection"/> is RTL then control will get a mirror presentation.
/// For controls that want to avoid mirror presentation, it is possible to override
/// this property and return true.
/// </remarks>
protected virtual bool BypassFlowDirectionPolicies => false;
/// <inheritdoc/>
void ISetterValue.Initialize(ISetter setter)
{
@ -338,37 +349,34 @@ namespace Avalonia.Controls
/// <summary>
/// Computes the <see cref="IVisual.IsMirrorTransform"/> value according to the
/// <see cref="FlowDirection"/>
/// <see cref="FlowDirection"/> and <see cref="BypassFlowDirectionPolicies"/>
/// </summary>
public virtual void InvalidateFlowDirection()
{
bool parentShouldPresentMirrored = false;
bool thisShouldPresentMirrored = ShouldPresentMirrored();
FlowDirection thisFD = this.FlowDirection;
FlowDirection parentFD = FlowDirection.LeftToRight;
bool thisBypassFlowDirectionPolicies = BypassFlowDirectionPolicies;
bool parentBypassFlowDirectionPolicies = false;
var parent = this.FindAncestorOfType<Control>();
if (parent != null)
{
parentShouldPresentMirrored = parent.ShouldPresentMirrored();
parentFD = parent.FlowDirection;
parentBypassFlowDirectionPolicies = parent.BypassFlowDirectionPolicies;
}
else if (this.Parent is Control logicalParent)
{
parentShouldPresentMirrored = logicalParent.ShouldPresentMirrored();
parentFD = logicalParent.FlowDirection;
parentBypassFlowDirectionPolicies = logicalParent.BypassFlowDirectionPolicies;
}
bool shouldApplyMirrorTransform = thisShouldPresentMirrored != parentShouldPresentMirrored;
bool thisShouldBeMirrored = thisFD == FlowDirection.RightToLeft && !BypassFlowDirectionPolicies;
bool parentShouldBeMirrored = parentFD == FlowDirection.RightToLeft && !parentBypassFlowDirectionPolicies;
IsMirrorTransform = shouldApplyMirrorTransform;
}
bool shouldApplyMirrorTransform = thisShouldBeMirrored != parentShouldBeMirrored;
/// <summary>
/// Determines whether the element should be present mirrored, this
/// method related to FlowDirection system and returns true if FlowDirection
/// is RightToLeft. For controls that want to avoid this behavior, it is
/// possible to override this method and return false.
/// </summary>
protected virtual bool ShouldPresentMirrored()
{
return FlowDirection == FlowDirection.RightToLeft;
IsMirrorTransform = shouldApplyMirrorTransform;
}
}
}

4
src/Avalonia.Controls/Image.cs

@ -66,6 +66,8 @@ namespace Avalonia.Controls
set { SetValue(StretchDirectionProperty, value); }
}
protected override bool BypassFlowDirectionPolicies => true;
/// <summary>
/// Renders the control.
/// </summary>
@ -127,7 +129,5 @@ namespace Avalonia.Controls
return new Size();
}
}
protected override bool ShouldPresentMirrored() => false;
}
}

4
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -281,6 +281,8 @@ namespace Avalonia.Controls.Presenters
}
}
protected override bool BypassFlowDirectionPolicies => true;
/// <summary>
/// Creates the <see cref="TextLayout"/> used to render the text.
/// </summary>
@ -798,7 +800,5 @@ namespace Avalonia.Controls.Presenters
}
}
}
protected override bool ShouldPresentMirrored() => false;
}
}

4
src/Avalonia.Controls/TextBlock.cs

@ -329,6 +329,8 @@ namespace Avalonia.Controls
set => SetValue(TextDecorationsProperty, value);
}
protected override bool BypassFlowDirectionPolicies => true;
/// <summary>
/// Gets the value of the attached <see cref="FontFamilyProperty"/> on a control.
/// </summary>
@ -612,7 +614,5 @@ namespace Avalonia.Controls
{
InvalidateTextLayout();
}
protected override bool ShouldPresentMirrored() => false;
}
}

12
src/Avalonia.Controls/TopLevel.cs

@ -348,6 +348,12 @@ namespace Avalonia.Controls
/// </summary>
protected virtual ILayoutManager CreateLayoutManager() => new LayoutManager(this);
public override void InvalidateFlowDirection()
{
}
protected override bool BypassFlowDirectionPolicies => true;
/// <summary>
/// Handles a paint notification from <see cref="ITopLevelImpl.Resized"/>.
/// </summary>
@ -529,11 +535,5 @@ namespace Avalonia.Controls
ITextInputMethodImpl? ITextInputMethodRoot.InputMethod =>
(PlatformImpl as ITopLevelImplWithTextInputMethod)?.TextInputMethod;
public override void InvalidateFlowDirection()
{
}
protected override bool ShouldPresentMirrored() => false;
}
}

Loading…
Cancel
Save