Exemplo n.º 1
0
        private void ApplyAlignment(GUIControl element, Thickness t, double x, double y, double w, double h)
        {
            Rect rect = new Rect(x, y, element.Width, element.Height);

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                rect.X = x + ((w - element.Width) / 2);
                break;

            case HorizontalAlignment.Right:
                rect.X = x + w - element.Width;
                break;

            case HorizontalAlignment.Stretch:
                rect.Width = w;
                break;
            }

            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                rect.Y = y + ((h - element.Height) / 2);
                break;

            case VerticalAlignment.Bottom:
                rect.Y = y + h - element.Height;
                break;

            case VerticalAlignment.Stretch:
                rect.Height = h;
                break;
            }

            element.Arrange(rect);
        }
Exemplo n.º 2
0
        private void ApplyAlignment(GUIControl element, Thickness t, double x, double y, double w, double h)
        {
            Rect rect = new Rect(x, y, element.Width, element.Height);

            switch (element.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                rect.X = x + ((w - element.Width) / 2);
                break;

            case HorizontalAlignment.Right:
                rect.X = x + w - element.Width;
                break;

            case HorizontalAlignment.Stretch:
                rect.Width = w;
                break;
            }

            switch (element.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                rect.Y = y + ((h - element.Height) / 2);
                break;

            case VerticalAlignment.Bottom:
                rect.Y = y + h - element.Height;
                break;

            case VerticalAlignment.Stretch:
                rect.Height = h;
                break;
            }

            if (element is GUILabelControl)
            {
                if (((GUILabelControl)element).TextAlignment == Alignment.ALIGN_RIGHT)
                {
                    rect.X = rect.X + ((GUILabelControl)element).Width;
                }

                /* Wrong drawing in Stack Layout with centered labels
                 * if (((GUILabelControl)element).TextAlignment == Alignment.ALIGN_CENTER)
                 * {
                 * rect.X = rect.X + ((GUILabelControl)element).Width / 2;
                 * }
                 */
            }
            if (element is GUIFadeLabel)
            {
                if (((GUIFadeLabel)element).TextAlignment == Alignment.ALIGN_RIGHT)
                {
                    rect.X = rect.X + ((GUIFadeLabel)element).Width;
                }

                /* Wrong drawing in Stack Layout with centered labels
                 * if (((GUIFadeLabel)element).TextAlignment == Alignment.ALIGN_CENTER)
                 * {
                 * rect.X = rect.X + ((GUIFadeLabel)element).Width / 2;
                 * }
                 */
            }

            element.Arrange(rect);
        }