GravityFlags ExchangeAlignmentFlag(Xamarin.Forms.TextAlignment alignment)
        {
            switch (alignment)
            {
            case Xamarin.Forms.TextAlignment.Start:
                return(GravityFlags.Left);

            case Xamarin.Forms.TextAlignment.Center:
                return(GravityFlags.Center);

            case Xamarin.Forms.TextAlignment.End:
                return(GravityFlags.Right);
            }
            return(GravityFlags.Start);
        }
        internal static VerticalAlignment ToNativeVerticalAlignment(this Xamarin.Forms.TextAlignment alignment)
        {
            switch (alignment)
            {
            case Xamarin.Forms.TextAlignment.Start:
                return(VerticalAlignment.Top);

            case Xamarin.Forms.TextAlignment.Center:
                return(VerticalAlignment.Center);

            case Xamarin.Forms.TextAlignment.End:
                return(VerticalAlignment.Bottom);

            default:
                return(VerticalAlignment.Top);
            }
        }
Пример #3
0
        public static GravityFlags ToAndroidHorizontal(this Xamarin.Forms.TextAlignment formsAlignment)
        {
            switch (formsAlignment)
            {
            case Xamarin.Forms.TextAlignment.Start:
                return(GravityFlags.Left | GravityFlags.CenterVertical);

            case Xamarin.Forms.TextAlignment.Center:
                return(GravityFlags.Center | GravityFlags.CenterVertical);

            case Xamarin.Forms.TextAlignment.End:
                return(GravityFlags.Right | GravityFlags.CenterVertical);

            default:
                return(GravityFlags.Left | GravityFlags.CenterVertical);
            }
        }
Пример #4
0
        public static void UpdateFromFormsControl(this UILabel uiLabel, string text, Xamarin.Forms.TextAlignment textAlignment, Color textColor, Font font)
        {
            uiLabel.Text = text;

            switch (textAlignment)
            {
            case TextAlignment.Start:
                uiLabel.TextAlignment = UITextAlignment.Left;
                break;

            case TextAlignment.Center:
                uiLabel.TextAlignment = UITextAlignment.Center;
                break;

            case TextAlignment.End:
                uiLabel.TextAlignment = UITextAlignment.Right;
                break;
            }

            uiLabel.TextColor = textColor.ToUIColor();
            uiLabel.Font      = font.ToUIFont();
        }
Пример #5
0
        protected override void OnElementChanged(ElementChangedEventArgs <Picker> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Xamarin.Forms.TextAlignment align = ((PickerRender)Element).HorizontalTextAlignment;

                switch (align)
                {
                case Xamarin.Forms.TextAlignment.Center:
                    Control.Gravity = GravityFlags.CenterHorizontal;
                    break;

                case Xamarin.Forms.TextAlignment.Start:
                    Control.Gravity = GravityFlags.Left;
                    break;

                case Xamarin.Forms.TextAlignment.End:
                    Control.Gravity = GravityFlags.Right;
                    break;
                }
            }
        }
        private void UpdateBarTitleAlignment(TextAlignment alignment)
        {
            if (!(TextViewTitle.LayoutParameters is LinearLayout.LayoutParams textViewTitleParams))
            {
                return;
            }
            switch (alignment)
            {
            case Xamarin.Forms.TextAlignment.Start:
                textViewTitleParams.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                textViewTitleParams.Gravity = GravityFlags.Center;
                Toolbar.SetContentInsetsAbsolute(0, Toolbar.ContentInsetStartWithNavigation);
                break;

            case Xamarin.Forms.TextAlignment.End:
                textViewTitleParams.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
                break;
            }

            TextViewTitle.LayoutParameters = textViewTitleParams;
        }
