예제 #1
0
        public override Vector2 GetPreferredSize(NVGcontext ctx)
        {
            if (string.IsNullOrEmpty(caption))
            {
                return(Vector2.Zero);
            }

            Vector2 ret          = Vector2.Zero;
            int     prefFontSize = GetPreferredFontSize();

            NanoVG.nvgFontFace(ctx, font);
            NanoVG.nvgFontSize(ctx, prefFontSize);

            int fixedWidth = (int)this.fixedSize.X;

            if (0 < fixedWidth)
            {
                Vector2 pos = this.localPosition;
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgTextBoxBounds(ctx, pos.X, pos.Y, fixedWidth, caption, m_Bounds);

                ret.X = fixedWidth;
                ret.Y = (m_Bounds[3] - m_Bounds[1]);
            }
            else
            {
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));
                ret.X = NanoVG.nvgTextBounds(ctx, 0, 0, caption, m_Bounds);
                ret.Y = prefFontSize;
            }
            return(ret);
        }