コード例 #1
0
        public static Boolean CheckIfFitWithChordsOnRight(Label label, double fontSize)
        {
            FontCalc lowerFontCalc = new FontCalc(label, fontSize, (App.ScreenWidth * 0.9) * 0.85);

            if (lowerFontCalc.TextHeight > App.ScreenHeight * 0.80)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        public static Boolean CheckIfWrap(Label label, double fontSize)
        {
            FontCalc lowerFontCalc = new FontCalc(label, fontSize, Double.PositiveInfinity);

            if (lowerFontCalc.TextWidth > (App.ScreenWidth * 0.9) * 0.85)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        void OnTextRecive(AsyncClient source, string text)
        {
            if (text != "")
            {
                string[] songTitleAndText = text.Split('|');
                if (songTitleAndText != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Label testLabel = SongTextPresentationView.GetGhostLabelInstance();
                        TitleOfSongWhenConnectedToServer = songTitleAndText[0];
                        TextOfSongWhenConnectedToServer  = songTitleAndText[1];
                        testLabel.Text            = TextOfSongWhenConnectedToServer;
                        testLabel.FontSize        = FontSize;
                        FontCalc checkIfShortText = new FontCalc(testLabel, 25, App.ScreenWidth);
                        if (checkIfShortText.TextHeight < App.ScreenHeight * 0.5)
                        {
                            FontSize = checkIfShortText.FontSize;
                        }
                        else
                        {
                            // Calculate the height of the rendered text.
                            FontCalc lowerFontCalc = new FontCalc(testLabel, 10, App.ScreenWidth);
                            FontCalc upperFontCalc = new FontCalc(testLabel, 100, App.ScreenWidth);

                            while (upperFontCalc.FontSize - lowerFontCalc.FontSize > 1)
                            {
                                // Get the average font size of the upper and lower bounds.
                                double fontSize = (lowerFontCalc.FontSize + upperFontCalc.FontSize) / 2;

                                // Check the new text height against the container height.
                                FontCalc newFontCalc = new FontCalc(testLabel, fontSize, App.ScreenWidth);

                                if (newFontCalc.TextHeight > App.ScreenHeight * 0.85)
                                {
                                    upperFontCalc = newFontCalc;
                                }
                                else
                                {
                                    lowerFontCalc = newFontCalc;
                                }
                            }
                            FontSize = lowerFontCalc.FontSize;
                        }
                    });
                }
            }
        }
コード例 #4
0
        private void OnContentViewSizeChanged(object sender, EventArgs e)
        {
            View view = (View)sender;

            if (view.Width <= 0 || view.Height <= 0)
            {
                return;
            }

            label.Text =
                "This is a paragraph of text displayed with " +
                "a FontSize value of ?? that is empirically " +
                "calculated in a loop within the SizeChanged " +
                "handler of the Label's container. This technique " +
                "can be tricky: You don't want to get into " +
                "an infinite loop by triggering a layout pass " +
                "with every calculation. Does it work?";

            FontCalc lowerFontCalc = new FontCalc(label, 10, view.Width);
            FontCalc upperFontCalc = new FontCalc(label, 100, view.Width);

            while (upperFontCalc.FontSize - lowerFontCalc.FontSize > 1)
            {
                double fontSize = (lowerFontCalc.FontSize + upperFontCalc.FontSize) / 2;

                FontCalc newFontCalc = new FontCalc(label, fontSize, view.Width);

                if (newFontCalc.TextHeight > view.Height)
                {
                    upperFontCalc = newFontCalc;
                }

                else
                {
                    lowerFontCalc = newFontCalc;
                }
            }

            label.FontSize = lowerFontCalc.FontSize;
            label.Text     = label.Text.Replace("??", label.FontSize.ToString("F0"));
        }