Пример #7
0
        // TODO using Core Text here is going to be a huge problem because we have to
        // change the coordinate system for every call to DrawString rather than changing
        // it once for all the calls.  Not even sure we have enough info (the height of
        // the coord system or UIView) to do the transform?

        // TODO if we know the text is one-line, we can skip the big transform and just use
        // the textmatrix thing.

        public void DrawString(string s,
                               float box_x,
                               float box_y,
                               float box_width,
                               float box_height,
                               Xamarin.Forms.LineBreakMode lineBreak,
                               Xamarin.Forms.TextAlignment horizontal_align,
                               Xamarin.Forms.TextAlignment vertical_align
                               )
        {
            _c.SaveState();
            // TODO _c.SetTextDrawingMode (CGTextDrawingMode.Fill);

            // Core Text uses a different coordinate system.

            _c.TranslateCTM(0, _overall_height);
            _c.ScaleCTM(1, -1);

            var attributedString = new NSAttributedString(s, _ct_attr);

            float text_width;
            float text_height;

            if (
                (horizontal_align != TextAlignment.Start) ||
                (vertical_align != TextAlignment.Start))
            {
                // not all of the alignments need the bounding rect.  don't
                // calculate it if not needed.

                var sizeAttr = attributedString.GetBoundingRect(
                    new SizeF(
                        (float)box_width,
                        int.MaxValue),
                    NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading,
                    null
                    );

                text_width = sizeAttr.Width;
                //text_height = sizeAttr.Height;
                //text_height = sizeAttr.Height + uif.Descender; // descender is negative
                text_height = _font_ui.CapHeight;
            }
            else
            {
                text_width  = 0;
                text_height = 0;
            }

            //Console.WriteLine ("width: {0}    height: {1}", text_width, text_height);

            float x;

            switch (horizontal_align)
            {
            case Xamarin.Forms.TextAlignment.End:
                x = (box_x + box_width) - text_width;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                x = box_x + (box_width - text_width) / 2;
                break;

            case Xamarin.Forms.TextAlignment.Start:
            default:
                x = box_x;
                break;
            }

            float y;

            switch (vertical_align)
            {
            case Xamarin.Forms.TextAlignment.End:
                y = box_y + text_height;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                y = (box_y + box_height) - (box_height - text_height) / 2;
                break;

            case Xamarin.Forms.TextAlignment.Start:
            default:
                y = (box_y + box_height);
                break;
            }

            _c.TextPosition = new PointF((float)x, (float)(_overall_height - y));

            // I think that by using CTLine() below, we are preventing multi-line text.  :-(

            using (var textLine = new CTLine(attributedString)) {
                textLine.Draw(_c);
            }

            //gctx.StrokeRect (new RectangleF(x, height - y, text_width, text_height));

            _c.RestoreState();
        }
Пример #8
0
        public void DrawString(string s,
                               float box_x,
                               float box_y,
                               float box_width,
                               float box_height,
                               Xamarin.Forms.LineBreakMode lineBreak,
                               Xamarin.Forms.TextAlignment horizontal_align,
                               Xamarin.Forms.TextAlignment vertical_align
                               )
        {
            // TODO
            if (string.IsNullOrWhiteSpace(s))
            {
                return;
            }

            //SetTextAlign()

            float text_width;
            float text_height;

            if (
                (horizontal_align != TextAlignment.Start) ||
                (vertical_align != TextAlignment.Start))
            {
                // not all of the alignments need the bounding rect.  don't
                // calculate it if not needed.

                text_width = _paints.Text.MeasureText(s);

                text_height = -(TextFontMetrics.Ascent);
            }
            else
            {
                text_width  = 0;
                text_height = 0;
            }

            //Console.WriteLine ("width: {0}    height: {1}", text_width, text_height);

            float x;

            switch (horizontal_align)
            {
            case Xamarin.Forms.TextAlignment.End:
                x = (box_x + box_width) - text_width;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                x = box_x + (box_width - text_width) / 2;
                break;

            case Xamarin.Forms.TextAlignment.Start:
            default:
                x = box_x;
                break;
            }

            float y;

            switch (vertical_align)
            {
            case Xamarin.Forms.TextAlignment.End:
                y = box_y + text_height;
                break;

            case Xamarin.Forms.TextAlignment.Center:
                y = (box_y + box_height) - (box_height - text_height) / 2;
                break;

            case Xamarin.Forms.TextAlignment.Start:
            default:
                y = (box_y + box_height);
                break;
            }

            _c.DrawText(s, x, y, _paints.Text);
        }