示例#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)));
        }
 public MinHeight_LayoutQuery(double maxWidth, double maxHeight, LayoutScore minScore, LayoutDefaults layoutDefaults)
 {
     this.setMaxWidth(maxWidth);
     this.setMaxHeight(maxHeight);
     this.setMinScore(minScore);
     this.setLayoutDefaults(layoutDefaults);
 }
示例#3
0
        public TextDiagnosticLayout()
        {
            //GridLayout grid0 = GridLayout.New(BoundProperty_List.Uniform(2), BoundProperty_List.Uniform(1), new LayoutScore());
            Editor editor = new Editor();

            editor.TextChanged += Editor_TextChanged;
            //grid0.AddLayout(new TextboxLayout(editor));
            BoundProperty_List heights = new BoundProperty_List(3);

            heights.BindIndices(0, 1);
            heights.BindIndices(0, 2);
            heights.SetPropertyScale(0, 1);
            heights.SetPropertyScale(1, 1);
            heights.SetPropertyScale(2, 12);

            GridLayout grid1      = GridLayout.New(heights, new BoundProperty_List(1), LayoutScore.Zero);
            View       bottomView = new ContentView();

            bottomView.BackgroundColor = Color.DarkGray;

            GridLayout grid2 = GridLayout.New(new BoundProperty_List(1), new BoundProperty_List(2), LayoutScore.Zero);

            this.editorToUpdate = new Editor();
            grid2.AddLayout(new TextboxLayout(this.editorToUpdate));
            View rightView = new ContentView();

            rightView.BackgroundColor = Color.Green;
            grid2.AddLayout(new ImageLayout(rightView, LayoutScore.Get_UsedSpace_LayoutScore(1)));

            grid1.AddLayout(grid2);
            grid1.AddLayout(new TextboxLayout(editor));
            grid1.AddLayout(new ImageLayout(bottomView, LayoutScore.Get_UsedSpace_LayoutScore(1000)));

            this.SubLayout = grid1;
        }
示例#4
0
        // Divides the two scores and truncates the result into a double
        public double DividedBy(LayoutScore other)
        {
            ListItemStats <double, double> ourFirstItem = this.components.GetLastValue();

            if (ourFirstItem == null)
            {
                ourFirstItem = new ListItemStats <double, double>(double.NegativeInfinity, 0);
            }
            ListItemStats <double, double> theirFirstItem = other.components.GetLastValue();

            if (theirFirstItem == null)
            {
                theirFirstItem = new ListItemStats <double, double>(double.NegativeInfinity, 0);
            }
            double ourValue   = 0;
            double theirValue = 0;

            if (ourFirstItem.Key > theirFirstItem.Key)
            {
                theirValue = 0;
            }
            else
            {
                theirValue = theirFirstItem.Value;
            }
            if (ourFirstItem.Key < theirFirstItem.Key)
            {
                ourValue = 0;
            }
            else
            {
                ourValue = ourFirstItem.Value;
            }
            return(ourValue / theirValue);
        }
示例#5
0
        public LayoutQuery WithScore(LayoutScore score)
        {
            LayoutQuery result = this.Clone();

            result.setMinScore(score);
            return(result);
        }
示例#6
0
 protected void setMinScore(LayoutScore value)
 {
     this.minScore = value;
     if (!this.Accepts(this.proposedSolution_forDebugging))
     {
         this.proposedSolution_forDebugging = null;
     }
 }
示例#7
0
 public MustScroll_Layout(LayoutChoice_Set subLayout, ScrollView view, double pixelSize, bool treatNegativeScoresAsZero)
 {
     this.requiredChildScore = LayoutScore.Zero;
     this.resultingScore     = LayoutScore.Get_UsedSpace_LayoutScore(1);
     this.subLayout          = subLayout;
     this.subLayout.AddParent(this);
     this.view = view;
 }
示例#8
0
        public LeafLayout(View view, LayoutDimensions desiredDimensions)
        {
            this.view = view;
            List <LayoutDimensions> dimensionOptions = new List <LayoutDimensions>();

            dimensionOptions.Add(desiredDimensions);
            dimensionOptions.Add(new LayoutDimensions(0, 0, LayoutScore.Get_CutOff_LayoutScore(1)));
            this.dimensionOptions = dimensionOptions;
        }
示例#9
0
        public LayoutQuery WithDimensions(double width, double height, LayoutScore score)
        {
            LayoutQuery result = this.Clone();

            result.setMaxWidth(width);
            result.setMaxHeight(height);
            result.setMinScore(score);
            return(result);
        }
