Beispiel #1
0
        private LayoutScore ComputeScore(Size desiredSize, Size availableSize, string originalText, string formattedText)
        {
            if ((originalText == "" || originalText == null) && !this.ScoreIfEmpty)
            {
                return(LayoutScore.Zero);
            }
            bool cropped      = (desiredSize.Width > availableSize.Width || desiredSize.Height > availableSize.Height);
            int  numLineWraps = this.countLinewraps(formattedText);

            if (cropped)
            {
                if (this.ScoreIfCropped)
                {
                    double desiredArea   = desiredSize.Width * desiredSize.Height;
                    double availableArea = availableSize.Width * availableSize.Height;
                    return(this.BonusScore.Times(availableArea / desiredArea)
                           .Plus(LayoutScore.Get_CutOff_LayoutScore(1))
                           .Plus(LayoutScore.Get_UnCentered_LayoutScore(numLineWraps)));
                }
                else
                {
                    return(LayoutScore.Get_CutOff_LayoutScore(1));
                }
            }
            return(new LayoutScore(this.BonusScore).Plus(LayoutScore.Get_UnCentered_LayoutScore(numLineWraps)));
        }
        private LayoutChoice_Set build()
        {
            GridLayout_Builder mainBuilder = new Vertical_GridLayout_Builder().Uniform();

            this.buttons            = new List <Button>();
            this.subtitles          = new List <TextblockLayout>();
            this.buttonDestinations = new Dictionary <Button, ValueProvider <StackEntry> >();
            for (int i = 0; i < this.buttonNameProviders.Count; i++)
            {
                Button button = new Button();
                button.Clicked += Button_Clicked;
                this.buttons.Add(button);

                ButtonLayout    buttonLayout   = new ButtonLayout(button);
                TextblockLayout subtitleLayout = new TextblockLayout();
                subtitleLayout.AlignHorizontally(TextAlignment.Center);
                subtitleLayout.AlignVertically(TextAlignment.Center);
                subtitleLayout.ScoreIfEmpty = false;
                this.subtitles.Add(subtitleLayout);

                BoundProperty_List columnWidths = new BoundProperty_List(2);
                columnWidths.SetPropertyScale(0, 2);
                columnWidths.SetPropertyScale(1, 1);
                columnWidths.BindIndices(0, 1);
                GridLayout entryGrid = GridLayout.New(new BoundProperty_List(1), columnWidths, LayoutScore.Get_UnCentered_LayoutScore(1));
                entryGrid.AddLayout(buttonLayout);
                entryGrid.AddLayout(subtitleLayout);

                LayoutUnion content = new LayoutUnion(entryGrid, buttonLayout);
                mainBuilder.AddLayout(content);

                ValueProvider <StackEntry> destinationProvider = destinationProviders[i];
                this.buttonDestinations[button] = destinationProvider;
            }
            return(LayoutCache.For(mainBuilder.BuildAnyLayout()));
        }