//public static Widget DropDown(IEnumerable<string> items, PopInOut pop_in_out_behavior = null)
        //{
        //    WidgetList widgets = new WidgetList();
        //    foreach (string item in items) widgets.Add(new Widget().WithAddedBehavior(new DrawText() { Text = item, ConstrainAreaToText = true }));
        //    return DropDown(widgets, pop_in_out_behavior);
        //}

        public static Widget DropDown(
            IEnumerable <Widget> widgets,
            PopInOut pop_in_out_behavior = null
            )
        {
            var widgets_ = widgets.ToList();
            var dropdown = new Widget();

            dropdown.VisualSettings.VisualRole = VisualRoleType.pop_up;
            dropdown.Behaviors.GroupBehaviors.AcceptancePolicy += GroupBehaviorAcceptancePolicy.NoUserScrolling;
            dropdown.MinimumSize = new Point2(1f, 1f);
            dropdown.AddRange(widgets_);
            dropdown.Behaviors.Add(new GridFormat(1, widgets_.Count));

            dropdown.Behaviors.Add(
                pop_in_out_behavior ?? new PopInOut(
                    RectanglePart.Uniform(0.95f, Directions2D.DLR),
                    RectanglePart.Uniform(0f, Directions2D.D, 1f)
                    )
            {
                OpeningMotion = InterpolationSettings.Fast,
                ClosingMotion = InterpolationSettings.Faster
            }
                );

            return(dropdown);
        }
Beispiel #2
0
        public static Widget LoginWindow(
            Action <LoginSignal> confirm_handle,
            Action <CreateAccountSignal> handle_account_creation = null
            )
        {
            const int login_create_spacing = 8 / 2;

            var window = new Widget {
                Size = new Point2(400, 300), Name = "Login Window"
            };

            window.VisualSettings.VisualRole = GeneralVisualSettings.VisualRoleType.pop_up;

            window.Behaviors.Add(new CenterContent());
            window.Behaviors.Add(new PinWidget {
                Pin = InnerWidgetLocation.Centered
            });
            window.Behaviors.Add(new PopInOut(RectanglePart.Uniform(0.975f), RectanglePart.Uniform(0.5f))
            {
                OpeningMotion = InterpolationSettings.Fast, ClosingMotion = InterpolationSettings.Fast
            });

            var username_entry = CommonWidgets.SingleLineTextEntry("", DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.center, 8f);
            var password_entry = CommonWidgets.SingleLineTextEntry("", DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.center, 8f);

            username_entry.Area = new RectangleF(100, 0, 150, 40);
            password_entry.Area = new RectangleF(100, 60, 150, 40);

            var username_label = CommonWidgets.Label("Username:"******"Password:"******"Login");

            login_button.Area = handle_account_creation != null
                ? new RectangleF(125 + login_create_spacing, 120, 125 - login_create_spacing, 40)
                : new RectangleF(100, 120, 150, 40);

            window.Add(username_label);
            window.Add(password_label);
            window.Add(username_entry);
            window.Add(password_entry);
            window.Add(login_button);

            void handleResponse(WidgetResponse response)
            {
                if (response.Reply != WidgetResponse.ResponseType.reject)
                {
                    return;
                }

                window.ParentDWindow.ShowPopUpMessage("Could not log in.\n\nError: " + response.Message);
            }

            login_button.OnClick += (s, a) =>
                                    confirm_handle.Invoke(new LoginSignal(
                                                              username_entry.Behaviors.Common.DrawText.Text,
                                                              password_entry.Behaviors.Common.DrawText.Text,
                                                              handleResponse
                                                              ));

            if (handle_account_creation == null)
            {
                return(window);
            }

            var create_account_button = CommonWidgets.Button("Create Account");

            create_account_button.Area = new RectangleF(0, 120, 125 - login_create_spacing, 40);

            void handleCreationResponse(WidgetResponse r)
            {
                if (r.Reply != WidgetResponse.ResponseType.reject)
                {
                    return;
                }

                window.ParentDWindow.ShowPopUpMessage("Error creating account: " + r.Message);
            }

            create_account_button.OnClick += (s, a) =>
                                             handle_account_creation.Invoke(
                new CreateAccountSignal(
                    username_entry.Behaviors.Common.DrawText.Text,
                    password_entry.Behaviors.Common.DrawText.Text,
                    "",
                    handleCreationResponse
                    )
                );

            window.Add(create_account_button);

            return(window);
        }