Ejemplo n.º 1
0
        /// <summary>
        /// Move the widgets to the bottom of a Row or right of a Column.
        /// </summary>
        /// <param name="widget"></param>
        public void ApplyOn(IWidget widget)
        {
            ApplicationDone = false;
            ApplyUtils.ApplyIfThereAreChildren(widget, $"{widget} has no children to item-base.",
                                               () =>
            {
                var rowsAtBase =
                    PutAtBase(widget, l => l.Height, GridHelper.WidgetHeight,
                              (y, c) => new Vector2(c.Space.X, y + c.Margins.Top));
                var colsAtBase =
                    PutAtBase(widget, l => l.Width, GridHelper.WidgetWidth,
                              (x, c) => new Vector2(x + c.Margins.Left, c.Space.Y));

                if (ApplyUtils.TryExtractRows(widget, out var rows))
                {
                    rowsAtBase(rows);
                }
                else if (ApplyUtils.TryExtractColumns(widget, out var cols))
                {
                    colsAtBase(cols);
                }
                else
                {
                    Log.Error(
                        "ItemBase can only be applied to a Row or Column Widget! Make sure this {W} has a Row or Column Prop",
                        widget.ToString());
                    throw new IncompatibleWidgetException(
                        "Tried to apply ItemBase to a widget without a Row or Column Prop");
                }
            });
            ApplicationDone = true;
            OnApplied();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Move the widgets to the vertical center of a Row or to the horizontal center of a Column.
 /// </summary>
 /// <param name="widget"></param>
 public void ApplyOn(IWidget widget)
 {
     ApplicationDone = false;
     ApplyUtils.ApplyIfThereAreChildren(widget,
                                        $"{widget} has no children to item-center.",
                                        () =>
     {
         if (ApplyUtils.TryExtractRows(widget, out var rows))
         {
             CenterHelper.ItemCenterVertical(widget, rows);
         }
         else if (ApplyUtils.TryExtractColumns(widget, out var cols))
         {
             CenterHelper.ItemCenterHorizontal(widget, cols);
         }
         else
         {
             Log.Error(
                 "ItemCenter can only be applied to a Row or Column Widget! Make sure this {W} has a Row or Column Prop",
                 widget.ToString());
             throw new IncompatibleWidgetException(
                 "Tried to apply ItemCenter to a widget without a Row or Column Prop");
         }
     });
     ApplicationDone = false;
     OnApplied();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Move the widgets in a way to have them maximally separated between them.
 /// In a Row they are separated horizontally, in a Column vertically.
 /// </summary>
 /// <param name="widget"></param>
 public void ApplyOn(IWidget widget)
 {
     ApplicationDone = false;
     ApplyUtils.ApplyIfThereAreChildren(widget,
                                        $"{widget} has no children to justify space between.",
                                        () =>
     {
         if (widget.Children.Count == 1)
         {
             return;
         }
         if (ApplyUtils.TryExtractRows(widget, out var rows))
         {
             SpaceBetweenHorizontally(widget, rows);
         }
         else if (ApplyUtils.TryExtractColumns(widget, out var cols))
         {
             SpaceBetweenVertically(widget, cols);
         }
         else
         {
             Log.Error(
                 "JustifyBetween can only be applied to a Row or Column Widget! Make sure this {W} has a Row or Column Prop",
                 widget.ToString());
             throw new IncompatibleWidgetException(
                 "Tried to apply JustifyBetween to a widget without a Row or Column Prop");
         }
     });
     ApplicationDone = true;
     OnApplied();
 }