Exemplo n.º 1
0
        public void DrawFrame_With_Positive_Positions()
        {
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem(new MenuItem [] {
                    new MenuItem("One", "", null),
                    new MenuItem("Two", "", null)
                })
            });

            Assert.Equal(Point.Empty, new Point(menu.Frame.X, menu.Frame.Y));

            menu.OpenMenu();
            Application.Begin(Application.Top);

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

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

            Assert.Equal(new Rect(0, 1, 8, 4), pos);
        }
Exemplo n.º 2
0
        public void HotKey_MenuBar_ProcessHotKey_Menu_ProcessKey()
        {
            var newAction  = false;
            var copyAction = false;

            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New", "", () => newAction = true)
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", () => copyAction = true)
                })
            });

            Application.Top.Add(menu);

            Assert.False(newAction);
            Assert.False(copyAction);

            Assert.True(menu.ProcessHotKey(new (Key.AltMask | Key.F, new KeyModifiers()
            {
                Alt = true
            })));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  File   Edit
┌──────┐
│ New  │
└──────┘
";

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

            Assert.Equal(new Rect(2, 0, 13, 4), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new (Key.N, null)));
            Application.MainLoop.MainIteration();
            Assert.True(newAction);

            Assert.True(menu.ProcessHotKey(new (Key.AltMask | Key.E, new KeyModifiers()
            {
                Alt = true
            })));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
       ┌───────┐
       │ Copy  │
       └───────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 16, 4), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new (Key.C, null)));
            Application.MainLoop.MainIteration();
            Assert.True(copyAction);
        }
Exemplo n.º 3
0
        public void MenuBar_ButtonPressed_Open_The_Menu_ButtonPressed_Again_Close_The_Menu()
        {
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("File", new MenuItem [] {
                    new MenuItem("New", "", null)
                }),
                new MenuBarItem("Edit", new MenuItem [] {
                    new MenuItem("Copy", "", null)
                })
            });

            Application.Top.Add(menu);

            Assert.True(menu.MouseEvent(new MouseEvent()
            {
                X = 1, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu
            }));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  File   Edit
┌──────┐
│ New  │
└──────┘
";

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

            Assert.Equal(new Rect(2, 0, 13, 4), pos);

            Assert.True(menu.MouseEvent(new MouseEvent()
            {
                X = 1, Y = 0, Flags = MouseFlags.Button1Pressed, View = menu
            }));
            Assert.False(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 13, 1), pos);
        }
Exemplo n.º 4
0
        public void Update_Parameterless_Only_On_Or_After_Initialize()
        {
            var btn = new Button()
            {
                X    = Pos.Center(),
                Y    = Pos.Center(),
                Text = "Say Hello 你"
            };
            var win = new Window()
            {
                Width  = Dim.Fill(),
                Height = Dim.Fill(),
                Title  = "Test Demo 你"
            };

            win.Add(btn);
            Application.Top.Add(win);

            Assert.False(btn.IsInitialized);

            Application.Begin(Application.Top);
            ((FakeDriver)Application.Driver).SetBufferSize(30, 5);

            Assert.True(btn.IsInitialized);
            Assert.Equal("Say Hello 你", btn.Text);
            Assert.Equal("[ Say Hello 你 ]", btn.TextFormatter.Text);
            Assert.Equal(new Rect(0, 0, 16, 1), btn.Bounds);

            var expected = @"
┌ Test Demo 你 ──────────────┐
│                            │
│      [ Say Hello 你 ]      │
│                            │
└────────────────────────────┘
";

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

            Assert.Equal(new Rect(0, 0, 30, 5), pos);
        }
