Esempio n. 1
0
 public PosCombine(bool add, Pos left, Pos right)
 {
     this.left  = left;
     this.right = right;
     this.add   = add;
 }
Esempio n. 2
0
        void Initialize(Rect frame)
        {
            contentView = new View(frame);
            vertical    = new ScrollBarView(1, 0, isVertical: true)
            {
                X      = Pos.AnchorEnd(1),
                Y      = 0,
                Width  = 1,
                Height = Dim.Fill(showHorizontalScrollIndicator ? 1 : 0)
            };
            vertical.ChangedPosition += delegate {
                ContentOffset = new Point(ContentOffset.X, vertical.Position);
            };
            vertical.Host = this;
            horizontal    = new ScrollBarView(1, 0, isVertical: false)
            {
                X      = 0,
                Y      = Pos.AnchorEnd(1),
                Width  = Dim.Fill(showVerticalScrollIndicator ? 1 : 0),
                Height = 1
            };
            horizontal.ChangedPosition += delegate {
                ContentOffset = new Point(horizontal.Position, ContentOffset.Y);
            };
            horizontal.Host               = this;
            vertical.OtherScrollBarView   = horizontal;
            horizontal.OtherScrollBarView = vertical;
            base.Add(contentView);
            CanFocus = true;

            MouseEnter             += View_MouseEnter;
            MouseLeave             += View_MouseLeave;
            contentView.MouseEnter += View_MouseEnter;
            contentView.MouseLeave += View_MouseLeave;

            // Things this view knows how to do
            AddCommand(Command.ScrollUp, () => ScrollUp(1));
            AddCommand(Command.ScrollDown, () => ScrollDown(1));
            AddCommand(Command.ScrollLeft, () => ScrollLeft(1));
            AddCommand(Command.ScrollRight, () => ScrollRight(1));
            AddCommand(Command.PageUp, () => ScrollUp(Bounds.Height));
            AddCommand(Command.PageDown, () => ScrollDown(Bounds.Height));
            AddCommand(Command.PageLeft, () => ScrollLeft(Bounds.Width));
            AddCommand(Command.PageRight, () => ScrollRight(Bounds.Width));
            AddCommand(Command.TopHome, () => ScrollUp(contentSize.Height));
            AddCommand(Command.BottomEnd, () => ScrollDown(contentSize.Height));
            AddCommand(Command.LeftHome, () => ScrollLeft(contentSize.Width));
            AddCommand(Command.RightEnd, () => ScrollRight(contentSize.Width));

            // Default keybindings for this view
            AddKeyBinding(Key.CursorUp, Command.ScrollUp);
            AddKeyBinding(Key.CursorDown, Command.ScrollDown);
            AddKeyBinding(Key.CursorLeft, Command.ScrollLeft);
            AddKeyBinding(Key.CursorRight, Command.ScrollRight);

            AddKeyBinding(Key.PageUp, Command.PageUp);
            AddKeyBinding((Key)'v' | Key.AltMask, Command.PageUp);

            AddKeyBinding(Key.PageDown, Command.PageDown);
            AddKeyBinding(Key.V | Key.CtrlMask, Command.PageDown);

            AddKeyBinding(Key.PageUp | Key.CtrlMask, Command.PageLeft);
            AddKeyBinding(Key.PageDown | Key.CtrlMask, Command.PageRight);
            AddKeyBinding(Key.Home, Command.TopHome);
            AddKeyBinding(Key.End, Command.BottomEnd);
            AddKeyBinding(Key.Home | Key.CtrlMask, Command.LeftHome);
            AddKeyBinding(Key.End | Key.CtrlMask, Command.RightEnd);
        }
Esempio n. 3
0
        static int QueryFull(bool useErrorColors, int width, int height, ustring title, ustring message, params ustring [] buttons)
        {
            const int defaultWidth = 50;
            int       textWidth    = TextFormatter.MaxWidth(message, width == 0 ? defaultWidth : width);
            int       textHeight   = TextFormatter.MaxLines(message, textWidth); // 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.RuneCount + 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);
        }
