Exemplo n.º 1
0
        public void FocusNearestView_Ensure_Focus_Ordered()
        {
            var top = new Toplevel();

            var win        = new Window();
            var winSubview = new View("WindowSubview")
            {
                CanFocus = true
            };

            win.Add(winSubview);
            top.Add(win);

            var frm        = new FrameView();
            var frmSubview = new View("FrameSubview")
            {
                CanFocus = true
            };

            frm.Add(frmSubview);
            top.Add(frm);

            top.ProcessKey(new KeyEvent(Key.Tab, new KeyModifiers()));
            Assert.Equal($"WindowSubview", top.MostFocused.Text);
            top.ProcessKey(new KeyEvent(Key.Tab, new KeyModifiers()));
            Assert.Equal("FrameSubview", top.MostFocused.Text);
            top.ProcessKey(new KeyEvent(Key.Tab, new KeyModifiers()));
            Assert.Equal($"WindowSubview", top.MostFocused.Text);

            top.ProcessKey(new KeyEvent(Key.BackTab | Key.ShiftMask, new KeyModifiers()));
            Assert.Equal("FrameSubview", top.MostFocused.Text);
            top.ProcessKey(new KeyEvent(Key.BackTab | Key.ShiftMask, new KeyModifiers()));
            Assert.Equal($"WindowSubview", top.MostFocused.Text);
        }
Exemplo n.º 2
0
        public void CanFocus_Faced_With_Container()
        {
            var t = new Toplevel();
            var w = new Window();
            var f = new FrameView();
            var v = new View()
            {
                CanFocus = true
            };

            f.Add(v);
            w.Add(f);
            t.Add(w);

            Assert.True(t.CanFocus);
            Assert.True(w.CanFocus);
            Assert.True(f.CanFocus);
            Assert.True(v.CanFocus);

            f.CanFocus = false;
            Assert.False(f.CanFocus);
            Assert.True(v.CanFocus);

            v.CanFocus = false;
            Assert.False(f.CanFocus);
            Assert.False(v.CanFocus);

            v.CanFocus = true;
            Assert.False(f.CanFocus);
            Assert.True(v.CanFocus);
        }
Exemplo n.º 3
0
        public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException()
        {
            var top  = new Toplevel();
            var host = new View();

            top.Add(host);
            var v = new ScrollBarView(host, false);
            var h = new ScrollBarView(host, false);

            Assert.Throws <ArgumentException> (null, () => v.OtherScrollBarView = h);
            Assert.Throws <ArgumentException> (null, () => h.OtherScrollBarView = v);
        }
Exemplo n.º 4
0
        public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically()
        {
            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var t = new Toplevel()
            {
                Id = "0",
            };

            var w = new Window()
            {
                Id = "t", Width = Dim.Fill(), Height = Dim.Fill()
            };
            var v1 = new View()
            {
                Id = "v1", Width = Dim.Fill(), Height = Dim.Fill()
            };
            var v2 = new View()
            {
                Id = "v2", Width = Dim.Fill(), Height = Dim.Fill()
            };

            int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;

            t.Initialized += (s, e) => {
                tc++;
                Assert.Equal(1, tc);
                Assert.Equal(0, wc);
                Assert.Equal(0, v1c);
                Assert.Equal(0, v2c);
                Assert.Equal(0, sv1c);

                Assert.True(t.CanFocus);
                Assert.True(w.CanFocus);
                Assert.False(v1.CanFocus);
                Assert.False(v2.CanFocus);

                Application.Refresh();
            };
            w.Initialized += (s, e) => {
                wc++;
                Assert.Equal(t.Frame.Width, w.Frame.Width);
                Assert.Equal(t.Frame.Height, w.Frame.Height);
            };
            v1.Initialized += (s, e) => {
                v1c++;
                Assert.Equal(t.Frame.Width, v1.Frame.Width);
                Assert.Equal(t.Frame.Height, v1.Frame.Height);
            };
            v2.Initialized += (s, e) => {
                v2c++;
                Assert.Equal(t.Frame.Width, v2.Frame.Width);
                Assert.Equal(t.Frame.Height, v2.Frame.Height);
            };
            w.Add(v1, v2);
            t.Add(w);

            Application.Iteration = () => {
                var sv1 = new View()
                {
                    Id = "sv1", Width = Dim.Fill(), Height = Dim.Fill()
                };

                sv1.Initialized += (s, e) => {
                    sv1c++;
                    Assert.NotEqual(t.Frame.Width, sv1.Frame.Width);
                    Assert.NotEqual(t.Frame.Height, sv1.Frame.Height);
                    Assert.False(sv1.CanFocus);
                    sv1.CanFocus = true;
                    Assert.True(sv1.CanFocus);
                };

                v1.Add(sv1);

                Application.Refresh();
                t.Running = false;
            };

            Application.Run(t);
            Application.Shutdown();

            Assert.Equal(1, tc);
            Assert.Equal(1, wc);
            Assert.Equal(1, v1c);
            Assert.Equal(1, v2c);
            Assert.Equal(1, sv1c);

            Assert.True(t.CanFocus);
            Assert.True(w.CanFocus);
            Assert.False(v1.CanFocus);
            Assert.False(v2.CanFocus);
        }