示例#10
0
 public Specific_ScrollLayout(ScrollView view, Size size, LayoutScore score, SpecificLayout sublayout)
     : base(view, size, score, sublayout, new Thickness())
 {
     this.View = view;
     if (double.IsInfinity(this.SubLayout.Height))
     {
         ErrorReporter.ReportParadox("Infinite Specific_ScrollLayout height: " + this);
     }
 }
 public Specific_ContainerLayout(View view, Size size, LayoutScore bonusScore, SpecificLayout subLayout, Thickness borderThickness)
 {
     this.Initialize();
     this.view            = view;
     this.Size            = size;
     this.bonusScore      = bonusScore;
     this.BorderThickness = borderThickness;
     this.subLayout       = subLayout;
 }
示例#12
0
        public LayoutScore Times(double weightScale)
        {
            LayoutScore product = new LayoutScore();

            foreach (ListItemStats <double, double> item in this.components.AllItems)
            {
                product.addComponent(item.Key, item.Value * weightScale);
            }
            return(product);
        }
示例#13
0
        public override bool Equals(object other)
        {
            LayoutScore otherScore = other as LayoutScore;

            if (otherScore != null)
            {
                return(this.CompareTo(otherScore) == 0);
            }
            return(false);
        }
示例#14
0
 public static LayoutScore Max(LayoutScore a, LayoutScore b)
 {
     if (a.CompareTo(b) > 0)
     {
         return(a);
     }
     else
     {
         return(b);
     }
 }
示例#15
0
        public override SpecificLayout GetBestLayout(LayoutQuery query)
        {
            if (query.MaxWidth <= 0 || query.MaxHeight <= 0)
            {
                double width  = 0;
                double height = 0;
                if (this.ComputeScore(width, height).CompareTo(query.MinScore) < 0)
                {
                    return(null);
                }
                return(this.MakeLayout(width, height, query));
            }
            LayoutScore score = this.ComputeScore(query.MaxWidth, query.MaxHeight);

            if (score.CompareTo(query.MinScore) < 0)
            {
                return(null);
            }
            double ratio = query.MinScore.DividedBy(score);

            if (query.MinimizesWidth())
            {
                double width = Math.Ceiling(query.MaxWidth * ratio / this.pixelSize) * this.pixelSize;
                if (this.ComputeScore(width, query.MaxHeight).CompareTo(query.MinScore) < 0)
                {
                    // the score has some additional components that the division didn't catch, so we have to add another pixel
                    width += this.pixelSize;
                }
                if (width > query.MaxWidth)
                {
                    // We had to round up past the max height, so there is no solution
                    return(null);
                }

                return(this.MakeLayout(width, query.MaxHeight, query));
            }
            if (query.MinimizesHeight())
            {
                double height = Math.Ceiling(query.MaxHeight * ratio / this.pixelSize) * this.pixelSize;
                if (this.ComputeScore(query.MaxWidth, height).CompareTo(query.MinScore) < 0)
                {
                    // the score has some additional components that the division didn't catch, so we have to add another pixel
                    height += this.pixelSize;
                }
                if (height > query.MaxHeight)
                {
                    // We had to round up past the max height, so there is no solution
                    return(null);
                }

                return(this.MakeLayout(query.MaxWidth, height, query));
            }
            return(MakeLayout(query.MaxWidth, query.MaxHeight, query));
        }
示例#16
0
        public LayoutScore ComponentRange(int minIndexInclusive, int maxIndexExclusive)
        {
            LayoutScore range = new LayoutScore();
            List <ListItemStats <double, double> > subComponents = this.components.ItemsBetweenIndices(minIndexInclusive, maxIndexExclusive);

            foreach (ListItemStats <double, double> component in subComponents)
            {
                range.addComponent(component.Key, component.Value);
            }
            return(range);
        }
