예제 #1
0
        /// <summary>
        /// Gets the children of the widget and expands the space enough to accomodate them,
        /// depending on if the parent is Row or Column.
        /// </summary>
        /// <param name="widget"></param>
        public void ApplyOn(IWidget widget)
        {
            ApplicationDone = false;
            IncreaseSpaceWithChildren(widget);

            var(x, y, _, _) = widget.Space;

            var maybeRow = ApplyUtils.ExtractRowProp(widget);

            if (maybeRow.TryGetValue(out var row))
            {
                row.Applied += (sender, args) =>
                {
                    WidgetsSpaceHelper.UpdateSpace(widget,
                                                   new RectangleF(
                                                       x,
                                                       y,
                                                       row.Rows.Max(r => r.Width),
                                                       row.Rows.Sum(r => r.Height)));
                };
            }
            else
            {
                var maybeCol = ApplyUtils.ExtractColumnProp(widget);
                if (maybeCol.TryGetValue(out var col))
                {
                    col.Applied += (sender, args) =>
                    {
                        WidgetsSpaceHelper.UpdateSpace(widget,
                                                       new RectangleF(
                                                           x,
                                                           y,
                                                           col.Columns.Sum(c => c.Width),
                                                           col.Columns.Sum(c => c.Height)));
                    };
                }
                else
                {
                    Log.Error(
                        "Flex can only be applied to a Row or Column Widget! Make sure the widget you applied Flex to has a Row or Column Prop");
                    throw new IncompatibleWidgetException(
                              "Tried to apply Flex to a widget without a Row or Column Prop");
                }
            }

            ApplicationDone = true;
            OnApplied();
        }