Esempio n. 4
0
        public void LeftTopBottomRight_Win_ShouldNotThrow()
        {
            // Setup Fake driver
            (Window win, Button button) setup()
            {
                Application.Init(new FakeDriver(), new FakeMainLoop(() => 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);
        }
Esempio n. 5
0
        public void Center_SetsValue()
        {
            var pos = Pos.Center();

            Assert.Equal("Pos.Center", pos.ToString());
        }
Esempio n. 6
0
        public void New_Works()
        {
            var pos = new Pos();

            Assert.Equal("Terminal.Gui.Pos", pos.ToString());
        }
Esempio n. 7
0
        public void PosSide_SetsValue()
        {
            string side;             // used in format string
            var    testRect = Rect.Empty;
            var    testInt  = 0;
            Pos    pos;

            // Pos.Left
            side     = "x";
            testInt  = 0;
            testRect = Rect.Empty;
            pos      = Pos.Left(new View());
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            pos = Pos.Left(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testRect = new Rect(1, 2, 3, 4);
            pos      = Pos.Left(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Left(win) + 0
            pos = Pos.Left(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = 1;
            // Pos.Left(win) +1
            pos = Pos.Left(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = -1;
            // Pos.Left(win) -1
            pos = Pos.Left(new View(testRect)) - testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.X
            side     = "x";
            testInt  = 0;
            testRect = Rect.Empty;
            pos      = Pos.X(new View());
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            pos = Pos.X(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testRect = new Rect(1, 2, 3, 4);
            pos      = Pos.X(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.X(win) + 0
            pos = Pos.X(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = 1;
            // Pos.X(win) +1
            pos = Pos.X(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = -1;
            // Pos.X(win) -1
            pos = Pos.X(new View(testRect)) - testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Top
            side     = "y";
            testInt  = 0;
            testRect = Rect.Empty;
            pos      = Pos.Top(new View());
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            pos = Pos.Top(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testRect = new Rect(1, 2, 3, 4);
            pos      = Pos.Top(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Top(win) + 0
            pos = Pos.Top(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = 1;
            // Pos.Top(win) +1
            pos = Pos.Top(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = -1;
            // Pos.Top(win) -1
            pos = Pos.Top(new View(testRect)) - testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Y
            side     = "y";
            testInt  = 0;
            testRect = Rect.Empty;
            pos      = Pos.Y(new View());
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            pos = Pos.Y(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testRect = new Rect(1, 2, 3, 4);
            pos      = Pos.Y(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Y(win) + 0
            pos = Pos.Y(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = 1;
            // Pos.Y(win) +1
            pos = Pos.Y(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = -1;
            // Pos.Y(win) -1
            pos = Pos.Y(new View(testRect)) - testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Bottom
            side     = "bottom";
            testRect = Rect.Empty;
            testInt  = 0;
            pos      = Pos.Bottom(new View());
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            pos = Pos.Bottom(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testRect = new Rect(1, 2, 3, 4);
            pos      = Pos.Bottom(new View(testRect));
            Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            // Pos.Bottom(win) + 0
            pos = Pos.Bottom(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = 1;
            // Pos.Bottom(win) +1
            pos = Pos.Bottom(new View(testRect)) + testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());

            testInt = -1;
            // Pos.Bottom(win) -1
            pos = Pos.Bottom(new View(testRect)) - testInt;
            Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString());
        }
Esempio n. 8
0
        public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height()
        {
            // Testing with the Button because it properly handles the Dim class.

            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = 100,
                Height = 100
            };

            var f1 = new FrameView("f1")
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Percent(50),
                Height = 5
            };

            var f2 = new FrameView("f2")
            {
                X      = Pos.Right(f1),
                Y      = 0,
                Width  = Dim.Fill(),
                Height = 5
            };

            var v1 = new Button("v1")
            {
                X      = Pos.X(f1) + 2,
                Y      = Pos.Bottom(f1) + 2,
                Width  = Dim.Width(f1) - 2,
                Height = Dim.Fill() - 2
            };

            var v2 = new Button("v2")
            {
                X      = Pos.X(f2) + 2,
                Y      = Pos.Bottom(f2) + 2,
                Width  = Dim.Width(f2) - 2,
                Height = Dim.Fill() - 2
            };

            var v3 = new Button("v3")
            {
                Width  = Dim.Percent(10),
                Height = Dim.Percent(10)
            };

            var v4 = new Button("v4")
            {
                Width  = Dim.Sized(50),
                Height = Dim.Sized(50)
            };

            var v5 = new Button("v5")
            {
                Width  = Dim.Width(v1) - Dim.Width(v3),
                Height = Dim.Height(v1) - Dim.Height(v3)
            };

            var v6 = new Button("v6")
            {
                X      = Pos.X(f2),
                Y      = Pos.Bottom(f2) + 2,
                Width  = Dim.Percent(20, true),
                Height = Dim.Percent(20, true)
            };

            w.Add(f1, f2, v1, v2, v3, v4, v5, v6);
            t.Add(w);

            t.Ready += () => {
                Assert.Equal("Dim.Absolute(100)", w.Width.ToString());
                Assert.Equal("Dim.Absolute(100)", w.Height.ToString());
                Assert.Equal(100, w.Frame.Width);
                Assert.Equal(100, w.Frame.Height);

                Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f1.Height.ToString());
                Assert.Equal(49, f1.Frame.Width);                  // 50-1=49
                Assert.Equal(5, f1.Frame.Height);

                Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f2.Height.ToString());
                Assert.Equal(49, f2.Frame.Width);                  // 50-1=49
                Assert.Equal(5, f2.Frame.Height);

                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v1.Width.ToString());
                Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v1.Height.ToString());
                Assert.Equal(47, v1.Frame.Width);                  // 49-2=47
                Assert.Equal(89, v1.Frame.Height);                 // 98-5-2-2=89


                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=49,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v2.Width.ToString());
                Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v2.Height.ToString());
                Assert.Equal(47, v2.Frame.Width);                  // 49-2=47
                Assert.Equal(89, v2.Frame.Height);                 // 98-5-2-2=89

                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString());
                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Height.ToString());
                Assert.Equal(9, v3.Frame.Width);                  // 98*10%=9
                Assert.Equal(9, v3.Frame.Height);                 // 98*10%=9

                Assert.Equal("Dim.Absolute(50)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(50)", v4.Height.ToString());
                Assert.Equal(50, v4.Frame.Width);
                Assert.Equal(50, v4.Frame.Height);

                Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Width.ToString());
                Assert.Equal("Dim.Combine(DimView(side=Height, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Height, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Height.ToString());
                Assert.Equal(38, v5.Frame.Width);                  // 47-9=38
                Assert.Equal(80, v5.Frame.Height);                 // 89-9=80

                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString());
                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Height.ToString());
                Assert.Equal(9, v6.Frame.Width);                  // 47*20%=9
                Assert.Equal(18, v6.Frame.Height);                // 89*20%=18


                w.Width  = 200;
                w.Height = 200;
                t.LayoutSubviews();

                Assert.Equal("Dim.Absolute(200)", w.Width.ToString());
                Assert.Equal("Dim.Absolute(200)", w.Height.ToString());
                Assert.Equal(200, w.Frame.Width);
                Assert.Equal(200, w.Frame.Height);

                f1.Text = "Frame1";
                Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f1.Height.ToString());
                Assert.Equal(99, f1.Frame.Width);                  // 100-1=99
                Assert.Equal(5, f1.Frame.Height);

                f2.Text = "Frame2";
                Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString());
                Assert.Equal("Dim.Absolute(5)", f2.Height.ToString());
                Assert.Equal(99, f2.Frame.Width);                  // 100-1=99
                Assert.Equal(5, f2.Frame.Height);

                v1.Text = "Button1";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v1.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v1.Height.ToString());
                Assert.Equal(97, v1.Frame.Width);                  // 99-2=97
                Assert.Equal(1, v1.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v2.Text = "Button2";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=99,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v2.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v2.Height.ToString());
                Assert.Equal(97, v2.Frame.Width);                  // 99-2=97
                Assert.Equal(1, v2.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v3.Text = "Button3";
                Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v3.Height.ToString());
                Assert.Equal(19, v3.Frame.Width);                  // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
                Assert.Equal(1, v3.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v4.Text = "Button4";
                Assert.Equal("Dim.Absolute(11)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v4.Height.ToString());
                Assert.Equal(11, v4.Frame.Width);                  // 11 is the text length and because is Dim.DimAbsolute
                Assert.Equal(1, v4.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v5.Text = "Button5";
                Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=97,Height=1}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=19,Height=1})))", v5.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v5.Height.ToString());
                Assert.Equal(78, v5.Frame.Width);                  // 97-19=78
                Assert.Equal(1, v5.Frame.Height);                  // 1 because is Dim.DimAbsolute

                v6.Text = "Button6";
                Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v6.Height.ToString());
                Assert.Equal(19, v6.Frame.Width);                  // 99*20%=19
                Assert.Equal(1, v6.Frame.Height);                  // 1 because is Dim.DimAbsolute
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Computed"/> layout.
 /// </summary>
 /// <param name="host">The view that will host this scrollbar.</param>
 /// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal.</param>
 /// <param name="showBothScrollIndicator">If set to <c>true (default)</c> will have the other scrollbar, otherwise will have only one.</param>
 public ScrollBarView(View host, bool isVertical, bool showBothScrollIndicator = true) : this(0, 0, isVertical)
 {
     if (host == null)
     {
         throw new ArgumentNullException("The host parameter can't be null.");
     }
     else if (host.SuperView == null)
     {
         throw new ArgumentNullException("The host SuperView parameter can't be null.");
     }
     hosted      = true;
     ColorScheme = host.ColorScheme;
     X           = isVertical ? Pos.Right(host) - 1 : Pos.Left(host);
     Y           = isVertical ? Pos.Top(host) : Pos.Bottom(host) - 1;
     Host        = host;
     CanFocus    = false;
     Enabled     = host.Enabled;
     Visible     = host.Visible;
     //Host.CanFocusChanged += Host_CanFocusChanged;
     Host.EnabledChanged += Host_EnabledChanged;
     Host.VisibleChanged += Host_VisibleChanged;
     Host.SuperView.Add(this);
     AutoHideScrollBars = true;
     if (showBothScrollIndicator)
     {
         OtherScrollBarView = new ScrollBarView(0, 0, !isVertical)
         {
             ColorScheme        = host.ColorScheme,
             Host               = host,
             CanFocus           = false,
             Enabled            = host.Enabled,
             Visible            = host.Visible,
             OtherScrollBarView = this
         };
         OtherScrollBarView.hosted = true;
         OtherScrollBarView.X      = OtherScrollBarView.IsVertical ? Pos.Right(host) - 1 : Pos.Left(host);
         OtherScrollBarView.Y      = OtherScrollBarView.IsVertical ? Pos.Top(host) : Pos.Bottom(host) - 1;
         OtherScrollBarView.Host.SuperView.Add(OtherScrollBarView);
         OtherScrollBarView.showScrollIndicator = true;
     }
     ShowScrollIndicator      = true;
     contentBottomRightCorner = new View(" ")
     {
         Visible = host.Visible
     };
     Host.SuperView.Add(contentBottomRightCorner);
     contentBottomRightCorner.X           = Pos.Right(host) - 1;
     contentBottomRightCorner.Y           = Pos.Bottom(host) - 1;
     contentBottomRightCorner.Width       = 1;
     contentBottomRightCorner.Height      = 1;
     contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick;
 }
Esempio n. 10
0
        private void Initialize()
        {
            search.Changed += Search_Changed;

            listview.SelectedChanged += (object sender, ListViewItemEventArgs e) => {
                if (searchset.Count > 0)
                {
                    SetValue(searchset [listview.SelectedItem]);
                }
            };

            // TODO: LayoutComplete event breaks cursor up/down. Revert to Application.Loaded
            Application.Loaded += (sender, a) => {
                // Determine if this view is hosted inside a dialog
                for (View view = this.SuperView; view != null; view = view.SuperView)
                {
                    if (view is Dialog)
                    {
                        autoHide = false;
                        break;
                    }
                }

                searchset = autoHide ? new List <string> () : listsource;

                // Needs to be re-applied for LayoutStyle.Computed
                // If Dim or Pos are null, these are the from the parametrized constructor
                if (X == null)
                {
                    listview.X = x;
                }

                if (Y == null)
                {
                    listview.Y = y + 1;
                }
                else
                {
                    listview.Y = Pos.Bottom(search);
                }

                if (Width == null)
                {
                    listview.Width = CalculateWidth();
                }
                else
                {
                    width          = GetDimAsInt(Width);
                    listview.Width = CalculateWidth();
                }

                if (Height == null)
                {
                    listview.Height = CalculatetHeight();
                }
                else
                {
                    height          = GetDimAsInt(Height);
                    listview.Height = CalculatetHeight();
                }

                if (this.Text != null)
                {
                    Search_Changed(search, Text);
                }

                if (autoHide)
                {
                    listview.ColorScheme = Colors.Menu;
                }
                else
                {
                    search.ColorScheme = Colors.Menu;
                }
            };

            search.MouseClick += Search_MouseClick;

            this.Add(listview, search);
            this.SetFocus(search);
        }