Browse Source

improve algorithm and typo fixes

pull/7810/head
daniel mayost 5 years ago
parent
commit
0f5e78d70f
  1. 2
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 38
      src/Avalonia.Controls/Control.cs
  3. 2
      src/Avalonia.Controls/Image.cs
  4. 2
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  5. 2
      src/Avalonia.Controls/TextBlock.cs
  6. 2
      src/Avalonia.Controls/TopLevel.cs

2
samples/ControlCatalog/Pages/ScreenPage.cs

@ -79,6 +79,6 @@ namespace ControlCatalog.Pages
Typeface.Default, 12, Brushes.Green); Typeface.Default, 12, Brushes.Green);
} }
protected override bool ShouldGetInvertedIfRightToLeft() => false; protected override bool ShouldApplyMirrorTransform() => false;
} }
} }

38
src/Avalonia.Controls/Control.cs

@ -141,7 +141,7 @@ namespace Avalonia.Controls
{ {
if (_hasMirrorTransform) if (_hasMirrorTransform)
{ {
value = MargeTransforms(MirrorTrasform(), value); value = MergeTransforms(MirrorTrasform(), value);
} }
base.RenderTransform = value; base.RenderTransform = value;
@ -357,23 +357,16 @@ namespace Avalonia.Controls
private void InvalidateFlowDirection() private void InvalidateFlowDirection()
{ {
FlowDirection parentFD = FlowDirection.LeftToRight; bool parentShouldGetMirrored = false;
FlowDirection thisFD = FlowDirection; bool thisShouldGetMirrored = ShouldPresentedMirrored();
bool parentShouldGetMirrored = true;
bool thisShouldGetMirrored = ShouldGetInvertedIfRightToLeft();
var parent = this.FindAncestorOfType<Control>(); var parent = this.FindAncestorOfType<Control>();
if (parent != null) if (parent != null)
{ {
parentFD = parent.FlowDirection; parentShouldGetMirrored = parent.ShouldPresentedMirrored();
parentShouldGetMirrored = parent.ShouldGetInvertedIfRightToLeft();
} }
bool shouldBeMirrored = thisFD == FlowDirection.RightToLeft && thisShouldGetMirrored; bool shouldApplyMirrorTransform = thisShouldGetMirrored != parentShouldGetMirrored;
bool parentMirrored = parentFD == FlowDirection.RightToLeft && parentShouldGetMirrored;
bool shouldApplyMirrorTransform = shouldBeMirrored != parentMirrored;
if (shouldApplyMirrorTransform) if (shouldApplyMirrorTransform)
{ {
@ -404,12 +397,12 @@ namespace Avalonia.Controls
} }
var mirrorTransform = MirrorTrasform(); var mirrorTransform = MirrorTrasform();
var rendertransform = RenderTransform; var renderTransform = RenderTransform;
ITransform? finalTransform = mirrorTransform; ITransform? finalTransform = mirrorTransform;
if (rendertransform != null) if (renderTransform != null)
{ {
finalTransform = MargeTransforms(rendertransform, mirrorTransform); finalTransform = MergeTransforms(renderTransform, mirrorTransform);
} }
base.RenderTransform = finalTransform; base.RenderTransform = finalTransform;
@ -424,9 +417,9 @@ namespace Avalonia.Controls
} }
var mirrorTransform = MirrorTrasform(); var mirrorTransform = MirrorTrasform();
var rendertransform = RenderTransform; var renderTransform = RenderTransform;
ITransform? finalTransform = MargeTransforms(rendertransform, mirrorTransform); ITransform? finalTransform = MergeTransforms(renderTransform, mirrorTransform);
if (finalTransform!.Value == Matrix.Identity) if (finalTransform!.Value == Matrix.Identity)
{ {
finalTransform = null; finalTransform = null;
@ -438,12 +431,15 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Determines whether the element should be inverted if the /// Determines whether the element should be presented mirrored
/// flow direction is RightToLeft /// by FlowDirection system
/// </summary> /// </summary>
protected virtual bool ShouldGetInvertedIfRightToLeft() => true; protected virtual bool ShouldPresentedMirrored()
{
return FlowDirection == FlowDirection.RightToLeft;
}
static ITransform? MargeTransforms(ITransform? iTransform1, ITransform? iTransform2) static ITransform? MergeTransforms(ITransform? iTransform1, ITransform? iTransform2)
{ {
// don't know how to marge ITransform // don't know how to marge ITransform
if (iTransform1 is Transform transform1 && iTransform2 is Transform transform2) if (iTransform1 is Transform transform1 && iTransform2 is Transform transform2)

2
src/Avalonia.Controls/Image.cs

@ -128,6 +128,6 @@ namespace Avalonia.Controls
} }
} }
protected override bool ShouldGetInvertedIfRightToLeft() => false; protected override bool ShouldApplyMirrorTransform() => false;
} }
} }

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

@ -799,6 +799,6 @@ namespace Avalonia.Controls.Presenters
} }
} }
protected override bool ShouldGetInvertedIfRightToLeft() => false; protected override bool ShouldApplyMirrorTransform() => false;
} }
} }

2
src/Avalonia.Controls/TextBlock.cs

@ -613,6 +613,6 @@ namespace Avalonia.Controls
InvalidateTextLayout(); InvalidateTextLayout();
} }
protected override bool ShouldGetInvertedIfRightToLeft() => false; protected override bool ShouldApplyMirrorTransform() => false;
} }
} }

2
src/Avalonia.Controls/TopLevel.cs

@ -530,6 +530,6 @@ namespace Avalonia.Controls
ITextInputMethodImpl? ITextInputMethodRoot.InputMethod => ITextInputMethodImpl? ITextInputMethodRoot.InputMethod =>
(PlatformImpl as ITopLevelImplWithTextInputMethod)?.TextInputMethod; (PlatformImpl as ITopLevelImplWithTextInputMethod)?.TextInputMethod;
protected override bool ShouldGetInvertedIfRightToLeft() => false; protected override bool ShouldApplyMirrorTransform() => false;
} }
} }

Loading…
Cancel
Save