Пример #1
0
        void CalculateSize()
        {
            if (isCalculatingSize)
            {
                return;
            }

            isCalculatingSize = true;

            switch (fitting)
            {
            case FittingMode.SizerOnly:

                base.resizeTextForBestFit = false;
                base.fontSize             = Mathf.RoundToInt(FontSizer.CalculateSize());
                break;

            case FittingMode.StayInBounds:

                base.resizeTextMinSize    = Mathf.RoundToInt(FontSizer.MinSize);
                base.resizeTextMaxSize    = Mathf.RoundToInt(FontSizer.MaxSize);
                base.resizeTextForBestFit = true;
                int size = Mathf.RoundToInt(FontSizer.CalculateSize());

                base.fontSize = size;
                base.Rebuild(CanvasUpdate.PreRender);

                int bestFit = base.cachedTextGenerator.fontSizeUsedForBestFit;
                base.resizeTextForBestFit = false;

                fontSize = (bestFit < size) ? bestFit : size;
                FontSizer.OverrideLastCalculatedSize(base.fontSize);

                break;

            case FittingMode.BestFit:

                base.resizeTextMinSize    = Mathf.RoundToInt(FontSizer.MinSize);
                base.resizeTextMaxSize    = Mathf.RoundToInt(FontSizer.MaxSize);
                base.resizeTextForBestFit = true;

                base.Rebuild(CanvasUpdate.PreRender);

                FontSizer.OverrideLastCalculatedSize(base.cachedTextGenerator.fontSizeUsedForBestFit);
                break;

            default:
                break;
            }

            isCalculatingSize = false;
        }
        void OnStackSizeChanged(object sender, EventArgs args)
        {
            // set frames to fill 1/4 of stack height
            double frameHeight = pageStack.Height / 4;

            frame1.HeightRequest = frameHeight;
            frame2.HeightRequest = frameHeight;
            frame3.HeightRequest = frameHeight;
            frame4.HeightRequest = frameHeight;

            // for storing the size results to be passed on to the labels
            double sizingResult;

            // sizing labelOne
            ghostLabel.Text = String.Copy(label1.Text);

            sizingResult = FontSizer.CalculateMaxFontSize(ghostLabel, 10, 100,
                                                          pageStack.Width, pageStack.Height / 4);

            label1.FontSize = sizingResult;

            // sizing labelTwo
            ghostLabel.Text = String.Copy(label2.Text);

            sizingResult = FontSizer.CalculateMaxFontSize(ghostLabel, 10, 100,
                                                          pageStack.Width, pageStack.Height / 4);

            label2.FontSize = sizingResult;

            // sizing labelThree
            ghostLabel.Text = String.Copy(label3.Text);

            sizingResult = FontSizer.CalculateMaxFontSize(ghostLabel, 10, 100,
                                                          pageStack.Width, pageStack.Height / 4);

            label3.FontSize = sizingResult;

            // sizing labelFour
            ghostLabel.Text = String.Copy(label4.Text);

            sizingResult = FontSizer.CalculateMaxFontSize(ghostLabel, 10, 100,
                                                          pageStack.Width, pageStack.Height / 4);

            label4.FontSize = sizingResult;
        }