Exemplo n.º 5
0
        public void UseSubMenusSingleFrame_True_By_Mouse()
        {
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("Numbers", new MenuItem [] {
                    new MenuItem("One", "", null),
                    new MenuBarItem("Two", new MenuItem [] {
                        new MenuItem("Sub-Menu 1", "", null),
                        new MenuItem("Sub-Menu 2", "", null)
                    }),
                    new MenuItem("Three", "", null),
                })
            });

            Application.Top.Add(menu);

            Assert.Equal(Point.Empty, new Point(menu.Frame.X, menu.Frame.Y));
            Assert.False(menu.UseSubMenusSingleFrame);
            menu.UseSubMenusSingleFrame = true;
            Assert.True(menu.UseSubMenusSingleFrame);

            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  Numbers
";

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

            Assert.Equal(new Rect(2, 0, 9, 1), pos);

            Assert.True(menu.MouseEvent(new MouseEvent()
            {
                X     = 1,
                Y     = 0,
                Flags = MouseFlags.Button1Pressed,
                View  = menu
            }));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌────────┐
│ One    │
│ Two   ►│
│ Three  │
└────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 10, 6), pos);

            Assert.False(menu.MouseEvent(new MouseEvent()
            {
                X     = 1,
                Y     = 3,
                Flags = MouseFlags.Button1Clicked,
                View  = Application.Top.Subviews [1]
            }));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌─────────────┐
│◄    Two     │
├─────────────┤
│ Sub-Menu 1  │
│ Sub-Menu 2  │
└─────────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 15, 7), pos);

            Assert.False(menu.MouseEvent(new MouseEvent()
            {
                X     = 1,
                Y     = 2,
                Flags = MouseFlags.Button1Clicked,
                View  = Application.Top.Subviews [2]
            }));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌────────┐
│ One    │
│ Two   ►│
│ Three  │
└────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 10, 6), pos);

            Assert.False(menu.MouseEvent(new MouseEvent()
            {
                X     = 70,
                Y     = 2,
                Flags = MouseFlags.Button1Clicked,
                View  = Application.Top
            }));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 9, 1), pos);
        }
Exemplo n.º 6
0
        public void UseSubMenusSingleFrame_True_By_Keyboard()
        {
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("Numbers", new MenuItem [] {
                    new MenuItem("One", "", null),
                    new MenuBarItem("Two", new MenuItem [] {
                        new MenuItem("Sub-Menu 1", "", null),
                        new MenuItem("Sub-Menu 2", "", null)
                    }),
                    new MenuItem("Three", "", null),
                })
            });

            Application.Top.Add(menu);

            Assert.Equal(Point.Empty, new Point(menu.Frame.X, menu.Frame.Y));
            Assert.False(menu.UseSubMenusSingleFrame);
            menu.UseSubMenusSingleFrame = true;
            Assert.True(menu.UseSubMenusSingleFrame);

            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  Numbers
";

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

            Assert.Equal(new Rect(2, 0, 9, 1), pos);

            Assert.True(menu.ProcessHotKey(new KeyEvent(Key.F9, null)));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌────────┐
│ One    │
│ Two   ►│
│ Three  │
└────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 10, 6), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new KeyEvent(Key.CursorDown, null)));
            Assert.True(Application.Top.Subviews [1].ProcessKey(new KeyEvent(Key.Enter, null)));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌─────────────┐
│◄    Two     │
├─────────────┤
│ Sub-Menu 1  │
│ Sub-Menu 2  │
└─────────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 15, 7), pos);

            Assert.True(Application.Top.Subviews [2].ProcessKey(new KeyEvent(Key.Enter, null)));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
┌────────┐
│ One    │
│ Two   ►│
│ Three  │
└────────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 10, 6), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new KeyEvent(Key.Esc, null)));
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  Numbers
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 9, 1), pos);
        }