Exemplo n.º 5
0
        public void Initialized_Event_Comparing_With_Added_Event()
        {
            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var t = new Toplevel()
            {
                Id = "0",
            };

            var w = new Window()
            {
                Id = "t", Width = Dim.Fill(), Height = Dim.Fill()
            };
            var v1 = new View()
            {
                Id = "v1", Width = Dim.Fill(), Height = Dim.Fill()
            };
            var v2 = new View()
            {
                Id = "v2", Width = Dim.Fill(), Height = Dim.Fill()
            };
            var sv1 = new View()
            {
                Id = "sv1", Width = Dim.Fill(), Height = Dim.Fill()
            };

            int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0;

            w.Added += (e) => {
                Assert.Equal(e.Frame.Width, w.Frame.Width);
                Assert.Equal(e.Frame.Height, w.Frame.Height);
            };
            v1.Added += (e) => {
                Assert.Equal(e.Frame.Width, v1.Frame.Width);
                Assert.Equal(e.Frame.Height, v1.Frame.Height);
            };
            v2.Added += (e) => {
                Assert.Equal(e.Frame.Width, v2.Frame.Width);
                Assert.Equal(e.Frame.Height, v2.Frame.Height);
            };
            sv1.Added += (e) => {
                Assert.Equal(e.Frame.Width, sv1.Frame.Width);
                Assert.Equal(e.Frame.Height, sv1.Frame.Height);
            };

            t.Initialized += (s, e) => {
                tc++;
                Assert.Equal(1, tc);
                Assert.Equal(1, wc);
                Assert.Equal(1, v1c);
                Assert.Equal(1, v2c);
                Assert.Equal(1, sv1c);

                Assert.True(t.CanFocus);
                Assert.True(w.CanFocus);
                Assert.False(v1.CanFocus);
                Assert.False(v2.CanFocus);
                Assert.False(sv1.CanFocus);

                Application.Refresh();
            };
            w.Initialized += (s, e) => {
                wc++;
                Assert.Equal(t.Frame.Width, w.Frame.Width);
                Assert.Equal(t.Frame.Height, w.Frame.Height);
            };
            v1.Initialized += (s, e) => {
                v1c++;
                Assert.Equal(t.Frame.Width, v1.Frame.Width);
                Assert.Equal(t.Frame.Height, v1.Frame.Height);
            };
            v2.Initialized += (s, e) => {
                v2c++;
                Assert.Equal(t.Frame.Width, v2.Frame.Width);
                Assert.Equal(t.Frame.Height, v2.Frame.Height);
            };
            sv1.Initialized += (s, e) => {
                sv1c++;
                Assert.Equal(t.Frame.Width, sv1.Frame.Width);
                Assert.Equal(t.Frame.Height, sv1.Frame.Height);
                Assert.False(sv1.CanFocus);
                Assert.Throws <InvalidOperationException> (() => sv1.CanFocus = true);
                Assert.False(sv1.CanFocus);
            };

            v1.Add(sv1);
            w.Add(v1, v2);
            t.Add(w);

            Application.Iteration = () => {
                Application.Refresh();
                t.Running = false;
            };

            Application.Run(t);
            Application.Shutdown();

            Assert.Equal(1, tc);
            Assert.Equal(1, wc);
            Assert.Equal(1, v1c);
            Assert.Equal(1, v2c);
            Assert.Equal(1, sv1c);

            Assert.True(t.CanFocus);
            Assert.True(w.CanFocus);
            Assert.False(v1.CanFocus);
            Assert.False(v2.CanFocus);
            Assert.False(sv1.CanFocus);

            v1.CanFocus = true;
            Assert.False(sv1.CanFocus);              // False because sv1 was disposed and it isn't a subview of v1.
        }