Exemple #1
0
        public void LeftTopBottomRight_Win_ShouldNotThrow()
        {
            // Setup Fake driver
            (Window win, Button button) setup()
            {
                Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));
                Application.Iteration = () => {
                    Application.RequestStop();
                };
                var win = new Window("window")
                {
                    X      = 0,
                    Y      = 0,
                    Width  = Dim.Fill(),
                    Height = Dim.Fill(),
                };

                Application.Top.Add(win);

                var button = new Button("button")
                {
                    X = Pos.Center(),
                };

                win.Add(button);

                return(win, button);
            }

            Application.RunState rs;

            void cleanup(Application.RunState rs)
            {
                // Cleanup
                Application.End(rs);
            }

            // Test cases:
            var app = setup();

            app.button.Y = Pos.Left(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);

            app          = setup();
            app.button.Y = Pos.X(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);

            app          = setup();
            app.button.Y = Pos.Top(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);

            app          = setup();
            app.button.Y = Pos.Y(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);

            app          = setup();
            app.button.Y = Pos.Bottom(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);

            app          = setup();
            app.button.Y = Pos.Right(app.win);
            rs           = Application.Begin(Application.Top);
            Application.Run();
            cleanup(rs);
        }
Exemple #2
0
        public void Center_SetsValue()
        {
            var pos = Pos.Center();

            Assert.Equal("Pos.Center", pos.ToString());
        }
        static int QueryFull(bool useErrorColors, int width, int height, ustring title, ustring message, params ustring [] buttons)
        {
            const int defaultWidth = 50;
            int       textWidth    = Label.MaxWidth(message, width);
            int       textHeight   = Label.MaxHeight(message, width == 0 ? defaultWidth : width); // message.Count (ustring.Make ('\n')) + 1;
            int       msgboxHeight = Math.Max(1, textHeight) + 3;                                 // textHeight + (top + top padding + buttons + bottom)

            // Create button array for Dialog
            int           count      = 0;
            List <Button> buttonList = new List <Button> ();

            foreach (var s in buttons)
            {
                var b = new Button(s);
                if (count == 0)
                {
                    b.IsDefault = true;
                }
                buttonList.Add(b);
                count++;
            }

            // Create Dialog (retain backwards compat by supporting specifying height/width)
            Dialog d;

            if (width == 0 & height == 0)
            {
                d        = new Dialog(title, buttonList.ToArray());
                d.Height = msgboxHeight;
            }
            else
            {
                d = new Dialog(title, Math.Max(width, textWidth) + 4, height, buttonList.ToArray());
            }

            if (useErrorColors)
            {
                d.ColorScheme = Colors.Error;
            }

            if (message != null)
            {
                var l = new Label(textWidth > width ? 0 : (width - 4 - textWidth) / 2, 1, message);
                l.LayoutStyle   = LayoutStyle.Computed;
                l.TextAlignment = TextAlignment.Centered;
                l.X             = Pos.Center();
                l.Y             = Pos.Center();
                l.Width         = Dim.Fill(2);
                l.Height        = Dim.Fill(1);
                d.Add(l);
            }

            // Dynamically size Width
            int msgboxWidth = Math.Max(defaultWidth, Math.Max(title.Length + 8, Math.Max(textWidth + 4, d.GetButtonsWidth()) + 8));                 // textWidth + (left + padding + padding + right)

            d.Width = msgboxWidth;

            // Setup actions
            int clicked = -1;

            for (int n = 0; n < buttonList.Count; n++)
            {
                int buttonId = n;
                buttonList [n].Clicked += () => {
                    clicked = buttonId;
                    Application.RequestStop();
                };
            }

            // Rin the modal; do not shutdown the mainloop driver when done
            Application.Run(d, false);
            return(clicked);
        }