示例#17
0
        private void considerAnnouncingChanges()
        {
            if (this.LoggingEnabled)
            {
                System.Diagnostics.Debug.WriteLine("considerAnnouncingChanges textItem_text = " + this.textItem_text + " Text = " + this.Text);
            }
            if (this.Get_ChangedSinceLastRender())
            {
                return;
            }
            bool mustRedraw = false;

            if (!this.ScoreIfEmpty && (this.Text == "" || this.Text == null || this.textItem_text == "" || this.textItem_text == null))
            {
                mustRedraw = true;
            }
            else
            {
                View view        = this.TextItem_Configurer.View;
                Size currentSize = new Size(view.Width, view.Height);
                Specific_TextLayout layoutForCurrentText = this.ComputeDimensions(currentSize, false);
                this.TextItem_Text  = this.Text;
                this.layoutsByWidth = new Dictionary <double, FormattedParagraph>();
                Specific_TextLayout layoutForNewText = this.ComputeDimensions(currentSize, false);
                LayoutScore         oldScore         = layoutForCurrentText.Score;
                LayoutScore         newScore         = layoutForNewText.Score;
                if (!oldScore.Equals(newScore))
                {
                    // Something about the score would change if we keep the same size and use the new text
                    // Maybe we suddenly need more space and should ask for it
                    // Maybe we suddenly have enough space and we might become an interesting layout that permits a different font size
                    // In either of these cases, we want to recalculate the layout size
                    mustRedraw = true;
                }
                else
                {
                    // The score didn't change with the new text and the old layout size
                    // So, the user probably isn't interested in having us recompute the layout dimensions
                    mustRedraw = false;
                    this.TextItem_Configurer.DisplayText = layoutForNewText.DisplayText;
                }

                if (this.LoggingEnabled)
                {
                    System.Diagnostics.Debug.WriteLine("TextLayout calculating: Have size: " + currentSize + ". Old text: " + layoutForCurrentText.DisplayText +
                                                       ". Old target: " + layoutForCurrentText.DesiredSizeForDebugging + ". New text: " + layoutForNewText.DisplayText + ". New target: " + layoutForNewText.DesiredSizeForDebugging);
                }
            }

            this.AnnounceChange(mustRedraw);
        }
示例#18
0
        private SpecificLayout makeLayout(Size size, SpecificLayout childLayout)
        {
            double childHeight = childLayout.Height;

            if (childHeight == 0)
            {
                childHeight = 1;
            }
            LayoutScore    score           = this.resultingScore.Times(size.Height / childHeight);
            LayoutScore    scoreDifference = score.Minus(childLayout.Score);
            SpecificLayout result          = new Specific_ScrollLayout(this.view, size, scoreDifference, childLayout);

            return(result);
        }
示例#19
0
        public override LayoutQuery OptimizedPastDimensions(LayoutDimensions example)
        {
            MaxScore_LayoutQuery result   = this;
            LayoutScore          minScore = example.Score.Plus(LayoutScore.Tiny);

            if (this.MinScore.CompareTo(minScore) < 0)
            {
                result = this.Clone((MaxScore_LayoutQuery)null);
                result.setMinScore(minScore);
                if (!result.Accepts(result.ProposedSolution_ForDebugging))
                {
                    result.ProposedSolution_ForDebugging = null;
                }
            }
            return(result);
        }
示例#20
0
        protected void setMinScore(LayoutScore value)
        {
            this.minScore = value;
            if (!this.Accepts(this.proposedSolution_forDebugging))
            {
                this.proposedSolution_forDebugging = null;
            }

            /*if (this.maxWidth > 0 && this.maxHeight > 0)
             * {
             *  if (this.minScore.CompareTo(LayoutScore.Get_CutOff_LayoutScore(1)) <= 0 && this.minScore.CompareTo(LayoutScore.Minimum) > 0)
             *  {
             *      System.Diagnostics.Debug.WriteLine("Considering cropping: " + this);
             *  }
             * }*/
        }
示例#21
0
        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()));
        }
示例#22
0
        public int CompareTo(LayoutScore other)
        {
            int ourIndex   = this.components.NumItems - 1;
            int theirIndex = other.components.NumItems - 1;

            // loop over the list of components and once a coordinate differs, use it for the comparison
            while (true)
            {
                if (ourIndex >= 0)
                {
                    if (theirIndex >= 0)
                    {
                        // both coordinates exist
                        ListItemStats <double, double> ourComponent   = this.components.GetValueAtIndex(ourIndex);
                        ListItemStats <double, double> theirComponent = other.components.GetValueAtIndex(theirIndex);
                        // check for the possibility that one coordinate is more important than the other
                        if (ourComponent.Key > theirComponent.Key)
                        {
                            if (ourComponent.Value != 0)
                            {
                                return(ourComponent.Value.CompareTo(0));
                            }
                        }
                        else
                        {
                            if (theirComponent.Key > ourComponent.Key)
                            {
                                if (theirComponent.Value != 0)
                                {
                                    return(-theirComponent.Value.CompareTo(0));
                                }
                            }
                            else
                            {
                                // keys are equal
                                int comparison = ourComponent.Value.CompareTo(theirComponent.Value);
                                if (comparison != 0)
                                {
                                    return(comparison);
                                }
                            }
                        }
                        if (ourComponent.Key >= theirComponent.Key)
                        {
                            ourIndex--;
                        }
                        if (ourComponent.Key <= theirComponent.Key)
                        {
                            theirIndex--;
                        }
                    }
                    else
                    {
                        // only our coordinate exists
                        ListItemStats <double, double> ourComponent = this.components.GetValueAtIndex(ourIndex);
                        if (ourComponent.Value != 0)
                        {
                            return(ourComponent.Value.CompareTo(0));
                        }
                        ourIndex--;
                    }
                }
                else
                {
                    if (theirIndex >= 0)
                    {
                        // only their coordinate exists
                        ListItemStats <double, double> theirComponent = other.components.GetValueAtIndex(theirIndex);
                        if (theirComponent.Value != 0)
                        {
                            return(-theirComponent.Value.CompareTo(0));
                        }
                        theirIndex--;
                    }
                    else
                    {
                        // neither score has any more coordinates
                        return(0);
                    }
                }
            }
        }
