Exemple #1
0
        // Todo: 'Flow' options. Pack widgets up in rows until full, flow...
        // Must track rects in each corner used for flow.
        private static Rectangle LayoutChild(Rectangle Inside, Margin Padding, Widget Child)
        {
            Rectangle newPos;

            var size = Child.GetBestSize();

            switch (Child.AutoLayout)
            {
            case AutoLayout.None:
                newPos = Child.Rect;
                break;

            case AutoLayout.DockTop:
                size   = GetClampedChildSize(Child, new Point(Inside.Width - Padding.Horizontal, size.Y));
                newPos = new Rectangle(Inside.X + Padding.Left, Inside.Y + Padding.Top, size.X, size.Y);
                Inside = Inside.Interior(0, size.Y + Padding.Top, 0, 0);
                break;

            case AutoLayout.DockRight:
                size   = GetClampedChildSize(Child, new Point(size.X, Inside.Height - Padding.Vertical));
                newPos = new Rectangle(Inside.Right - size.X - Padding.Right,
                                       Inside.Y + Padding.Top, size.X, size.Y);
                Inside = Inside.Interior(0, 0, size.X + Padding.Right, 0);
                break;

            case AutoLayout.DockBottom:
                size   = GetClampedChildSize(Child, new Point(Inside.Width - Padding.Horizontal, size.Y));
                newPos = new Rectangle(Inside.X + Padding.Left,
                                       Inside.Bottom - size.Y - Padding.Bottom, size.X, size.Y);
                Inside = Inside.Interior(0, 0, 0, size.Y + Padding.Bottom);
                break;

            case AutoLayout.DockLeft:
                size   = GetClampedChildSize(Child, new Point(size.X, Inside.Height - Padding.Vertical));
                newPos = new Rectangle(Inside.X + Padding.Left, Inside.Y + Padding.Top, size.X, size.Y);
                Inside = Inside.Interior(size.X + Padding.Left, 0, 0, 0);
                break;

            case AutoLayout.DockFill:
                size = GetClampedChildSize(Child, new Point(
                                               Inside.Width - Padding.Horizontal, Inside.Height - Padding.Vertical));
                newPos = new Rectangle(         // Actually just centers widget in space
                    Inside.X + (Inside.Width / 2) - (size.X / 2),
                    Inside.Y + (Inside.Height / 2) - (size.Y / 2),
                    size.X, size.Y);
                Inside = new Rectangle(0, 0, 0, 0);
                break;

            case AutoLayout.FloatCenter:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(
                    Inside.X + (Inside.Width / 2) - (size.X / 2),
                    Inside.Y + (Inside.Height / 2) - (size.Y / 2),
                    size.X, size.Y);
                break;

            case AutoLayout.FloatTop:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + (Inside.Width / 2) - (size.X / 2),
                                       Inside.Y + Padding.Top, size.X, size.Y);
                break;

            case AutoLayout.FloatBottom:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + (Inside.Width / 2) - (size.X / 2),
                                       Inside.Bottom - size.Y - Padding.Bottom, size.X, size.Y);
                break;

            case AutoLayout.FloatLeft:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + Padding.Left, Inside.Y + (Inside.Height / 2) - (size.Y / 2),
                                       size.X, size.Y);
                break;

            case AutoLayout.FloatRight:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.Right - size.X - Padding.Right,
                                       Inside.Y + (Inside.Height / 2) - (size.Y / 2),
                                       size.X, size.Y);
                break;

            case AutoLayout.FloatTopRight:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + Inside.Width - size.X - Padding.Right,
                                       Inside.Y + Padding.Top, size.X, size.Y);
                break;

            case AutoLayout.FloatTopLeft:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + Padding.Left, Inside.Y + Padding.Top, size.X, size.Y);
                break;

            case AutoLayout.FloatBottomRight:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(
                    Inside.X + Inside.Width - size.X - Padding.Right,
                    Inside.Y + Inside.Height - size.Y - Padding.Bottom,
                    size.X, size.Y);
                break;

            case AutoLayout.FloatBottomLeft:
                size   = GetClampedChildSize(Child, size);
                newPos = new Rectangle(Inside.X + Padding.Left,
                                       Inside.Y + Inside.Height - size.Y - Padding.Bottom, size.X, size.Y);
                break;

            default:
                newPos = new Rectangle(0, 0, 0, 0);
                break;
            }

            Child.Rect = newPos;
            Child.Layout();

            return(Inside);
        }
Exemple #2
0
        private void BuildTab(Gum.Widgets.TabPanel TabPanel, String TabName, IEnumerable <BuildableItem> ItemSource,
                              Action <BuildableItem, Gum.Widget, Gum.Widget> BuildDescriptionPanel)
        {
            var panel = TabPanel.AddTab(TabName, new Widget
            {
                Border  = "border-thin",
                Padding = new Margin(4, 4, 0, 0)
            });

            Gum.Widgets.WidgetListView list = null;
            Gum.Widget descriptionPanel     = null;
            Gum.Widget buildButton          = null;

            list = panel.AddChild(new Gum.Widgets.WidgetListView
            {
                ItemHeight             = 32,
                MinimumSize            = new Point(256, 0),
                AutoLayout             = Gum.AutoLayout.DockLeft,
                OnSelectedIndexChanged = (sender) =>
                {
                    var selectedItem = (sender as Gum.Widgets.WidgetListView).SelectedItem;
                    if (selectedItem != null)
                    {
                        descriptionPanel.Clear();
                        buildButton.Hidden = false;
                        BuildDescriptionPanel(selectedItem.Tag as BuildableItem, descriptionPanel, buildButton);
                        descriptionPanel.Layout();
                        buildButton.Invalidate();
                    }
                }
            }) as Gum.Widgets.WidgetListView;

            var bottomRow = panel.AddChild(new Widget
            {
                MinimumSize = new Point(0, 32),
                AutoLayout  = Gum.AutoLayout.DockBottom
            });

            buildButton = bottomRow.AddChild(new Widget
            {
                Text = "BUILD",
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border = "border-button",
                //OnClick = (sender, args) => BuildClicked(list.SelectedItem.Tag as BuildableItem),
                AutoLayout = AutoLayout.DockRight
            });

            descriptionPanel = panel.AddChild(new Widget
            {
                AutoLayout = Gum.AutoLayout.DockFill,
                OnLayout   = (sender) => sender.Rect.Height -= 36
            });

            foreach (var buildableItem in ItemSource)
            {
                var row = new Gum.Widget
                {
                    Background = new TileReference("basic", 0),
                    Tag        = buildableItem
                };

                list.AddItem(row);

                if (buildableItem.Icon != null)
                {
                    row.AddChild(new Gum.Widget
                    {
                        MinimumSize = new Point(32, 32),
                        Background  = buildableItem.Icon,
                        AutoLayout  = Gum.AutoLayout.DockLeft
                    });
                }

                row.AddChild(new Gum.Widget
                {
                    Text       = buildableItem.Name,
                    AutoLayout = Gum.AutoLayout.DockFill
                });
            }

            list.SelectedIndex = 0;
        }