Beispiel #1
0
        public override void Construct()
        {
            if (Rect.Width == 0 || Rect.Height == 0) // Ooops.
            {
                Rect.Width  = 480;
                Rect.Height = 320;
            }

            //Center on screen.
            Rect.X = (Root.RenderData.VirtualScreen.Width / 2) - (Rect.Width / 2);
            Rect.Y = (Root.RenderData.VirtualScreen.Height / 2) - (Rect.Height / 2);

            Border = "border-one";

            AddChild(new Button
            {
                Text = OkayText,
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    DialogResult = Result.OKAY;
                    this.Close();
                },
                AutoLayout = AutoLayout.FloatBottomRight
            });

            AddChild(new Button
            {
                Text = CancelText,
                TextHorizontalAlign = HorizontalAlign.Center,
                TextVerticalAlign   = VerticalAlign.Center,
                Border  = "border-button",
                OnClick = (sender, args) =>
                {
                    DialogResult = Result.CANCEL;
                    this.Close();
                },
                AutoLayout = AutoLayout.FloatBottomLeft
            });

            Panel = AddChild(new GridPanel
            {
                AutoLayout  = Gui.AutoLayout.DockFill,
                OnLayout    = (sender) => sender.Rect.Height -= 36,
                ItemSize    = ItemSize,
                ItemSpacing = ItemSpacing
            }) as GridPanel;

            var index = 0;

            foreach (var item in ItemSource)
            {
                var lambdaIndex = index;
                var lambdaItem  = item;
                item.OnClick += (sender, args) =>
                {
                    Selection    = lambdaIndex;
                    SelectedItem = item;
                };
                item.OnMouseEnter += (sender, args) =>
                {
                    if (HoverItem != lambdaIndex)
                    {
                        HoverItem = lambdaIndex;
                    }
                };
                item.OnMouseLeave += (sender, args) =>
                {
                    if (HoverItem == lambdaIndex)
                    {
                        HoverItem = -1;
                    }
                };
                index += 1;
                Panel.AddChild(item);
            }

            Layout();
        }