示例#23
0
 public LayoutScore Minus(LayoutScore other)
 {
     return(this.Plus(other.Times(-1)));
 }
示例#24
0
        public LayoutScore Plus(LayoutScore other)
        {
            int         ourIndex   = 0;
            int         theirIndex = 0;
            LayoutScore sum        = new LayoutScore();

            while (true)
            {
                double priority;
                double weight = 0;
                if (ourIndex < this.components.NumItems)
                {
                    if (theirIndex < other.components.NumItems)
                    {
                        // both coordinates exist
                        ListItemStats <double, double> ourComponent   = this.components.GetValueAtIndex(ourIndex);
                        ListItemStats <double, double> theirComponent = other.components.GetValueAtIndex(theirIndex);
                        priority = Math.Min(ourComponent.Key, theirComponent.Key);
                        if (ourComponent.Key == priority)
                        {
                            weight += ourComponent.Value;
                            ourIndex++;
                        }
                        if (theirComponent.Key == priority)
                        {
                            if (double.IsInfinity(weight) && double.IsInfinity(theirComponent.Value) &&
                                double.IsPositiveInfinity(weight) != double.IsPositiveInfinity(theirComponent.Value))
                            {
                                // Treat negative infinity plus positive infinity as zero
                                weight = 0;
                            }
                            else
                            {
                                weight += theirComponent.Value;
                            }
                            theirIndex++;
                        }
                    }
                    else
                    {
                        // only our coordinate exists
                        ListItemStats <double, double> ourComponent = this.components.GetValueAtIndex(ourIndex);
                        priority = ourComponent.Key;
                        weight   = ourComponent.Value;
                        ourIndex++;
                    }
                }
                else
                {
                    if (theirIndex < other.components.NumItems)
                    {
                        // only their coordinate exists
                        ListItemStats <double, double> theirComponent = other.components.GetValueAtIndex(theirIndex);
                        priority = theirComponent.Key;
                        weight   = theirComponent.Value;
                        theirIndex++;
                    }
                    else
                    {
                        // no more components are left
                        // debug-check: make sure there are no duplicate coordinates
                        int i;
                        for (i = 1; i < sum.components.NumItems; i++)
                        {
                            if (sum.components.GetValueAtIndex(i - 1).Key == sum.components.GetValueAtIndex(i).Key)
                            {
                                System.Diagnostics.Debug.WriteLine("error: layout score has a duplicate key");
                            }
                        }


                        return(sum);
                    }
                }
                // only add the coordinate if it is nonzero, because zeros are always provided by default
                if (weight != 0)
                {
                    sum.addComponent(priority, weight);
                }
            }
        }
示例#25
0
 public void CopyFrom(LayoutScore original)
 {
     this.components = new StatList <double, double>(original.components);
 }
示例#26
0
 public LayoutScore(LayoutScore original)
 {
     this.Initialize();
     this.CopyFrom(original);
 }
示例#27
0
 public Specific_TextLayout(TextItem_Configurer textItem, double width, double height, double fontSize, LayoutScore score, String displayText, Size desiredSize)
 {
     this.textItem                = textItem;
     this.width                   = width;
     this.height                  = height;
     this.fontSize                = fontSize;
     this.score                   = score;
     this.DisplayText             = displayText;
     this.DesiredSizeForDebugging = desiredSize;
 }
示例#28
0
 public MinWidth_LayoutQuery(double maxWidth, double maxHeight, LayoutScore minScore)
 {
     this.setMaxWidth(maxWidth);
     this.setMaxHeight(maxHeight);
     this.setMinScore(minScore);
 }
 public Specific_ContainerLayout(View view, Size size, LayoutScore bonusScore, Thickness borderThickness)
     : this(view, size, bonusScore, null, borderThickness)
 {
 }
示例#30
0
 protected Specific_ContainerLayout makeSpecificLayout(View view, Size size, LayoutScore bonusScore, SpecificLayout subLayout, Thickness border)
 {
     return(new Specific_ContainerLayout(view, size, bonusScore, subLayout, border));
 }