FFImageLoading.Views.ImageViewAsync.SetFrame C# (CSharp) Method

SetFrame() protected method

protected SetFrame ( int l, int t, int r, int b ) : bool
l int
t int
r int
b int
return bool
		protected override bool SetFrame(int l, int t, int r, int b)
		{
			if (Drawable != null && Drawable.IntrinsicWidth != 0)
			{
				bool bottomAlignmentDefined = AlignMode != AlignMode.None;
				if (ScaleToFit || bottomAlignmentDefined)
				{
					var matrix = this.ImageMatrix;
					float scaleFactor = 1f;

					if (ScaleToFit)
					{
						float scaleFactorWidth = (float)Width / (float)Drawable.IntrinsicWidth;
						float scaleFactorHeight = (float)Height / (float)Drawable.IntrinsicHeight;

						if (scaleFactorHeight < scaleFactorWidth)
						{
							scaleFactor = scaleFactorHeight;
						}
						else
						{
							scaleFactor = scaleFactorWidth;
						}

						if (scaleFactor != 1f)
						{
							matrix.SetScale(scaleFactor, scaleFactor, 0, 0);
						}
					}

					if (AlignMode != AlignMode.None)
					{
						if (AlignMode != AlignMode.TopCenter && Height - (Drawable.IntrinsicHeight * scaleFactor) > 0)
						{
							//align to the bottom
							matrix.PostTranslate(0, Height - (Drawable.IntrinsicHeight * scaleFactor));
						}

						if (Width - (Drawable.IntrinsicWidth * scaleFactor) > 0)
						{
							switch (AlignMode)
							{
								case AlignMode.BottomLeft:
									//by default is aligned to the left
									break;
								case AlignMode.BottomCenter:
									matrix.PostTranslate((Width - (Drawable.IntrinsicWidth * scaleFactor)) / 2, 0);
									break;
								case AlignMode.BottomRight:
									matrix.PostTranslate(Width - (Drawable.IntrinsicWidth * scaleFactor), 0);
									break;
								case AlignMode.TopCenter:
									matrix.PostTranslate((Width - (Drawable.IntrinsicWidth * scaleFactor)) / 2, 0);
									break;
							}
						}


					}

					ImageMatrix = matrix;
				}
			}

			return base.SetFrame(l, t, r, b);
		}
	}