Ejemplo n.º 1
0
        public void Show_Display_At_Zero_If_The_Toplevel_Height_Is_Less_Than_The_Menu_Height()
        {
            var cm = new ContextMenu(0, 0,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            Assert.Equal(new Point(0, 0), cm.Position);

            cm.Show();
            Assert.Equal(new Point(0, 0), cm.Position);
            Application.Begin(Application.Top);
            ((FakeDriver)Application.Driver).SetBufferSize(80, 4);

            var expected = @"
┌──────┐
│ One  │
│ Two  │
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(0, 1, 8, 3), pos);

            cm.Hide();
            Assert.Equal(new Point(0, 0), cm.Position);
        }
Ejemplo n.º 2
0
        public void Position_Changing()
        {
            var cm = new ContextMenu(10, 5,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            cm.Show();
            Application.Begin(Application.Top);

            var expected = @"
          ┌──────┐
          │ One  │
          │ Two  │
          └──────┘
";

            GraphViewTests.AssertDriverContentsAre(expected, output);

            cm.Position = new Point(5, 10);

            cm.Show();
            Application.Refresh();

            expected = @"
     ┌──────┐
     │ One  │
     │ Two  │
     └──────┘
";

            GraphViewTests.AssertDriverContentsAre(expected, output);
        }
Ejemplo n.º 3
0
        public void Show_Hide_IsShow()
        {
            var cm = new ContextMenu(10, 5,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            cm.Show();
            Assert.True(ContextMenu.IsShow);

            Application.Begin(Application.Top);

            var expected = @"
          ┌──────┐
          │ One  │
          │ Two  │
          └──────┘
";

            GraphViewTests.AssertDriverContentsAre(expected, output);

            cm.Hide();
            Assert.False(ContextMenu.IsShow);

            Application.Refresh();

            expected = "";

            GraphViewTests.AssertDriverContentsAre(expected, output);
        }
Ejemplo n.º 4
0
        public void Show_Display_Below_The_Bottom_Host_If_Has_Enough_Space()
        {
            var view = new View("View")
            {
                X = 10, Y = 5, Width = 10, Height = 1
            };
            var cm = new ContextMenu(view,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            Application.Top.Add(view);
            Application.Begin(Application.Top);

            Assert.Equal(new Point(10, 5), cm.Position);

            cm.Show();
            Application.Top.Redraw(Application.Top.Bounds);
            Assert.Equal(new Point(10, 5), cm.Position);

            var expected = @"
          View
          ┌──────┐
          │ One  │
          │ Two  │
          └──────┘
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(10, 5, 18, 5), pos);

            cm.Hide();
            Assert.Equal(new Point(10, 5), cm.Position);
            cm.Host.X      = 5;
            cm.Host.Y      = 10;
            cm.Host.Height = 3;

            cm.Show();
            Application.Top.Redraw(Application.Top.Bounds);
            Assert.Equal(new Point(5, 12), cm.Position);

            expected = @"
     View


     ┌──────┐
     │ One  │
     │ Two  │
     └──────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(5, 10, 13, 7), pos);

            cm.Hide();
            Assert.Equal(new Point(5, 12), cm.Position);
        }
Ejemplo n.º 5
0
        public void Show_Ensures_Display_Inside_The_Container_But_Preserves_Position()
        {
            var cm = new ContextMenu(80, 25,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            Assert.Equal(new Point(80, 25), cm.Position);

            cm.Show();
            Assert.Equal(new Point(80, 25), cm.Position);
            Application.Begin(Application.Top);

            var expected = @"
                                                                        ┌──────┐
                                                                        │ One  │
                                                                        │ Two  │
                                                                        └──────┘
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(72, 21, 80, 4), pos);

            cm.Hide();
            Assert.Equal(new Point(80, 25), cm.Position);
        }
Ejemplo n.º 6
0
        public void Show_Ensures_Display_Inside_The_Container_Without_Overlap_The_Host()
        {
            var view = new View("View")
            {
                X      = Pos.AnchorEnd(10),
                Y      = Pos.AnchorEnd(1),
                Width  = 10,
                Height = 1
            };
            var cm = new ContextMenu(view,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            Application.Top.Add(view);
            Application.Begin(Application.Top);

            Assert.Equal(new Rect(70, 24, 10, 1), view.Frame);
            Assert.Equal(new Point(0, 0), cm.Position);

            cm.Show();
            Assert.Equal(new Point(70, 24), cm.Position);
            Application.Top.Redraw(Application.Top.Bounds);

            var expected = @"
                                                                      ┌──────┐
                                                                      │ One  │
                                                                      │ Two  │
                                                                      └──────┘
                                                                      View
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(70, 20, 78, 5), pos);

            cm.Hide();
            Assert.Equal(new Point(70, 24), cm.Position);
        }
Ejemplo n.º 7
0
        public void MenuItens_Changing()
        {
            var cm = new ContextMenu(10, 5,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            cm.Show();
            Application.Begin(Application.Top);

            var expected = @"
          ┌──────┐
          │ One  │
          │ Two  │
          └──────┘
";

            GraphViewTests.AssertDriverContentsAre(expected, output);

            cm.MenuItems = new MenuBarItem(new MenuItem [] {
                new MenuItem("First", "", null),
                new MenuItem("Second", "", null),
                new MenuItem("Third", "", null)
            });


            cm.Show();
            Application.Refresh();

            expected = @"
          ┌─────────┐
          │ First   │
          │ Second  │
          │ Third   │
          └─────────┘
";

            GraphViewTests.AssertDriverContentsAre(expected, output);
        }
Ejemplo n.º 8
0
        public void ForceMinimumPosToZero_True_False()
        {
            var cm = new ContextMenu(-1, -2,
                                     new MenuBarItem(new MenuItem [] {
                new MenuItem("One", "", null),
                new MenuItem("Two", "", null)
            })
                                     );

            Assert.Equal(new Point(-1, -2), cm.Position);

            cm.Show();
            Assert.Equal(new Point(-1, -2), cm.Position);
            Application.Begin(Application.Top);

            var expected = @"
┌──────┐
│ One  │
│ Two  │
└──────┘
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(0, 1, 8, 4), pos);

            cm.ForceMinimumPosToZero = false;
            cm.Show();
            Assert.Equal(new Point(-1, -2), cm.Position);
            Application.Refresh();

            expected = @"
 One  │
 Two  │
──────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(1, 0, 7, 3), pos);
        }