Exemplo n.º 7
0
        public void DrawFrame_With_Negative_Positions()
        {
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem(new MenuItem [] {
                    new MenuItem("One", "", null),
                    new MenuItem("Two", "", null)
                })
            })
            {
                X = -1,
                Y = -1
            };

            Assert.Equal(new Point(-1, -1), new Point(menu.Frame.X, menu.Frame.Y));

            menu.OpenMenu();
            Application.Begin(Application.Top);

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

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

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

            menu.CloseAllMenus();
            menu.Frame = new Rect(-1, -2, menu.Frame.Width, menu.Frame.Height);
            menu.OpenMenu();
            Application.Refresh();

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

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(1, 0, 7, 3), pos);

            menu.CloseAllMenus();
            menu.Frame = new Rect(0, 0, menu.Frame.Width, menu.Frame.Height);
            ((FakeDriver)Application.Driver).SetBufferSize(7, 5);
            menu.OpenMenu();
            Application.Refresh();

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

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(0, 1, 7, 4), pos);

            menu.CloseAllMenus();
            menu.Frame = new Rect(0, 0, menu.Frame.Width, menu.Frame.Height);
            ((FakeDriver)Application.Driver).SetBufferSize(7, 4);
            menu.OpenMenu();
            Application.Refresh();

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

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(0, 1, 7, 3), pos);
        }
Exemplo n.º 8
0
        public void MenuBar_Position_And_Size_With_HotKeys_Is_The_Same_As_Without_HotKeys()
        {
            // With HotKeys
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New", "", null)
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", null)
                })
            });

            Application.Top.Add(menu);

            Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers())));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            var expected = @"
  File   Edit
┌──────┐
│ New  │
└──────┘
";

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

            Assert.Equal(new Rect(2, 0, 13, 4), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new (Key.CursorRight, null)));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
       ┌───────┐
       │ Copy  │
       └───────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 16, 4), pos);

            Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers())));
            Assert.False(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 13, 1), pos);

            // Without HotKeys
            menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("File", new MenuItem [] {
                    new MenuItem("New", "", null)
                }),
                new MenuBarItem("Edit", new MenuItem [] {
                    new MenuItem("Copy", "", null)
                })
            });

            Assert.True(menu.ProcessHotKey(new (Key.F9, new KeyModifiers())));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
┌──────┐
│ New  │
└──────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 13, 4), pos);

            Assert.True(Application.Top.Subviews [1].ProcessKey(new (Key.CursorRight, null)));
            Assert.True(menu.IsMenuOpen);
            Application.Top.Redraw(Application.Top.Bounds);
            expected = @"
  File   Edit
       ┌───────┐
       │ Copy  │
       └───────┘
";

            pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
            Assert.Equal(new Rect(2, 0, 16, 4), pos);
        }
Exemplo n.º 9
0
        public void Not_Setting_Child_Size_Default_AutoSize_True()
        {
            var top   = Application.Top;
            var win   = new Window();
            var label = new Label("Hello World")
            {
                ColorScheme   = Colors.TopLevel,
                Text          = "This is a test\nwith a \nPanelView",
                TextAlignment = TextAlignment.Centered
            };
            var pv = new PanelView(label)
            {
                Width  = 24,
                Height = 13,
                Border = new Border()
                {
                    BorderStyle     = BorderStyle.Single,
                    DrawMarginFrame = true,
                    BorderThickness = new Thickness(2),
                    BorderBrush     = Color.Red,
                    Padding         = new Thickness(2),
                    Background      = Color.BrightGreen,
                    Effect3D        = true
                },
            };

            win.Add(pv);
            top.Add(win);

            Application.Begin(top);

            Assert.Equal(new Rect(0, 0, 14, 3), label.Frame);
            Assert.Equal(new Rect(0, 0, 24, 13), pv.Frame);
            Assert.Equal(new Rect(0, 0, 80, 25), win.Frame);
            Assert.Equal(new Rect(0, 0, 80, 25), Application.Top.Frame);

            var expected = @"
┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│    ┌──────────────┐                                                          │
│    │This is a test│                                                          │
│    │   with a     │                                                          │
│    │  PanelView   │                                                          │
│    └──────────────┘                                                          │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
";

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

            Assert.Equal(new Rect(0, 0, 80, 25), pos);
        }