Ejemplo n.º 9
0
        public void ContextMenu_On_Toplevel_With_A_MenuBar_Window_TextField_StatusBar()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("File", "", null),
                new MenuBarItem("Edit", "", null)
            });

            var label = new Label("Label:")
            {
                X = 2,
                Y = 3
            };

            var tf = new TextField("TextField")
            {
                X     = Pos.Right(label) + 1,
                Y     = Pos.Top(label),
                Width = 20
            };

            var win = new Window("Window");

            win.Add(label, tf);

            var statusBar = new StatusBar(new StatusItem [] {
                new StatusItem(Key.F1, "~F1~ Help", null),
                new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", null)
            });

            Application.Top.Add(menu, win, statusBar);
            Application.Begin(Application.Top);
            ((FakeDriver)Application.Driver).SetBufferSize(44, 17);


            Assert.Equal(new Rect(9, 3, 20, 1), tf.Frame);
            Assert.True(tf.HasFocus);

            tf.ContextMenu.Show();
            Assert.True(ContextMenu.IsShow);
            Assert.Equal(new Point(10, 5), tf.ContextMenu.Position);
            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  File   Edit
┌ Window ──────────────────────────────────┐
│                                          │
│                                          │
│                                          │
│  Label: TextField                        │
│         ┌───────────────────────────┐    │
│         │ Select All         Ctrl+T │    │
│         │ Delete All   Ctrl+Shift+D │    │
│         │ Copy               Ctrl+C │    │
│         │ Cut                Ctrl+X │    │
│         │ Paste              Ctrl+V │    │
│         │ Undo               Ctrl+Z │    │
│         │ Redo               Ctrl+Y │    │
│         └───────────────────────────┘    │
└──────────────────────────────────────────┘
 F1 Help │ ^Q Quit
";

            var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);

            Assert.Equal(new Rect(2, 0, 44, 17), pos);
        }