Ejemplo n.º 1
0
        public static Window generateWindow(Window baseWindow)
        {
            Window loginView = new Window(new Rect(0, 0, baseWindow.Frame.Width - 2, baseWindow.Frame.Height - 2), "Login");
            var    login     = new Label("Wallet Name: ")
            {
                X = 3, Y = 6
            };
            var password = new Label("Wallet Password: "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 40
            };
            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            var loginButton = new Button("Login")
            {
                X         = 3,
                Y         = 19,
                IsDefault = true,
                Clicked   = () => {
                    var subView = baseWindow.Subviews[0];
                    subView.RemoveAll();

                    var costView = DashboardView.generateWindow(baseWindow);
                    baseWindow.Add(costView);
                    costView.FocusFirst();
                    costView.LayoutSubviews();
                }
            };


            loginView.Add(
                new TextField(14, 2, 40, "Welcome to login view"),
                login,
                loginText,
                password,
                passText,
                loginButton
                );
            return(loginView);
        }
Ejemplo n.º 2
0
        public void DimCombine_Do_Not_Throws()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = Dim.Width(t) - 2,
                Height = Dim.Height(t) - 2
            };
            var f  = new FrameView("f");
            var v1 = new View("v1")
            {
                Width  = Dim.Width(w) - 2,
                Height = Dim.Height(w) - 2
            };
            var v2 = new View("v2")
            {
                Width  = Dim.Width(v1) - 2,
                Height = Dim.Height(v1) - 2
            };

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

            f.Width  = Dim.Width(t) - Dim.Width(v2);
            f.Height = Dim.Height(t) - Dim.Height(v2);

            t.Ready += () => {
                Assert.Equal(80, t.Frame.Width);
                Assert.Equal(25, t.Frame.Height);
                Assert.Equal(78, w.Frame.Width);
                Assert.Equal(23, w.Frame.Height);
                Assert.Equal(6, f.Frame.Width);
                Assert.Equal(6, f.Frame.Height);
                Assert.Equal(76, v1.Frame.Width);
                Assert.Equal(21, v1.Frame.Height);
                Assert.Equal(74, v2.Frame.Width);
                Assert.Equal(19, v2.Frame.Height);
            };

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

            Application.Run();
            Application.Shutdown();
        }
Ejemplo n.º 3
0
        public void Width_SetsValue()
        {
            var dim = Dim.Width(null);

            Assert.Throws <NullReferenceException> (() => dim.ToString());

            var testVal = Rect.Empty;

            testVal = Rect.Empty;
            dim     = Dim.Width(new View(testVal));
            Assert.Equal($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString());

            testVal = new Rect(1, 2, 3, 4);
            dim     = Dim.Width(new View(testVal));
            Assert.Equal($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString());
        }
Ejemplo n.º 4
0
        public void TopologicalSort_Missing_Add()
        {
            var root = new View();
            var sub1 = new View();

            root.Add(sub1);
            var sub2 = new View();

            sub1.Width = Dim.Width(sub2);

            Assert.Throws <InvalidOperationException> (() => root.LayoutSubviews());

            sub2.Width = Dim.Width(sub1);

            Assert.Throws <InvalidOperationException> (() => root.LayoutSubviews());
        }
Ejemplo n.º 5
0
        public InputSet(string name, int?valueWidth = null)
        {
            Name  = new FixedLengthLabel(name);
            Value = new TextField("")
            {
                X = Pos.Right(Name)
            };
            if (valueWidth != null)
            {
                Value.Width = valueWidth.Value;
            }

            Add(Name, Value);

            Width  = Dim.Width(Name) + Dim.Width(Value);
            Height = Name.Height;
        }
        public InputSetWithValidation(string name, string errorText, string successText, Predicate <string> validator, int?valueWidth = null) : base(name, valueWidth)
        {
            _validator   = validator;
            _errorText   = errorText;
            _successText = successText;
            ErrorText    = new FixedLengthLabel(errorText)
            {
                X         = Pos.Right(Value),
                Width     = errorText.Length,
                TextColor = _errorColor
            };

            Value.Changed += Value_Changed;

            Add(ErrorText);

            Width  = Dim.Width(Name) + Dim.Width(Value) + Dim.Width(ErrorText);
            Height = Name.Height;
        }
Ejemplo n.º 7
0
        public void Width_Equals()
        {
            var testRect1 = Rect.Empty;
            var view1     = new View(testRect1);
            var testRect2 = Rect.Empty;
            var view2     = new View(testRect2);

            var dim1 = Dim.Width(view1);
            var dim2 = Dim.Width(view1);

            // FIXED: Dim.Width should support Equals() and this should change to Equal.
            Assert.Equal(dim1, dim2);

            dim2 = Dim.Width(view2);
            Assert.NotEqual(dim1, dim2);

            testRect1 = new Rect(0, 1, 2, 3);
            view1     = new View(testRect1);
            testRect2 = new Rect(0, 1, 2, 3);
            dim1      = Dim.Width(view1);
            dim2      = Dim.Width(view1);
            // FIXED: Dim.Width should support Equals() and this should change to Equal.
            Assert.Equal(dim1, dim2);

            Assert.Throws <ArgumentException> (() => new Rect(0, -1, -2, -3));
            testRect1 = new Rect(0, -1, 2, 3);
            view1     = new View(testRect1);
            testRect2 = new Rect(0, -1, 2, 3);
            dim1      = Dim.Width(view1);
            dim2      = Dim.Width(view1);
            // FIXED: Dim.Width should support Equals() and this should change to Equal.
            Assert.Equal(dim1, dim2);

            testRect1 = new Rect(0, -1, 2, 3);
            view1     = new View(testRect1);
            testRect2 = Rect.Empty;
            view2     = new View(testRect2);
            dim1      = Dim.Width(view1);
            dim2      = Dim.Width(view2);
            Assert.NotEqual(dim1, dim2);
        }
Ejemplo n.º 8
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the MessageBox will be sized automatically.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextView()
            {
                Text        = "Message",
                X           = Pos.Right(label) + 1,
                Y           = Pos.Top(label),
                Width       = Dim.Fill(),
                Height      = 5,
                ColorScheme = Colors.Dialog,
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(messageEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                           + Dim.Height(numButtonsEdit) + Dim.Height(styleRadioGroup) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 2,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label("")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 4,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
                Clicked   = () => {
                    try {
                        int width      = int.Parse(widthEdit.Text.ToString());
                        int height     = int.Parse(heightEdit.Text.ToString());
                        int numButtons = int.Parse(numButtonsEdit.Text.ToString());

                        var btns = new List <ustring> ();
                        for (int i = 0; i < numButtons; i++)
                        {
                            btns.Add(btnText[i % 10]);
                        }
                        if (styleRadioGroup.SelectedItem == 0)
                        {
                            buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                        else
                        {
                            buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                    } catch (FormatException) {
                        buttonPressedLabel.Text = "Invalid Options";
                    }
                },
            };

            Win.Add(showMessageBoxButton);

            Win.Add(buttonPressedLabel);
        }
        public TicketPrintScreenView() : base("Chhota Kashmir Boat Club")
        {
            window = new Window(" -- Print Ticket -- ");
            this.Add(window);

            // Ticket Type Controls
            lblTicketTypesHeader = new Label("Ticket Types:")
            {
                X = 1, Y = 1
            };
            lblTicketTypes = new Label("[B]oat / [T]rain / [M]erry-Go-Round / Moon [W]alker / [K]angaroo / C[a]terpillar / [C]ar")
            {
                X = 1, Y = 2
            };

            lblTicketSelection = new Label("Ticket Selection : ")
            {
                X = 1, Y = 4
            };
            txtTicketSelection = new TextField("")
            {
                X = 20, Y = 4, Width = 2
            };
            lblTicketSelectionDisplay = new Label("")
            {
                X = 23, Y = 4
            };

            ticketTypeView = new FrameView("Ticket Type")
            {
                X = 1, Y = 1, Height = 8, Width = Dim.Width(this) - 5
            };
            ticketTypeView.Add(lblTicketTypesHeader, lblTicketTypes, lblTicketSelection, txtTicketSelection, lblTicketSelectionDisplay);

            // Ticket Details Controls
            lblAdultCount = new Label("No. of Adults : ")
            {
                Y = 1
            };
            txtAdultCount = new TextField("")
            {
                X = 18, Y = 1, Width = 3
            };
            lblChildCount = new Label("No. of Children : ")
            {
                Y = 3
            };
            txtChildCount = new TextField("")
            {
                X = 18, Y = 3, Width = 3
            };
            lblTotal = new Label("Total Bill Amount : ")
            {
                Y = 6
            };
            txtTotal = new Label("")
            {
                X = 20, Y = 6, Width = 5
            };
            ticketDetailsView = new FrameView("Ticket Details")
            {
                X = 1, Y = 11, Width = Dim.Width(this) - 5, Height = 10
            };
            ticketDetailsView.Add(lblAdultCount, txtAdultCount, lblChildCount, txtChildCount, lblTotal, txtTotal);

            btnPrint = new Button("_Print Ticket")
            {
                X = 1, Y = 26
            };
            btnCancel = new Button("_Cancel")
            {
                X = 27, Y = 26
            };
            btnBack = new Button("_Back")
            {
                X = 18, Y = 26
            };
            window.Add(ticketTypeView, ticketDetailsView, btnPrint, btnCancel, btnBack);

            // Link event handlers.
            txtTicketSelection.Changed += TxtTicketSelection_Changed;
            txtAdultCount.Changed      += TxtAdultCount_Changed;
            txtChildCount.Changed      += TxtChildCount_Changed;

            btnCancel.Clicked = BtnCancel_Clicked;
            btnBack.Clicked   = BtnBack_Clicked;
            btnPrint.Clicked  = BtnPrint_Clicked;
        }
Ejemplo n.º 10
0
        public DynamicMenuBarSample(ustring title) : base(title)
        {
            DataContext = new DynamicMenuItemModel();

            var _frmMenu = new FrameView("Menus:")
            {
                Y      = 7,
                Width  = Dim.Percent(50),
                Height = Dim.Fill()
            };

            var _btnAddMenuBar = new Button("Add a MenuBar")
            {
                Y = 1,
            };

            _frmMenu.Add(_btnAddMenuBar);

            var _btnMenuBarUp = new Button("^")
            {
                X = Pos.Center()
            };

            _frmMenu.Add(_btnMenuBarUp);

            var _btnMenuBarDown = new Button("v")
            {
                X = Pos.Center(),
                Y = Pos.Bottom(_btnMenuBarUp)
            };

            _frmMenu.Add(_btnMenuBarDown);

            var _btnRemoveMenuBar = new Button("Remove a MenuBar")
            {
                Y = 1
            };

            _btnRemoveMenuBar.X = Pos.AnchorEnd() - (Pos.Right(_btnRemoveMenuBar) - Pos.Left(_btnRemoveMenuBar));
            _frmMenu.Add(_btnRemoveMenuBar);

            var _btnPrevious = new Button("<")
            {
                X = Pos.Left(_btnAddMenuBar),
                Y = Pos.Top(_btnAddMenuBar) + 2
            };

            _frmMenu.Add(_btnPrevious);

            var _btnAdd = new Button(" Add  ")
            {
                Y = Pos.Top(_btnPrevious) + 2,
            };

            _btnAdd.X = Pos.AnchorEnd() - (Pos.Right(_btnAdd) - Pos.Left(_btnAdd));
            _frmMenu.Add(_btnAdd);

            var _btnNext = new Button(">")
            {
                X = Pos.X(_btnAdd),
                Y = Pos.Top(_btnPrevious),
            };

            _frmMenu.Add(_btnNext);

            var _lblMenuBar = new Label()
            {
                ColorScheme   = Colors.Dialog,
                TextAlignment = TextAlignment.Centered,
                X             = Pos.Right(_btnPrevious) + 1,
                Y             = Pos.Top(_btnPrevious),
                Width         = Dim.Fill() - Dim.Width(_btnAdd) - 1,
                Height        = 1
            };

            _frmMenu.Add(_lblMenuBar);
            _lblMenuBar.WantMousePositionReports = true;
            _lblMenuBar.CanFocus = true;

            var _lblParent = new Label()
            {
                TextAlignment = TextAlignment.Centered,
                X             = Pos.Right(_btnPrevious) + 1,
                Y             = Pos.Top(_btnPrevious) + 1,
                Width         = Dim.Fill() - Dim.Width(_btnAdd) - 1
            };

            _frmMenu.Add(_lblParent);

            var _btnPreviowsParent = new Button("..")
            {
                X = Pos.Left(_btnAddMenuBar),
                Y = Pos.Top(_btnPrevious) + 1
            };

            _frmMenu.Add(_btnPreviowsParent);

            var _lstMenus = new ListView(new List <DynamicMenuItemList> ())
            {
                ColorScheme = Colors.Dialog,
                X           = Pos.Right(_btnPrevious) + 1,
                Y           = Pos.Top(_btnPrevious) + 2,
                Width       = _lblMenuBar.Width,
                Height      = Dim.Fill(),
            };

            _frmMenu.Add(_lstMenus);

            _lblMenuBar.TabIndex = _btnPrevious.TabIndex + 1;
            _lstMenus.TabIndex   = _lblMenuBar.TabIndex + 1;
            _btnNext.TabIndex    = _lstMenus.TabIndex + 1;
            _btnAdd.TabIndex     = _btnNext.TabIndex + 1;

            var _btnRemove = new Button("Remove")
            {
                X = Pos.Left(_btnAdd),
                Y = Pos.Top(_btnAdd) + 1
            };

            _frmMenu.Add(_btnRemove);

            var _btnUp = new Button("^")
            {
                X = Pos.Right(_lstMenus) + 2,
                Y = Pos.Top(_btnRemove) + 2
            };

            _frmMenu.Add(_btnUp);

            var _btnDown = new Button("v")
            {
                X = Pos.Right(_lstMenus) + 2,
                Y = Pos.Top(_btnUp) + 1
            };

            _frmMenu.Add(_btnDown);

            Add(_frmMenu);

            var _frmMenuDetails = new FrameView("Menu Details:")
            {
                X      = Pos.Right(_frmMenu),
                Y      = Pos.Top(_frmMenu),
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            var _lblTitle = new Label("Title:")
            {
                Y = 1
            };

            _frmMenuDetails.Add(_lblTitle);

            var _txtTitle = new TextField()
            {
                X     = Pos.Right(_lblTitle) + 2,
                Y     = Pos.Top(_lblTitle),
                Width = Dim.Fill()
            };

            _frmMenuDetails.Add(_txtTitle);

            var _lblHelp = new Label("Help:")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_lblTitle) + 1
            };

            _frmMenuDetails.Add(_lblHelp);

            var _txtHelp = new TextField()
            {
                X     = Pos.Left(_txtTitle),
                Y     = Pos.Top(_lblHelp),
                Width = Dim.Fill()
            };

            _frmMenuDetails.Add(_txtHelp);

            var _lblAction = new Label("Action:")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_lblHelp) + 1
            };

            _frmMenuDetails.Add(_lblAction);

            var _txtAction = new TextView()
            {
                ColorScheme = Colors.Dialog,
                X           = Pos.Left(_txtTitle),
                Y           = Pos.Top(_lblAction),
                Width       = Dim.Fill(),
                Height      = 5
            };

            _frmMenuDetails.Add(_txtAction);

            var _ckbIsTopLevel = new CheckBox("IsTopLevel")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_lblAction) + 5
            };

            _frmMenuDetails.Add(_ckbIsTopLevel);

            var _ckbSubMenu = new CheckBox("Has sub-menus")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_ckbIsTopLevel)
            };

            _frmMenuDetails.Add(_ckbSubMenu);
            _ckbIsTopLevel.Toggled = (e) => {
                if (_ckbIsTopLevel.Checked && _currentEditMenuBarItem.Parent != null)
                {
                    MessageBox.ErrorQuery("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok");
                    _ckbIsTopLevel.Checked = false;
                    return;
                }
                if (_ckbIsTopLevel.Checked)
                {
                    _ckbSubMenu.Checked = false;
                    _ckbSubMenu.SetNeedsDisplay();
                    _txtAction.ReadOnly = false;
                }
                else
                {
                    _txtAction.ReadOnly = true;
                }
            };
            _ckbSubMenu.Toggled = (e) => {
                if (_ckbSubMenu.Checked)
                {
                    _ckbIsTopLevel.Checked = false;
                    _ckbIsTopLevel.SetNeedsDisplay();
                    _txtAction.ReadOnly = true;
                }
                else
                {
                    _txtAction.ReadOnly = false;
                }
            };

            var _rChkLabels = new ustring [] { "NoCheck", "Checked", "Radio" };
            var _rbChkStyle = new RadioGroup(_rChkLabels)
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_ckbSubMenu) + 1,
            };

            _frmMenuDetails.Add(_rbChkStyle);

            var _btnOk = new Button("Ok")
            {
                X       = Pos.Left(_lblTitle) + 20,
                Y       = Pos.Bottom(_rbChkStyle) + 1,
                Clicked = () => {
                    if (ustring.IsNullOrEmpty(_txtTitle.Text) && _currentEditMenuBarItem != null)
                    {
                        MessageBox.ErrorQuery("Invalid title", "Must enter a valid title!.", "Ok");
                    }
                    else if (_currentEditMenuBarItem != null)
                    {
                        var menuItem = new DynamicMenuItem(_txtTitle.Text, _txtHelp.Text, _txtAction.Text, _ckbIsTopLevel != null ? _ckbIsTopLevel.Checked : false, _ckbSubMenu != null ? _ckbSubMenu.Checked : false, _rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck : _rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked : MenuItemCheckStyle.Radio);
                        UpdateMenuItem(_currentEditMenuBarItem, menuItem, _lstMenus.SelectedItem);
                    }
                }
            };

            _frmMenuDetails.Add(_btnOk);

            var _btnCancel = new Button("Cancel")
            {
                X       = Pos.Right(_btnOk) + 3,
                Y       = Pos.Top(_btnOk),
                Clicked = () => {
                    _txtTitle.Text = ustring.Empty;
                }
            };

            _frmMenuDetails.Add(_btnCancel);

            Add(_frmMenuDetails);

            _btnAdd.Clicked = () => {
                if (MenuBar == null)
                {
                    MessageBox.ErrorQuery("Menu Bar Error", "Must add a MenuBar first!", "Ok");
                    _btnAddMenuBar.SetFocus();
                    return;
                }

                var item = EnterMenuItem(_currentMenuBarItem);
                if (ustring.IsNullOrEmpty(item.title))
                {
                    return;
                }

                if (!(_currentMenuBarItem is MenuBarItem))
                {
                    var parent = _currentMenuBarItem.Parent as MenuBarItem;
                    var idx    = parent.GetChildrenIndex(_currentMenuBarItem);
                    _currentMenuBarItem           = new MenuBarItem(_currentMenuBarItem.Title, new MenuItem [] { new MenuItem("_New", "", CreateAction(_currentEditMenuBarItem, new DynamicMenuItem())) }, _currentMenuBarItem.Parent);
                    _currentMenuBarItem.CheckType = item.checkStyle;
                    parent.Children [idx]         = _currentMenuBarItem;
                }
                else
                {
                    MenuItem newMenu     = CreateNewMenu(item, _currentMenuBarItem);
                    var      menuBarItem = _currentMenuBarItem as MenuBarItem;
                    if (menuBarItem == null)
                    {
                        menuBarItem = new MenuBarItem(_currentMenuBarItem.Title, new MenuItem [] { newMenu }, _currentMenuBarItem.Parent);
                    }
                    else if (menuBarItem.Children == null)
                    {
                        menuBarItem.Children = new MenuItem [] { newMenu };
                    }
                    else
                    {
                        var childrens = menuBarItem.Children;
                        Array.Resize(ref childrens, childrens.Length + 1);
                        childrens [childrens.Length - 1] = newMenu;
                        menuBarItem.Children             = childrens;
                    }
                    DataContext.Menus.Add(new DynamicMenuItemList(newMenu.Title, newMenu));
                    _lstMenus.MoveDown();
                }
            };

            _btnRemove.Clicked = () => {
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    childrens [_lstMenus.SelectedItem] = null;
                    int i = 0;
                    foreach (var c in childrens)
                    {
                        if (c != null)
                        {
                            childrens [i] = c;
                            i++;
                        }
                    }
                    Array.Resize(ref childrens, childrens.Length - 1);
                    if (childrens.Length == 0)
                    {
                        if (_currentMenuBarItem.Parent == null)
                        {
                            ((MenuBarItem)_currentMenuBarItem).Children = null;
                            _currentMenuBarItem.Action = CreateAction(_currentEditMenuBarItem, new DynamicMenuItem(_currentMenuBarItem.Title));
                        }
                        else
                        {
                            _currentMenuBarItem = new MenuItem(_currentMenuBarItem.Title, _currentMenuBarItem.Help, CreateAction(_currentEditMenuBarItem, new DynamicMenuItem(_currentEditMenuBarItem.Title)), null, _currentMenuBarItem.Parent);
                        }
                    }
                    else
                    {
                        ((MenuBarItem)_currentMenuBarItem).Children = childrens;
                    }
                    DataContext.Menus.RemoveAt(_lstMenus.SelectedItem);
                }
            };

            _btnMenuBarUp.Clicked = () => {
                var i        = _currentSelectedMenuBar;
                var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
                if (menuItem != null)
                {
                    var menus = _menuBar.Menus;
                    if (i > 0)
                    {
                        menus [i]               = menus [i - 1];
                        menus [i - 1]           = menuItem;
                        _currentSelectedMenuBar = i - 1;
                        _menuBar.SetNeedsDisplay();
                    }
                }
            };

            _btnMenuBarDown.Clicked = () => {
                var i        = _currentSelectedMenuBar;
                var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
                if (menuItem != null)
                {
                    var menus = _menuBar.Menus;
                    if (i < menus.Length - 1)
                    {
                        menus [i]               = menus [i + 1];
                        menus [i + 1]           = menuItem;
                        _currentSelectedMenuBar = i + 1;
                        _menuBar.SetNeedsDisplay();
                    }
                }
            };

            _btnUp.Clicked = () => {
                var i        = _lstMenus.SelectedItem;
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    if (i > 0)
                    {
                        childrens [i]             = childrens [i - 1];
                        childrens [i - 1]         = menuItem;
                        DataContext.Menus [i]     = DataContext.Menus [i - 1];
                        DataContext.Menus [i - 1] = new DynamicMenuItemList(menuItem.Title, menuItem);
                        _lstMenus.SelectedItem    = i - 1;
                    }
                }
            };

            _btnDown.Clicked = () => {
                var i        = _lstMenus.SelectedItem;
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    if (i < childrens.Length - 1)
                    {
                        childrens [i]             = childrens [i + 1];
                        childrens [i + 1]         = menuItem;
                        DataContext.Menus [i]     = DataContext.Menus [i + 1];
                        DataContext.Menus [i + 1] = new DynamicMenuItemList(menuItem.Title, menuItem);
                        _lstMenus.SelectedItem    = i + 1;
                    }
                }
            };

            _btnAddMenuBar.Clicked = () => {
                var item = EnterMenuItem(null);
                if (ustring.IsNullOrEmpty(item.title))
                {
                    return;
                }

                if (MenuBar == null)
                {
                    _menuBar = new MenuBar();
                    Add(_menuBar);
                }
                var newMenu = CreateNewMenu(item) as MenuBarItem;

                var menus = _menuBar.Menus;
                Array.Resize(ref menus, menus.Length + 1);
                menus [^ 1]                              = newMenu;
Ejemplo n.º 11
0
        public static Window generateWindow(Window baseWindow)
        {
            Window sendKrateWindow = new Window(new Rect(0, 0, baseWindow.Frame.Width - 2, baseWindow.Frame.Height - 2), "Send Krates");

            var payToLabel = new Label("Pay to: ")
            {
                X = 1, Y = 1
            };
            var LabelLabel = new Label("Label: ")
            {
                X = Pos.Left(payToLabel),
                Y = Pos.Bottom(payToLabel) + 1
            };
            var AmountLabel = new Label("Amount: ")
            {
                X = Pos.Left(LabelLabel),
                Y = Pos.Bottom(LabelLabel) + 1
            };
            var payToText = new TextField("")
            {
                X     = Pos.Right(LabelLabel),
                Y     = Pos.Top(payToLabel),
                Width = 40
            };
            var LabelText = new TextField("")
            {
                X     = Pos.Left(payToText),
                Y     = Pos.Top(LabelLabel),
                Width = Dim.Width(payToText)
            };
            var AmountText = new TextField("")
            {
                X     = Pos.Left(LabelText),
                Y     = Pos.Top(AmountLabel),
                Width = Dim.Width(LabelText)
            };

            var subtractFreeCheckbox = new CheckBox("Subtract fee from account?", true)
            {
                X = Pos.Left(AmountLabel),
                Y = Pos.Bottom(AmountLabel) + 1
            };

            var sendKratesButton = new Button("Send")
            {
                X         = Pos.Left(AmountText),
                Y         = 10,
                IsDefault = true,
                Clicked   = () =>
                {
                    var resp = Utility.Post("URL");
                }
            };

            var clearButton = new Button("Clear")
            {
                X         = Pos.Right(sendKratesButton) + 15,
                Y         = 10,
                IsDefault = true,
                Clicked   = () => {
                    var subView = baseWindow.Subviews[0];
                    subView.RemoveAll();

                    var sendView = SendView.generateWindow(baseWindow);
                    baseWindow.Add(sendView);
                    sendView.FocusFirst();
                    sendView.LayoutSubviews();
                }
            };


            sendKrateWindow.Add(payToLabel, LabelLabel, AmountLabel, payToText, LabelText, AmountText, subtractFreeCheckbox, sendKratesButton, clearButton);

            return(sendKrateWindow);
        }
Ejemplo n.º 12
0
        public override void Setup()
        {
            var s         = "TAB to jump between text fields.";
            var textField = new TextField(s)
            {
                X     = 1,
                Y     = 1,
                Width = Dim.Percent(50),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(textField);

            var labelMirroringTextField = new Label(textField.Text)
            {
                X     = Pos.Right(textField) + 1,
                Y     = Pos.Top(textField),
                Width = Dim.Fill(1)
            };

            Win.Add(labelMirroringTextField);

            textField.TextChanged += (prev) => {
                labelMirroringTextField.Text = textField.Text;
            };

            var textView = new TextView()
            {
                X           = 1,
                Y           = 3,
                Width       = Dim.Percent(50),
                Height      = Dim.Percent(30),
                ColorScheme = Colors.Dialog
            };

            textView.Text = s;
            Win.Add(textView);

            var labelMirroringTextView = new Label(textView.Text)
            {
                X      = Pos.Right(textView) + 1,
                Y      = Pos.Top(textView),
                Width  = Dim.Fill(1),
                Height = Dim.Height(textView),
            };

            Win.Add(labelMirroringTextView);

            textView.TextChanged += () => {
                labelMirroringTextView.Text = textView.Text;
            };

            var btnMultiline = new Button("Toggle Multiline")
            {
                X = Pos.Right(textView) + 1,
                Y = Pos.Top(textView) + 1
            };

            btnMultiline.Clicked += () => textView.Multiline = !textView.Multiline;
            Win.Add(btnMultiline);

            // BUGBUG: 531 - TAB doesn't go to next control from HexView
            var hexView = new HexView(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                X      = 1,
                Y      = Pos.Bottom(textView) + 1,
                Width  = Dim.Fill(1),
                Height = Dim.Percent(30),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(hexView);

            var dateField = new DateField(System.DateTime.Now)
            {
                X     = 1,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };

            Win.Add(dateField);

            var labelMirroringDateField = new Label(dateField.Text)
            {
                X      = Pos.Right(dateField) + 1,
                Y      = Pos.Top(dateField),
                Width  = Dim.Width(dateField),
                Height = Dim.Height(dateField),
            };

            Win.Add(labelMirroringDateField);

            dateField.TextChanged += (prev) => {
                labelMirroringDateField.Text = dateField.Text;
            };

            _timeField = new TimeField(DateTime.Now.TimeOfDay)
            {
                X     = Pos.Right(labelMirroringDateField) + 5,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };
            Win.Add(_timeField);

            _labelMirroringTimeField = new Label(_timeField.Text)
            {
                X      = Pos.Right(_timeField) + 1,
                Y      = Pos.Top(_timeField),
                Width  = Dim.Width(_timeField),
                Height = Dim.Height(_timeField),
            };
            Win.Add(_labelMirroringTimeField);

            _timeField.TimeChanged += TimeChanged;

            // MaskedTextProvider
            var netProviderLabel = new Label(".Net MaskedTextProvider [ 999 000 LLL >LLL| AAA aaa ]")
            {
                X = Pos.Left(dateField),
                Y = Pos.Bottom(dateField) + 1
            };

            Win.Add(netProviderLabel);

            var netProvider = new NetMaskedTextProvider("999 000 LLL > LLL | AAA aaa");

            var netProviderField = new TextValidateField(netProvider)
            {
                X = Pos.Right(netProviderLabel) + 1,
                Y = Pos.Y(netProviderLabel)
            };

            Win.Add(netProviderField);

            // TextRegexProvider
            var regexProvider = new Label("Gui.cs TextRegexProvider [ ^([0-9]?[0-9]?[0-9]|1000)$ ]")
            {
                X = Pos.Left(netProviderLabel),
                Y = Pos.Bottom(netProviderLabel) + 1
            };

            Win.Add(regexProvider);

            var provider2 = new TextRegexProvider("^([0-9]?[0-9]?[0-9]|1000)$")
            {
                ValidateOnInput = false
            };
            var regexProviderField = new TextValidateField(provider2)
            {
                X             = Pos.Right(regexProvider) + 1,
                Y             = Pos.Y(regexProvider),
                Width         = 30,
                TextAlignment = TextAlignment.Centered
            };

            Win.Add(regexProviderField);
        }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            Application.Init();
            var top = Application.Top;
            // Creates the top-level window to show
            var win = new Window("DZ_3")
            {
                X = 0,
                Y = 0, // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);

            var frameView = new FrameView("How to")
            {
                X      = 1,
                Y      = 1,
                Width  = Dim.Fill() - 1,
                Height = 9
            };

            frameView.Add(
                new Label(1, 0, "'v' - Объединение"),
                new Label(1, 1, "'^' - Пересечение"),
                new Label(1, 2, "'-' - Отрицание"),
                new Label(1, 3, "'\\' - Вычитание"),
                new Label(1, 4, "В множествах A,B,C,D запятые расставляются автоматически"),
                new Label(1, 5, "В множествах X и Y обсалютно всё можно прописывать маленькими буквами"),
                new Label(1, 6, "Calc - посчитать. Save - Сохранить в файл.")
                );

            var aLabel = new Label("A:")
            {
                X = 1,
                Y = Pos.Bottom(frameView) + 1
            };
            var aText = new TextField("befkt")
            {
                X     = Pos.Right(aLabel),
                Y     = Pos.Top(aLabel),
                Width = 19
            };

            var bLabel = new Label("B:")
            {
                X = 1,
                Y = Pos.Bottom(aLabel) + 1
            };
            var bText = new TextField("fijpy")
            {
                X     = Pos.Right(bLabel),
                Y     = Pos.Top(bLabel),
                Width = Dim.Width(aText)
            };

            var cLabel = new Label("С:")
            {
                X = 1,
                Y = Pos.Bottom(bLabel) + 1
            };
            var cText = new TextField("jkly")
            {
                X     = Pos.Right(cLabel),
                Y     = Pos.Top(cLabel),
                Width = Dim.Width(aText)
            };

            var dLabel = new Label("D:")
            {
                X = 1,
                Y = Pos.Bottom(cLabel) + 1
            };
            var dText = new TextField("ijstuyz")
            {
                X     = Pos.Right(dLabel),
                Y     = Pos.Top(dLabel),
                Width = Dim.Width(aText)
            };

            // Add some controls,
            win.Add(
                // The ones with my favorite layout system, Computed
                frameView,
                aLabel,
                aText,
                bLabel,
                bText,
                cLabel,
                cText,
                dLabel,
                dText
                );

            var xLabel = new Label("X:")
            {
                X = 1,
                Y = Pos.Bottom(dLabel) + 2
            };
            var xText = new TextField("(A^C)v(B^C)")
            {
                X     = Pos.Right(xLabel),
                Y     = Pos.Top(xLabel),
                Width = Dim.Width(aText)
            };

            var yLabel = new Label("Y:")
            {
                X = 1,
                Y = Pos.Bottom(xLabel) + 1
            };
            var yText = new TextField("(A^-B)v(D\\C)")
            {
                X     = Pos.Right(yLabel),
                Y     = Pos.Top(yLabel),
                Width = Dim.Width(aText)
            };
            var button = new Button("Calc!")
            {
                HotKey = Key.AltMask | Key.ControlC,
                X      = 1,
                Y      = Pos.Bottom(yLabel) + 1
            };

            button.Clicked += () =>
            {
                var text = $"A={aText.Text};B={bText.Text};C={cText.Text};D={dText.Text};X={xText.Text.ToUpper()};Y={yText.Text.ToUpper()}";

                text = text.Replace(" ", "").Replace("\n", "");

                try
                {
                    FillArrayList(text);

                    var strX = "";
                    foreach (var c in X)
                    {
                        strX += $"{c}, ";
                    }
                    if (!string.IsNullOrEmpty(strX))
                    {
                        strX = strX.Remove(strX.Length - 2, 2);
                    }
                    var strY = "";
                    foreach (var c in Y)
                    {
                        strY += $"{c}, ";
                    }
                    if (!string.IsNullOrEmpty(strY))
                    {
                        strY = strY.Remove(strY.Length - 2, 2);
                    }
                    MessageBox.Query(60, 6, "Result", $"X = ({strX})\nY = ({strY})", "Ok");
                }
                catch (Exception e)
                {
                    MessageBox.Query(60, 10, "Error", $"{e.Message}\n{e.Source}", "Ok");
                    return;
                }
            };
            var button2 = new Button("Save!")
            {
                HotKey = Key.AltMask | Key.ControlS,
                X      = Pos.Right(button) + 1,
                Y      = Pos.Bottom(yLabel) + 1
            };

            button2.Clicked += () =>
            {
                FileMeneger fileMeneger = new FileMeneger();

                var text = $"A={aText.Text};B={bText.Text};C={cText.Text};D={dText.Text};X={xText.Text.ToUpper()};Y={yText.Text.ToUpper()}";
                text = text.Replace(" ", "").Replace("\n", "");
                try
                {
                    FillArrayList(text);
                }
                catch (Exception e)
                {
                    MessageBox.Query(60, 10, "Error", $"{e.Message}\n{e.Source}", "Ok");
                    return;
                }
                string[] row = new string[4];
                row[0] = aText.Text.ToString();
                row[1] = bText.Text.ToString();
                row[2] = cText.Text.ToString();
                row[3] = dText.Text.ToString();
                for (int i = 0; i < 4; i++)
                {
                    row[i] = string.Join <char>(", ", row[i]) + ",";
                    row[i] = row[i].Remove(row[i].Length - 1);
                }
                fileMeneger.StringSave($"A = {{{row[0]}}}; B = {{{row[1]}}}; C = {{{row[2]}}}; D = {{{row[3]}}};");
                fileMeneger.StringSave($"X = { xText.Text.ToUpper().ToString().Replace('^', '\u2229').Replace('V', '\u222A')};");
                string tempX = xText.Text.ToUpper().ToString();
                string resX  = "";
                while (tempX.IndexOf('(') != -1)
                {
                    int    indexStart = tempX.IndexOf('(');
                    int    indexStop  = tempX.IndexOf(')') + 1;
                    string scope      = tempX.Substring(indexStart, indexStop);
                    var    strX       = "";
                    foreach (var c in Calc(scope))
                    {
                        strX += $"{c}, ";
                    }
                    if (!string.IsNullOrEmpty(strX))
                    {
                        strX = strX.Remove(strX.Length - 2, 2);
                    }
                    if (strX.Length == 0)
                    {
                        resX += $"{scope} = \u2205;\n";
                    }
                    else
                    {
                        resX += $"{scope} = {{{strX}}};\n";
                    }
                    if (indexStop != tempX.Length)
                    {
                        tempX = tempX.Substring(indexStop + 1);
                    }
                    else
                    {
                        tempX = "";
                    }
                }
                //
                string strX2 = "";
                foreach (var c in X)
                {
                    strX2 += $"{c}, ";
                }
                if (!string.IsNullOrEmpty(strX2))
                {
                    strX2 = strX2.Remove(strX2.Length - 2, 2);
                }
                string strY2 = "";
                foreach (var c in Y)
                {
                    strY2 += $"{c}, ";
                }
                if (!string.IsNullOrEmpty(strY2))
                {
                    strY2 = strY2.Remove(strY2.Length - 2, 2);
                }
                //
                if (strX2.Length == 0)
                {
                    resX += $"X = { xText.Text.ToUpper()} = \u2205;";
                }
                else
                {
                    resX += $"X = { xText.Text.ToUpper()} = {{{strX2}}};";
                }
                resX = resX.Replace('^', '\u2229').Replace('V', '\u222A');
                fileMeneger.StringSave(resX);

                fileMeneger.StringSave($"\nY = { yText.Text.ToUpper().ToString().Replace('^', '\u2229').Replace('V', '\u222A')};");
                string tempY = yText.Text.ToUpper().ToString();
                string resY  = "";
                while (tempY.IndexOf('(') != -1)
                {
                    int    indexStart = tempY.IndexOf('(');
                    int    indexStop  = tempY.IndexOf(')') + 1;
                    string scope      = tempY.Substring(indexStart, indexStop);
                    var    strY       = "";
                    foreach (var c in Calc(scope))
                    {
                        strY += $"{c}, ";
                    }
                    if (!string.IsNullOrEmpty(strY))
                    {
                        strY = strY.Remove(strY.Length - 2, 2);
                    }
                    if (strY.Length == 0)
                    {
                        resY += $"{scope} = \u2205;\n";
                    }
                    else
                    {
                        resY += $"{scope} = {{{strY}}};\n";
                    }
                    if (indexStop != tempY.Length)
                    {
                        tempY = tempY.Substring(indexStop + 1);
                    }
                    else
                    {
                        tempY = "";
                    }
                }
                if (strY2.Length == 0)
                {
                    resY += $"Y = { yText.Text.ToUpper()} = \u2205;";
                }
                else
                {
                    resY += $"Y = { yText.Text.ToUpper()} = {{{strY2}}};";
                }
                resY = resY.Replace('^', '\u2229').Replace('V', '\u222A');
                fileMeneger.StringSave(resY);

                var Mes = MessageBox.Query(60, 6, "Success", $"Data add to File: \"{Directory.GetCurrentDirectory()}\\Answer.txt\"!", "Ok!");
                fileMeneger.FileClose();
            };

            win.Add(
                xLabel,
                xText,
                yLabel,
                yText,
                button,
                button2
                );
            Application.Run();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
#if NETCOREAPP || NETFRAMEWORK
            Application.Init();
            var top = Application.Top;

            // Creates the top-level window to show
            var win = new Window("MyApp")
            {
                X = 0,
                Y = 1,                   // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };
            top.Add(win);
            var proxy = new Label("Proxy: ")
            {
                X = 3, Y = 2
            };
            var port = new Label("Prox.Port.: ")
            {
                X = Pos.Left(proxy),
                Y = Pos.Top(proxy) + 1
            };
            var target = new Label("Target:     ")
            {
                X = Pos.Left(proxy),
                Y = Pos.Top(proxy) + 2
            };
            var proxyText = new TextField("")
            {
                X     = Pos.Right(target),
                Y     = Pos.Top(proxy),
                Width = 40
            };
            var portText = new TextField("3128")
            {
                X     = Pos.Right(target),
                Y     = Pos.Top(port),
                Width = 40
            };
            var targetText = new TextField("google.com:443")
            {
                X     = Pos.Left(proxyText),
                Y     = Pos.Top(target),
                Width = Dim.Width(proxyText)
            };
            var login = new Label("Login: "******"Password:   "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 40
            };
            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };
            var UseAuth = new CheckBox(3, 6, "Use Proxy Auth (Basic)");
            var TestBtn = new Button(3, 14, "Test", is_default: true)
            {
                Clicked = () => { try{ RunProxy(proxyText.Text.ToString(), Int32.Parse(portText.Text.ToString()), targetText.Text.ToString()); } finally{} }
            };
            var ExitBtn = new Button(14, 14, "Exit")
            {
                Clicked = () => { Application.RequestStop(); }
            };
            win.Add(
                proxy, target, port, proxyText, portText, targetText, login, password, loginText, passText, UseAuth, TestBtn, ExitBtn
                );

            Application.Run();
            Console.WriteLine("Hello World!");
        }
Ejemplo n.º 15
0
    static void ShowEntries(View container)
    {
        var scrollView = new ScrollView(new Rect(50, 10, 20, 8))
        {
            ContentSize   = new Size(100, 100),
            ContentOffset = new Point(-1, -1),
            ShowVerticalScrollIndicator   = true,
            ShowHorizontalScrollIndicator = true
        };

        scrollView.Add(new Box10x(0, 0));
        //scrollView.Add (new Filler (new Rect (0, 0, 40, 40)));

        // This is just to debug the visuals of the scrollview when small
        var scrollView2 = new ScrollView(new Rect(72, 10, 3, 3))
        {
            ContentSize = new Size(100, 100),
            ShowVerticalScrollIndicator   = true,
            ShowHorizontalScrollIndicator = true
        };

        scrollView2.Add(new Box10x(0, 0));
        var progress = new ProgressBar(new Rect(68, 1, 10, 1));

        bool timer(MainLoop caller)
        {
            progress.Pulse();
            return(true);
        }

        Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(300), timer);


        // A little convoluted, this is because I am using this to test the
        // layout based on referencing elements of another view:

        var login = new Label("Login: "******"Password: "******"")
        {
            X     = Pos.Right(password),
            Y     = Pos.Top(login),
            Width = 40
        };
        var passText = new TextField("")
        {
            Secret = true,
            X      = Pos.Left(loginText),
            Y      = Pos.Top(password),
            Width  = Dim.Width(loginText)
        };

        // Add some content
        container.Add(
            login,
            loginText,
            password,
            passText,
            new FrameView(new Rect(3, 10, 25, 6), "Options")
        {
            new CheckBox(1, 0, "Remember me"),
            new RadioGroup(1, 2, new [] { "_Personal", "_Company" }),
        },
            new ListView(new Rect(60, 6, 16, 4), new string [] {
            "First row",
            "<>",
            "This is a very long row that should overflow what is shown",
            "4th",
            "There is an empty slot on the second row",
            "Whoa",
            "This is so cool"
        }),
            scrollView,
            //scrollView2,
            new Button(3, 19, "Ok"),
            new Button(10, 19, "Cancel"),
            progress,
            new Label(3, 22, "Press ESC and 9 to activate the menubar")
            );
    }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            Application.Init();
            var top = Application.Top;

            var win = new Window("MyApp")
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill(),
            };

            top.Add(win);

            var menu = new MenuBar(new MenuBarItem[] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New", "Creates new file", NewFile),
                    new MenuItem("_Close", "", () => Close()),
                    new MenuItem("_Quit", "", () => { if (Quit())
                                                      {
                                                          top.Running = false;
                                                      }
                                 })
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", null),
                    new MenuItem("C_ut", "", null),
                    new MenuItem("_Paste", "", null)
                })
            });

            top.Add(menu);

            var login = new Label("Login: "******"Password: "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 40
            };
            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            var rect = new Rect()
            {
                X      = 3,
                Y      = 6,
                Width  = 113,
                Height = 17
            };
            var display = new TextView(rect);

            display.ColorScheme = Colors.Menu;

            var inputTextField = new TextField("")
            {
                X     = 3,
                Y     = Pos.Bottom(display) + 1,
                Width = 105
            };
            var sendButton = new Button("送信")
            {
                X     = Pos.Right(inputTextField),
                Y     = Pos.Top(inputTextField),
                Width = 6
            };

            win.Add(
                login,
                password,
                loginText,
                passText,
                display,
                inputTextField,
                sendButton
                );


            Application.Run();
        }
        public ReportsView() : base("Chhota Kashmir Boating Club")
        {
            window = new Window(" -- Reports -- ");
            this.Add(window);

            btnBack = new Button("_Back")
            {
                X = 1,
                Y = 29
            };
            btnPrintReport = new Button("_Print Report")
            {
                X = 10,
                Y = 29
            };

            //Init Controls
            lblReportRange = new Label("Fetch Reports for Date : ")
            {
                X = 1,
                Y = 1
            };
            txtReportRange = new TextField("")
            {
                X     = 26,
                Y     = 1,
                Width = 11
            };
            btnGetReport = new Button("Get Reports")
            {
                X = 1,
                Y = 4,
            };

            // Report Results View
            vwReportHeader = new FrameView("[Please enter a date]")
            {
                X      = 1,
                Y      = 6,
                Height = 23,
                Width  = Dim.Width(this) - 5
            };
            lblTypeTitle = new Label("Type")
            {
                Y = 1,
                X = 2,
            };
            lblAdultCountTitle = new Label("|Adl")
            {
                Y = 1,
                X = 20
            };
            lblChildCountTitle = new Label("|Chi")
            {
                Y = 1,
                X = 24
            };
            lblTotalTitle = new Label("|Tot |")
            {
                Y = 1,
                X = 28
            };

            vwReportResults = new FrameView("")
            {
                Y      = 2,
                Height = 19,
                Width  = Dim.Width(this) - 7
            };

            lblboatH = new Label("Boat")
            {
                X = 1,
                Y = 1
            };
            lblboatA = new Label("---")
            {
                X     = 20,
                Y     = 1,
                Width = 3
            };
            lblboatC = new Label("---")
            {
                X     = 24,
                Y     = 1,
                Width = 3
            };
            lblboatT = new Label("---")
            {
                X     = 28,
                Y     = 1,
                Width = 3
            };

            lbltrainH = new Label("Train")
            {
                X = 1,
                Y = 3
            };
            lbltrainA = new Label("---")
            {
                X     = 20,
                Y     = 3,
                Width = 3
            };
            lbltrainC = new Label("---")
            {
                X     = 24,
                Y     = 3,
                Width = 3
            };
            lbltrainT = new Label("---")
            {
                X     = 28,
                Y     = 3,
                Width = 3
            };

            lblmgrH = new Label("Merry-Go-Round")
            {
                X = 1,
                Y = 5
            };
            lblmgrA = new Label("---")
            {
                X     = 20,
                Y     = 5,
                Width = 3
            };
            lblmgrC = new Label("---")
            {
                X     = 24,
                Y     = 5,
                Width = 3
            };
            lblmgrT = new Label("---")
            {
                X     = 28,
                Y     = 5,
                Width = 3
            };

            lblmwalkH = new Label("Moon Walker")
            {
                X = 1,
                Y = 7
            };
            lblmwalkA = new Label("---")
            {
                X     = 20,
                Y     = 7,
                Width = 3
            };
            lblmwalkC = new Label("---")
            {
                X     = 24,
                Y     = 7,
                Width = 3
            };
            lblmwalkT = new Label("---")
            {
                X     = 28,
                Y     = 7,
                Width = 3
            };

            lblkangarooH = new Label("Kangaroo")
            {
                X = 1,
                Y = 9
            };
            lblkangarooA = new Label("---")
            {
                X     = 20,
                Y     = 9,
                Width = 3
            };
            lblkangarooC = new Label("---")
            {
                X     = 24,
                Y     = 9,
                Width = 3
            };
            lblkangarooT = new Label("---")
            {
                X     = 28,
                Y     = 9,
                Width = 3
            };

            lblcaterpH = new Label("Caterpillar")
            {
                X = 1,
                Y = 11
            };
            lblcaterpA = new Label("---")
            {
                X     = 20,
                Y     = 11,
                Width = 3
            };
            lblcaterpC = new Label("---")
            {
                X     = 24,
                Y     = 11,
                Width = 3
            };
            lblcaterpT = new Label("---")
            {
                X     = 28,
                Y     = 11,
                Width = 3
            };

            lblcarH = new Label("Car")
            {
                X = 1,
                Y = 13
            };
            lblcarA = new Label("---")
            {
                X     = 20,
                Y     = 13,
                Width = 3
            };
            lblcarC = new Label("---")
            {
                X     = 24,
                Y     = 13,
                Width = 3
            };
            lblcarT = new Label("---")
            {
                X     = 28,
                Y     = 13,
                Width = 3
            };
            lblgrandtotalH = new Label("Grand Total")
            {
                X = 1,
                Y = 15
            };
            lblgrandtotalT = new Label("----")
            {
                X     = 25,
                Y     = 15,
                Width = 6
            };

            vwReportResults.Add(lblboatH, lblboatA, lblboatC, lblboatT,
                                lbltrainH, lbltrainA, lbltrainC, lbltrainT,
                                lblmgrH, lblmgrA, lblmgrC, lblmgrT,
                                lblmwalkH, lblmwalkA, lblmwalkC, lblmwalkT,
                                lblkangarooH, lblkangarooA, lblkangarooC, lblkangarooT,
                                lblcaterpH, lblcaterpA, lblcaterpC, lblcaterpT,
                                lblcarH, lblcarA, lblcarC, lblcarT,
                                lblgrandtotalH, lblgrandtotalT);

            vwReportHeader.Add(lblTypeTitle, lblAdultCountTitle, lblChildCountTitle, lblTotalTitle, vwReportResults);

            window.Add(lblReportRange, txtReportRange, btnGetReport, btnBack, btnPrintReport, vwReportHeader);

            //Link Event Handlers
            txtReportRange.Changed += TxtReportRange_Changed;
            btnBack.Clicked         = () =>
            {
                Toplevel mainmenuLevel = new Toplevel()
                {
                    X      = Application.Top.X,
                    Y      = Application.Top.Y,
                    Height = Dim.Fill(),
                    Width  = Dim.Fill()
                };

                mainmenuLevel.Add(new MainMenuView());

                Application.RequestStop();

                Application.Top.RemoveAll();
                Application.Top.Add(mainmenuLevel);
                Application.Top.FocusFirst();
                Application.Top.LayoutSubviews();

                Application.Run(mainmenuLevel);
            };
            btnGetReport.Clicked = () =>
            {
                if (ValidateDate(txtReportRange.Text.ToString()))
                {
                    int adultCount  = 0;
                    int childCount  = 0;
                    int totalAmount = 0;
                    int grandTotal  = 0;

                    string formattedDate = FormatDateString(txtReportRange.Text.ToString());

                    vwReportHeader.Title = "Reports for " + txtReportRange.Text.ToString();

                    // Update Boat
                    GetReportData(formattedDate, "Boat", out adultCount, out childCount, out totalAmount);
                    lblboatA.Text = adultCount.ToString();
                    lblboatC.Text = childCount.ToString();
                    lblboatT.Text = totalAmount.ToString();
                    grandTotal   += totalAmount;

                    // Update Train
                    GetReportData(formattedDate, "Train", out adultCount, out childCount, out totalAmount);
                    lbltrainA.Text = adultCount.ToString();
                    lbltrainC.Text = childCount.ToString();
                    lbltrainT.Text = totalAmount.ToString();
                    grandTotal    += totalAmount;

                    // Update Merry-Go-Round
                    GetReportData(formattedDate, "Merry-Go-Round", out adultCount, out childCount, out totalAmount);
                    lblmgrA.Text = adultCount.ToString();
                    lblmgrC.Text = childCount.ToString();
                    lblmgrT.Text = totalAmount.ToString();
                    grandTotal  += totalAmount;

                    // Update Moon Walker
                    GetReportData(formattedDate, "Moon Walker", out adultCount, out childCount, out totalAmount);
                    lblmwalkA.Text = adultCount.ToString();
                    lblmwalkC.Text = childCount.ToString();
                    lblmwalkT.Text = totalAmount.ToString();
                    grandTotal    += totalAmount;

                    // Update Kangaroo
                    GetReportData(formattedDate, "Kangaroo", out adultCount, out childCount, out totalAmount);
                    lblkangarooA.Text = adultCount.ToString();
                    lblkangarooC.Text = childCount.ToString();
                    lblkangarooT.Text = totalAmount.ToString();
                    grandTotal       += totalAmount;

                    // Update Caterpillar
                    GetReportData(formattedDate, "Caterpillar", out adultCount, out childCount, out totalAmount);
                    lblcaterpA.Text = adultCount.ToString();
                    lblcaterpC.Text = childCount.ToString();
                    lblcaterpT.Text = totalAmount.ToString();
                    grandTotal     += totalAmount;

                    // Update Car
                    GetReportData(formattedDate, "Car", out adultCount, out childCount, out totalAmount);
                    lblcarA.Text = adultCount.ToString();
                    lblcarC.Text = childCount.ToString();
                    lblcarT.Text = totalAmount.ToString();
                    grandTotal  += totalAmount;

                    // Update Grand Total
                    lblgrandtotalT.Text = grandTotal.ToString();

                    // Update State
                    IsReportPopulated = true;
                }
                else
                {
                    MessageBox.ErrorQuery(44, 10, "Error!", "Invalid Date", "Ok");
                    FocusPrev();
                }
            };
            btnPrintReport.Clicked = () =>
            {
                if (IsReportPopulated)
                {
                    ReportPrintService ps = new ReportPrintService(PopulatePrintData(), txtReportRange.Text.ToString());
                    if (ps.SetupPrinter())
                    {
                        MessageBox.Query(44, 10, "Success!", "Report Printing...", "Ok");
                        ps.PrintDocument.Print();
                    }
                }
                else
                {
                    MessageBox.ErrorQuery(44, 10, "Error!", "Input Report Date", "Ok");
                }
            };

            //Initialize Page state
            IsReportPopulated = false;
        }
Ejemplo n.º 18
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the MessageBox will be sized automatically.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextView()
            {
                Text        = "Message",
                X           = Pos.Right(label) + 1,
                Y           = Pos.Top(label),
                Width       = Dim.Fill(),
                Height      = 5,
                ColorScheme = Colors.Dialog,
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(messageEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Default Button:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var defaultButtonEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(defaultButtonEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            var border = new Border()
            {
                Effect3D    = true,
                BorderStyle = BorderStyle.Single
            };
            var ckbEffect3D = new CheckBox("Effect3D", true)
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label) + 2
            };

            ckbEffect3D.Toggled += (e) => {
                border.Effect3D = !e;
            };
            frame.Add(ckbEffect3D);

            void Top_Loaded()
            {
                frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                               + Dim.Height(numButtonsEdit) + Dim.Height(defaultButtonEdit) + Dim.Height(styleRadioGroup) + 2 + Dim.Height(ckbEffect3D);
                Top.Loaded -= Top_Loaded;
            }

            Top.Loaded += Top_Loaded;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 5,
                Width         = 25,
                Height        = 1,
                ColorScheme   = Colors.Error,
                TextAlignment = Terminal.Gui.TextAlignment.Centered
            };

            //var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showMessageBoxButton.Clicked += () => {
                try {
                    int width         = int.Parse(widthEdit.Text.ToString());
                    int height        = int.Parse(heightEdit.Text.ToString());
                    int numButtons    = int.Parse(numButtonsEdit.Text.ToString());
                    int defaultButton = int.Parse(defaultButtonEdit.Text.ToString());

                    var btns = new List <ustring> ();
                    for (int i = 0; i < numButtons; i++)
                    {
                        //btns.Add(btnText[i % 10]);
                        btns.Add(NumberToWords.Convert(i));
                    }
                    if (styleRadioGroup.SelectedItem == 0)
                    {
                        buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                    else
                    {
                        buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showMessageBoxButton);

            Win.Add(buttonPressedLabel);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Application.Init();
            var top = Application.Top;

            // Creates the top-level window to show
            var win = new Window("MyApp")
            {
                X = 0,
                Y = 1, // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);

            // Creates a menubar, the item "New" has a help menu.
            var menu = new MenuBar(new MenuBarItem[] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New", "Creates new file", () => MessageBox.Query("Create new file", "I would have created a new file here.", "OK")),
                    new MenuItem("_Close", "", () => MessageBox.Query("Close", "I would have closed here", "OK")),
                    new MenuItem("_Quit", "", () => Application.Shutdown())
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", null),
                    new MenuItem("C_ut", "", null),
                    new MenuItem("_Paste", "", null)
                })
            });

            top.Add(menu);

            var login = new Label("Login: "******"Password: "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 40
            };
            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            // Add some controls,
            win.Add(
                // The ones with my favorite layout system
                login, password, loginText, passText,

                // The ones laid out like an australopithecus, with absolute positions:
                new CheckBox(3, 6, "Remember me"),
                new RadioGroup(3, 8, new NStack.ustring[] { "_Personal", "_Company" }, selected: 0),
                new Button(3, 14, "Ok"),
                new Button(10, 14, "Cancel"),
                new Label(3, 18, "Press F9 or ESC plus 9 to activate the menubar"));

            Application.Run();
        }
Ejemplo n.º 20
0
        public override void Setup()
        {
            var s         = "TAB to jump between text fields.";
            var textField = new TextField(s)
            {
                X     = 1,
                Y     = 1,
                Width = Dim.Percent(50),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(textField);

            var labelMirroringTextField = new Label(textField.Text)
            {
                X     = Pos.Right(textField) + 1,
                Y     = Pos.Top(textField),
                Width = Dim.Fill(1)
            };

            Win.Add(labelMirroringTextField);

            textField.TextChanged += (prev) => {
                labelMirroringTextField.Text = textField.Text;
            };

            var textView = new TextView()
            {
                X           = 1,
                Y           = 3,
                Width       = Dim.Percent(50),
                Height      = Dim.Percent(30),
                ColorScheme = Colors.Dialog
            };

            textView.Text = s;
            Win.Add(textView);

            var labelMirroringTextView = new Label(textView.Text)
            {
                X      = Pos.Right(textView) + 1,
                Y      = Pos.Top(textView),
                Width  = Dim.Fill(1),
                Height = Dim.Height(textView),
            };

            Win.Add(labelMirroringTextView);

            textView.TextChanged += () => {
                labelMirroringTextView.Text = textView.Text;
            };

            // BUGBUG: 531 - TAB doesn't go to next control from HexView
            var hexView = new HexView(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s)))
            {
                X      = 1,
                Y      = Pos.Bottom(textView) + 1,
                Width  = Dim.Fill(1),
                Height = Dim.Percent(30),
                //ColorScheme = Colors.Dialog
            };

            Win.Add(hexView);

            var dateField = new DateField(System.DateTime.Now)
            {
                X     = 1,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };

            Win.Add(dateField);

            var labelMirroringDateField = new Label(dateField.Text)
            {
                X      = Pos.Right(dateField) + 1,
                Y      = Pos.Top(dateField),
                Width  = Dim.Width(dateField),
                Height = Dim.Height(dateField),
            };

            Win.Add(labelMirroringDateField);

            dateField.TextChanged += (prev) => {
                labelMirroringDateField.Text = dateField.Text;
            };

            _timeField = new TimeField(DateTime.Now.TimeOfDay)
            {
                X     = Pos.Right(labelMirroringDateField) + 5,
                Y     = Pos.Bottom(hexView) + 1,
                Width = 20,
                //ColorScheme = Colors.Dialog,
                IsShortFormat = false
            };
            Win.Add(_timeField);

            _labelMirroringTimeField = new Label(_timeField.Text)
            {
                X      = Pos.Right(_timeField) + 1,
                Y      = Pos.Top(_timeField),
                Width  = Dim.Width(_timeField),
                Height = Dim.Height(_timeField),
            };
            Win.Add(_labelMirroringTimeField);

            _timeField.TimeChanged += TimeChanged;
        }
Ejemplo n.º 21
0
        public override void Setup()
        {
            var frame = new FrameView("Dialog Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the Dialog will size to 80% of container.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(titleEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit)
                           + Dim.Height(numButtonsEdit) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 5,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            //var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
            var showDialogButton = new Button("Show Dialog")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showDialogButton.Clicked += () => {
                try {
                    int width      = int.Parse(widthEdit.Text.ToString());
                    int height     = int.Parse(heightEdit.Text.ToString());
                    int numButtons = int.Parse(numButtonsEdit.Text.ToString());

                    var buttons = new List <Button> ();
                    var clicked = -1;
                    for (int i = 0; i < numButtons; i++)
                    {
                        var buttonId = i;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                    }

                    // This tests dynamically adding buttons; ensuring the dialog resizes if needed and
                    // the buttons are laid out correctly
                    var dialog = new Dialog(titleEdit.Text, width, height,
                                            buttons.ToArray());
                    var add = new Button("Add a button")
                    {
                        X = Pos.Center(),
                        Y = Pos.Center()
                    };
                    add.Clicked += () => {
                        var buttonId = buttons.Count;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                        dialog.AddButton(button);
                        button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1;
                    };
                    dialog.Add(add);

                    Application.Run(dialog);
                    buttonPressedLabel.Text = $"{clicked}";
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showDialogButton);

            Win.Add(buttonPressedLabel);
        }
Ejemplo n.º 22
0
        public void Show(Toplevel top, User user)
        {
            // Creates the top-level window to show
            var win = new Window("CPN app")
            {
                X = 0,
                Y = 1,                 // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);


            var logo = new StringBuilder();


            logo.AppendLine("   ▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒   ");
            logo.AppendLine(" ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
            logo.AppendLine("░▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒       ▓▓▓▓▓     ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒         ▓▓▓     ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒          ▓▓     ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒     ▓           ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒     ▓▓          ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒     ▓▓▓▓        ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▒     ▓▓▓▓▓▓      ░▓▓▓▓▓");
            logo.AppendLine("▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
            logo.AppendLine(" ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
            logo.AppendLine("  ▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ");
            logo.AppendLine("            ▓▓▓▓▓▓▓ app       ");
            Label logoLabel = new Label()
            {
                X = 15, Y = 0, Height = 16, Width = 35
            };

            logoLabel.Text = ustring.Make(logo.ToString());             // .Replace(" ", "\u00A0"); // \u00A0 is 'non-breaking space
            win.Add(logoLabel);

            var login = new Label("Login: "******"Password: "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 30
            };
            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            Button loginButton = new Button(6, 22, "Login");

            // Add some controls,
            win.Add(
                // The ones with my favorite layout system, Computed
                login, password, loginText, passText,

                // The ones laid out like an australopithecus, with Absolute positions:
                // new CheckBox(3, 6, "Remember me"),
                //new RadioGroup(3, 8, (new[] { NStack.ustring.Make("_Personal"), "_Company" })),
                loginButton,
                new Button(18, 22, "Cancel")
                );


            loginButton.Clicked += () => {
                var btnText = loginButton.Text.ToString();
                var l       = loginText.Text.ToString();
                var p       = passText.Text.ToString();

                var(result, loggedUser) = Controller.Login(l, p);
                if (result)
                {
                    top.Remove(win);
                    win.Dispose();
                    win.Clear();

                    Controller.RedirectToWindow(loggedUser);
                }
                else
                {
                    MessageBox.ErrorQuery("Exception", "Błędne dane logowania.", "Ok");
                }
            };
        }
Ejemplo n.º 23
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 FakeMainLoop(() => 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";
                v4.AutoSize = false;
                Assert.Equal("Dim.Absolute(50)", v4.Width.ToString());
                Assert.Equal("Dim.Absolute(1)", v4.Height.ToString());
                v4.AutoSize = true;
                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();
        }
        public Toplevel Top()
        {
            var top = new Toplevel()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            // Creates the top-level window to show
            var win = new Window(Name)
            {
                X = 0,
                Y = 1, // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);

            // Creates a menubar, the item "New" has a help menu.
            var menu = new MenuBar(new MenuBarItem[] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New", "Creates new file", () => { }),
                    new MenuItem("_Close", "", () => { }),
                    new MenuItem("_Quit", "", Program.Start)
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", null),
                    new MenuItem("C_ut", "", null),
                    new MenuItem("_Paste", "", null)
                })
            });

            top.Add(menu);

            var login = new Label("Login: "******"Password: "******"")
            {
                X     = Pos.Right(password),
                Y     = Pos.Top(login),
                Width = 40
            };

            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            // Add some controls,
            win.Add(
                // The ones with my favorite layout system
                login, password, loginText, passText,

                // The ones laid out like an australopithecus, with absolute positions:
                new CheckBox(3, 6, "Remember me"),
                new RadioGroup(3, 8, new[] { "_Personal", "_Company" }),
                new Button(3, 14, "Ok"),
                new Button(10, 14, "Cancel"),
                new Label(3, 18, "Press F9 or ESC plus 9 to activate the menubar"));

            return(top);
        }
Ejemplo n.º 25
0
        public DynamicStatusBarSample(ustring title) : base(title)
        {
            DataContext = new DynamicStatusItemModel();

            var _frmDelimiter = new FrameView("Shortcut Delimiter:")
            {
                X      = Pos.Center(),
                Y      = 0,
                Width  = 25,
                Height = 4
            };

            var _txtDelimiter = new TextField(StatusBar.ShortcutDelimiter.ToString())
            {
                X     = Pos.Center(),
                Width = 2,
            };

            _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
            _frmDelimiter.Add(_txtDelimiter);

            Add(_frmDelimiter);

            var _frmStatusBar = new FrameView("Items:")
            {
                Y      = 5,
                Width  = Dim.Percent(50),
                Height = Dim.Fill(2)
            };

            var _btnAddStatusBar = new Button("Add a StatusBar")
            {
                Y = 1,
            };

            _frmStatusBar.Add(_btnAddStatusBar);

            var _btnRemoveStatusBar = new Button("Remove a StatusBar")
            {
                Y = 1
            };

            _btnRemoveStatusBar.X = Pos.AnchorEnd() - (Pos.Right(_btnRemoveStatusBar) - Pos.Left(_btnRemoveStatusBar));
            _frmStatusBar.Add(_btnRemoveStatusBar);

            var _btnAdd = new Button(" Add  ")
            {
                Y = Pos.Top(_btnRemoveStatusBar) + 2,
            };

            _btnAdd.X = Pos.AnchorEnd() - (Pos.Right(_btnAdd) - Pos.Left(_btnAdd));
            _frmStatusBar.Add(_btnAdd);

            _lstItems = new ListView(new List <DynamicStatusItemList> ())
            {
                ColorScheme = Colors.Dialog,
                Y           = Pos.Top(_btnAddStatusBar) + 2,
                Width       = Dim.Fill() - Dim.Width(_btnAdd) - 1,
                Height      = Dim.Fill(),
            };
            _frmStatusBar.Add(_lstItems);

            var _btnRemove = new Button("Remove")
            {
                X = Pos.Left(_btnAdd),
                Y = Pos.Top(_btnAdd) + 1
            };

            _frmStatusBar.Add(_btnRemove);

            var _btnUp = new Button("^")
            {
                X = Pos.Right(_lstItems) + 2,
                Y = Pos.Top(_btnRemove) + 2
            };

            _frmStatusBar.Add(_btnUp);

            var _btnDown = new Button("v")
            {
                X = Pos.Right(_lstItems) + 2,
                Y = Pos.Top(_btnUp) + 1
            };

            _frmStatusBar.Add(_btnDown);

            Add(_frmStatusBar);


            var _frmStatusBarDetails = new DynamicStatusBarDetails("StatusBar Item Details:")
            {
                X      = Pos.Right(_frmStatusBar),
                Y      = Pos.Top(_frmStatusBar),
                Width  = Dim.Fill(),
                Height = Dim.Fill(4)
            };

            Add(_frmStatusBarDetails);

            _btnUp.Clicked += () => {
                var i          = _lstItems.SelectedItem;
                var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null;
                if (statusItem != null)
                {
                    var items = _statusBar.Items;
                    if (i > 0)
                    {
                        items [i]                 = items [i - 1];
                        items [i - 1]             = statusItem;
                        DataContext.Items [i]     = DataContext.Items [i - 1];
                        DataContext.Items [i - 1] = new DynamicStatusItemList(statusItem.Title, statusItem);
                        _lstItems.SelectedItem    = i - 1;
                        _statusBar.SetNeedsDisplay();
                    }
                }
            };

            _btnDown.Clicked += () => {
                var i          = _lstItems.SelectedItem;
                var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null;
                if (statusItem != null)
                {
                    var items = _statusBar.Items;
                    if (i < items.Length - 1)
                    {
                        items [i]                 = items [i + 1];
                        items [i + 1]             = statusItem;
                        DataContext.Items [i]     = DataContext.Items [i + 1];
                        DataContext.Items [i + 1] = new DynamicStatusItemList(statusItem.Title, statusItem);
                        _lstItems.SelectedItem    = i + 1;
                        _statusBar.SetNeedsDisplay();
                    }
                }
            };

            var _btnOk = new Button("Ok")
            {
                X = Pos.Right(_frmStatusBar) + 20,
                Y = Pos.Bottom(_frmStatusBarDetails),
            };

            Add(_btnOk);

            var _btnCancel = new Button("Cancel")
            {
                X = Pos.Right(_btnOk) + 3,
                Y = Pos.Top(_btnOk),
            };

            _btnCancel.Clicked += () => {
                SetFrameDetails(_currentEditStatusItem);
            };
            Add(_btnCancel);

            _lstItems.SelectedItemChanged += (e) => {
                SetFrameDetails();
            };

            _btnOk.Clicked += () => {
                if (ustring.IsNullOrEmpty(_frmStatusBarDetails._txtTitle.Text) && _currentEditStatusItem != null)
                {
                    MessageBox.ErrorQuery("Invalid title", "Must enter a valid title!.", "Ok");
                }
                else if (_currentEditStatusItem != null)
                {
                    _frmStatusBarDetails._txtTitle.Text = SetTitleText(
                        _frmStatusBarDetails._txtTitle.Text, _frmStatusBarDetails._txtShortcut.Text);
                    var statusItem = new DynamicStatusItem(_frmStatusBarDetails._txtTitle.Text,
                                                           _frmStatusBarDetails._txtAction.Text,
                                                           _frmStatusBarDetails._txtShortcut.Text);
                    UpdateStatusItem(_currentEditStatusItem, statusItem, _lstItems.SelectedItem);
                }
            };

            _btnAdd.Clicked += () => {
                if (StatusBar == null)
                {
                    MessageBox.ErrorQuery("StatusBar Bar Error", "Must add a StatusBar first!", "Ok");
                    _btnAddStatusBar.SetFocus();
                    return;
                }

                var frameDetails = new DynamicStatusBarDetails();
                var item         = frameDetails.EnterStatusItem();
                if (item == null)
                {
                    return;
                }

                StatusItem newStatusItem = CreateNewStatusBar(item);
                _currentSelectedStatusBar++;
                _statusBar.AddItemAt(_currentSelectedStatusBar, newStatusItem);
                DataContext.Items.Add(new DynamicStatusItemList(newStatusItem.Title, newStatusItem));
                _lstItems.MoveDown();
            };

            _btnRemove.Clicked += () => {
                var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
                if (statusItem != null)
                {
                    _statusBar.RemoveItem(_currentSelectedStatusBar);
                    DataContext.Items.RemoveAt(_lstItems.SelectedItem);
                    if (_lstItems.Source.Count > 0 && _lstItems.SelectedItem > _lstItems.Source.Count - 1)
                    {
                        _lstItems.SelectedItem = _lstItems.Source.Count - 1;
                    }
                    _lstItems.SetNeedsDisplay();
                    SetFrameDetails();
                }
            };

            _lstItems.Enter += (_) => {
                var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
                SetFrameDetails(statusItem);
            };

            _btnAddStatusBar.Clicked += () => {
                if (_statusBar != null)
                {
                    return;
                }

                _statusBar = new StatusBar();
                Add(_statusBar);
            };

            _btnRemoveStatusBar.Clicked += () => {
                if (_statusBar == null)
                {
                    return;
                }

                Remove(_statusBar);
                _statusBar                = null;
                DataContext.Items         = new List <DynamicStatusItemList> ();
                _currentStatusItem        = null;
                _currentSelectedStatusBar = -1;
                SetListViewSource(_currentStatusItem, true);
                SetFrameDetails(null);
            };


            SetFrameDetails();


            var ustringConverter     = new UStringValueConverter();
            var listWrapperConverter = new ListWrapperConverter();

            var lstItems = new Binding(this, "Items", _lstItems, "Source", listWrapperConverter);


            void SetFrameDetails(StatusItem statusItem = null)
            {
                StatusItem newStatusItem;

                if (statusItem == null)
                {
                    newStatusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
                }
                else
                {
                    newStatusItem = statusItem;
                }

                _currentEditStatusItem = newStatusItem;
                _frmStatusBarDetails.EditStatusItem(newStatusItem);
                var f = _btnOk.Enabled == _frmStatusBarDetails.Enabled;

                if (!f)
                {
                    _btnOk.Enabled     = _frmStatusBarDetails.Enabled;
                    _btnCancel.Enabled = _frmStatusBarDetails.Enabled;
                }
            }

            void SetListViewSource(StatusItem _currentStatusItem, bool fill = false)
            {
                DataContext.Items = new List <DynamicStatusItemList> ();
                var statusItem = _currentStatusItem;

                if (!fill)
                {
                    return;
                }
                if (statusItem != null)
                {
                    foreach (var si in _statusBar.Items)
                    {
                        DataContext.Items.Add(new DynamicStatusItemList(si.Title, si));
                    }
                }
            }

            StatusItem CreateNewStatusBar(DynamicStatusItem item)
            {
                StatusItem newStatusItem;

                newStatusItem = new StatusItem(ShortcutHelper.GetShortcutFromTag(
                                                   item.shortcut, StatusBar.ShortcutDelimiter),
                                               item.title, _frmStatusBarDetails.CreateAction(item));

                return(newStatusItem);
            }

            void UpdateStatusItem(StatusItem _currentEditStatusItem, DynamicStatusItem statusItem, int index)
            {
                _currentEditStatusItem   = CreateNewStatusBar(statusItem);
                _statusBar.Items [index] = _currentEditStatusItem;
                if (DataContext.Items.Count == 0)
                {
                    DataContext.Items.Add(new DynamicStatusItemList(_currentEditStatusItem.Title, _currentEditStatusItem));
                }
                DataContext.Items [index] = new DynamicStatusItemList(_currentEditStatusItem.Title, _currentEditStatusItem);
                SetFrameDetails(_currentEditStatusItem);
            }

            //_frmStatusBarDetails.Initialized += (s, e) => _frmStatusBarDetails.Enabled = false;
        }
Ejemplo n.º 26
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("Width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("50")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("Height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("6")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextField("Message")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                           + Dim.Height(numButtonsEdit) + Dim.Height(styleRadioGroup) + 2;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 2,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label("")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 4,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
                Clicked   = () => {
                    try {
                        int width      = int.Parse(widthEdit.Text.ToString());
                        int height     = int.Parse(heightEdit.Text.ToString());
                        int numButtons = int.Parse(numButtonsEdit.Text.ToString());
                        var btns       = new List <string> ();
                        for (int i = 0; i < numButtons; i++)
                        {
                            btns.Add($"Btn {i}");
                        }
                        if (styleRadioGroup.Selected == 0)
                        {
                            buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                        else
                        {
                            buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
                        }
                    } catch {
                        buttonPressedLabel.Text = "Invalid Options";
                    }
                },
            };

            Win.Add(showMessageBoxButton);
            Win.Add(buttonPressedLabel);
        }
Ejemplo n.º 27
0
    static void ShowEntries(View container)
    {
        var scrollView = new ScrollView(new Rect(50, 10, 20, 8))
        {
            ContentSize = new Size(20, 50),
            //ContentOffset = new Point (0, 0),
            ShowVerticalScrollIndicator   = true,
            ShowHorizontalScrollIndicator = true
        };

#if false
        scrollView.Add(new Box10x(0, 0));
#else
        var filler = new Filler(new Rect(0, 0, 40, 40));
        scrollView.Add(filler);
        scrollView.DrawContent = (r) => {
            scrollView.ContentSize = filler.GetContentSize();
        };
#endif

        // This is just to debug the visuals of the scrollview when small
        var scrollView2 = new ScrollView(new Rect(72, 10, 3, 3))
        {
            ContentSize = new Size(100, 100),
            ShowVerticalScrollIndicator   = true,
            ShowHorizontalScrollIndicator = true
        };
        scrollView2.Add(new Box10x(0, 0));
        var progress = new ProgressBar(new Rect(68, 1, 10, 1));
        bool timer(MainLoop caller)
        {
            progress.Pulse();
            return(true);
        }

        Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(300), timer);


        // A little convoluted, this is because I am using this to test the
        // layout based on referencing elements of another view:

        var login = new Label("Login: "******"Password: "******"")
        {
            X     = Pos.Right(password),
            Y     = Pos.Top(login),
            Width = 40
        };

        var passText = new TextField("")
        {
            Secret = true,
            X      = Pos.Left(loginText),
            Y      = Pos.Top(password),
            Width  = Dim.Width(loginText)
        };

        var tf = new Button(3, 19, "Ok");
        // Add some content
        container.Add(
            login,
            loginText,
            password,
            passText,
            new FrameView(new Rect(3, 10, 25, 6), "Options")
        {
            new CheckBox(1, 0, "Remember me"),
            new RadioGroup(1, 2, new ustring [] { "_Personal", "_Company" }),
        },
            new ListView(new Rect(59, 6, 16, 4), new string [] {
            "First row",
            "<>",
            "This is a very long row that should overflow what is shown",
            "4th",
            "There is an empty slot on the second row",
            "Whoa",
            "This is so cool"
        }),
            scrollView,
            scrollView2,
            tf,
            new Button(10, 19, "Cancel"),
            new TimeField(3, 20, DateTime.Now.TimeOfDay),
            new TimeField(23, 20, DateTime.Now.TimeOfDay, true),
            new DateField(3, 22, DateTime.Now),
            new DateField(23, 22, DateTime.Now, true),
            progress,
            new Label(3, 24, "Press F9 (on Unix, ESC+9 is an alias) or Ctrl+T to activate the menubar"),
            menuKeysStyle,
            menuAutoMouseNav

            );
        container.SendSubviewToBack(tf);
    }
Ejemplo n.º 28
0
        public override void Setup()
        {
            // string txt = ".\n...\n.....\nHELLO\n.....\n...\n.";
            // string txt = "┌──┴──┐\n┤HELLO├\n└──┬──┘";
            string txt = "HELLO WORLD";

            var color1 = new ColorScheme {
                Normal = Application.Driver.MakeAttribute(Color.Black, Color.Gray)
            };
            var color2 = new ColorScheme {
                Normal = Application.Driver.MakeAttribute(Color.Black, Color.DarkGray)
            };

            var txts  = new List <Label> ();           // single line
            var mtxts = new List <Label> ();           // multi line

            // Horizontal Single-Line

            var labelHL = new Label("Left")
            {
                X = 1, Y = 1, Width = 9, Height = 1, TextAlignment = TextAlignment.Right, ColorScheme = Colors.ColorSchemes ["Dialog"]
            };
            var labelHC = new Label("Centered")
            {
                X = 1, Y = 2, Width = 9, Height = 1, TextAlignment = TextAlignment.Right, ColorScheme = Colors.ColorSchemes ["Dialog"]
            };
            var labelHR = new Label("Right")
            {
                X = 1, Y = 3, Width = 9, Height = 1, TextAlignment = TextAlignment.Right, ColorScheme = Colors.ColorSchemes ["Dialog"]
            };
            var labelHJ = new Label("Justified")
            {
                X = 1, Y = 4, Width = 9, Height = 1, TextAlignment = TextAlignment.Right, ColorScheme = Colors.ColorSchemes ["Dialog"]
            };

            var txtLabelHL = new Label(txt)
            {
                X = Pos.Right(labelHL) + 1, Y = Pos.Y(labelHL), Width = Dim.Fill(1) - 9, Height = 1, ColorScheme = color1, TextAlignment = TextAlignment.Left
            };
            var txtLabelHC = new Label(txt)
            {
                X = Pos.Right(labelHC) + 1, Y = Pos.Y(labelHC), Width = Dim.Fill(1) - 9, Height = 1, ColorScheme = color2, TextAlignment = TextAlignment.Centered
            };
            var txtLabelHR = new Label(txt)
            {
                X = Pos.Right(labelHR) + 1, Y = Pos.Y(labelHR), Width = Dim.Fill(1) - 9, Height = 1, ColorScheme = color1, TextAlignment = TextAlignment.Right
            };
            var txtLabelHJ = new Label(txt)
            {
                X = Pos.Right(labelHJ) + 1, Y = Pos.Y(labelHJ), Width = Dim.Fill(1) - 9, Height = 1, ColorScheme = color2, TextAlignment = TextAlignment.Justified
            };

            txts.Add(txtLabelHL); txts.Add(txtLabelHC); txts.Add(txtLabelHR); txts.Add(txtLabelHJ);

            Win.Add(labelHL); Win.Add(txtLabelHL);
            Win.Add(labelHC); Win.Add(txtLabelHC);
            Win.Add(labelHR); Win.Add(txtLabelHR);
            Win.Add(labelHJ); Win.Add(txtLabelHJ);

            // Vertical Single-Line

            var labelVT = new Label("Top")
            {
                X = Pos.AnchorEnd(8), Y = 1, Width = 2, Height = 9, ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Bottom
            };
            var labelVM = new Label("Middle")
            {
                X = Pos.AnchorEnd(6), Y = 1, Width = 2, Height = 9, ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Bottom
            };
            var labelVB = new Label("Bottom")
            {
                X = Pos.AnchorEnd(4), Y = 1, Width = 2, Height = 9, ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Bottom
            };
            var labelVJ = new Label("Justified")
            {
                X = Pos.AnchorEnd(2), Y = 1, Width = 1, Height = 9, ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Bottom
            };

            var txtLabelVT = new Label(txt)
            {
                X = Pos.X(labelVT), Y = Pos.Bottom(labelVT) + 1, Width = 1, Height = Dim.Fill(1), ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Top
            };
            var txtLabelVM = new Label(txt)
            {
                X = Pos.X(labelVM), Y = Pos.Bottom(labelVM) + 1, Width = 1, Height = Dim.Fill(1), ColorScheme = color2, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Middle
            };
            var txtLabelVB = new Label(txt)
            {
                X = Pos.X(labelVB), Y = Pos.Bottom(labelVB) + 1, Width = 1, Height = Dim.Fill(1), ColorScheme = color1, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Bottom
            };
            var txtLabelVJ = new Label(txt)
            {
                X = Pos.X(labelVJ), Y = Pos.Bottom(labelVJ) + 1, Width = 1, Height = Dim.Fill(1), ColorScheme = color2, TextDirection = TextDirection.TopBottom_LeftRight, VerticalTextAlignment = VerticalTextAlignment.Justified
            };

            txts.Add(txtLabelVT); txts.Add(txtLabelVM); txts.Add(txtLabelVB); txts.Add(txtLabelVJ);

            Win.Add(labelVT); Win.Add(txtLabelVT);
            Win.Add(labelVM); Win.Add(txtLabelVM);
            Win.Add(labelVB); Win.Add(txtLabelVB);
            Win.Add(labelVJ); Win.Add(txtLabelVJ);

            // Multi-Line

            var container = new View()
            {
                X = 0, Y = Pos.Bottom(txtLabelHJ), Width = Dim.Fill(31), Height = Dim.Fill(7), ColorScheme = color2
            };

            var txtLabelTL = new Label(txt)
            {
                X = 1 /*                    */, Y = 1, Width = Dim.Percent(100f / 3f), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Left, VerticalTextAlignment = VerticalTextAlignment.Top, ColorScheme = color1
            };
            var txtLabelTC = new Label(txt)
            {
                X = Pos.Right(txtLabelTL) + 2, Y = 1, Width = Dim.Percent(100f / 3f), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Top, ColorScheme = color1
            };
            var txtLabelTR = new Label(txt)
            {
                X = Pos.Right(txtLabelTC) + 2, Y = 1, Width = Dim.Percent(100f, true), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Right, VerticalTextAlignment = VerticalTextAlignment.Top, ColorScheme = color1
            };

            var txtLabelML = new Label(txt)
            {
                X = Pos.X(txtLabelTL) /*    */, Y = Pos.Bottom(txtLabelTL) + 1, Width = Dim.Width(txtLabelTL), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Left, VerticalTextAlignment = VerticalTextAlignment.Middle, ColorScheme = color1
            };
            var txtLabelMC = new Label(txt)
            {
                X = Pos.X(txtLabelTC) /*    */, Y = Pos.Bottom(txtLabelTC) + 1, Width = Dim.Width(txtLabelTC), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Middle, ColorScheme = color1
            };
            var txtLabelMR = new Label(txt)
            {
                X = Pos.X(txtLabelTR) /*    */, Y = Pos.Bottom(txtLabelTR) + 1, Width = Dim.Percent(100f, true), Height = Dim.Percent(100f / 3f), TextAlignment = TextAlignment.Right, VerticalTextAlignment = VerticalTextAlignment.Middle, ColorScheme = color1
            };

            var txtLabelBL = new Label(txt)
            {
                X = Pos.X(txtLabelML) /*    */, Y = Pos.Bottom(txtLabelML) + 1, Width = Dim.Width(txtLabelML), Height = Dim.Percent(100f, true), TextAlignment = TextAlignment.Left, VerticalTextAlignment = VerticalTextAlignment.Bottom, ColorScheme = color1
            };
            var txtLabelBC = new Label(txt)
            {
                X = Pos.X(txtLabelMC) /*    */, Y = Pos.Bottom(txtLabelMC) + 1, Width = Dim.Width(txtLabelMC), Height = Dim.Percent(100f, true), TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Bottom, ColorScheme = color1
            };
            var txtLabelBR = new Label(txt)
            {
                X = Pos.X(txtLabelMR) /*    */, Y = Pos.Bottom(txtLabelMR) + 1, Width = Dim.Percent(100f, true), Height = Dim.Percent(100f, true), TextAlignment = TextAlignment.Right, VerticalTextAlignment = VerticalTextAlignment.Bottom, ColorScheme = color1
            };

            mtxts.Add(txtLabelTL); mtxts.Add(txtLabelTC); mtxts.Add(txtLabelTR);
            mtxts.Add(txtLabelML); mtxts.Add(txtLabelMC); mtxts.Add(txtLabelMR);
            mtxts.Add(txtLabelBL); mtxts.Add(txtLabelBC); mtxts.Add(txtLabelBR);

            // Save Alignments in Data
            foreach (var t in mtxts)
            {
                t.Data = new { h = t.TextAlignment, v = t.VerticalTextAlignment };
            }

            container.Add(txtLabelTL);
            container.Add(txtLabelTC);
            container.Add(txtLabelTR);

            container.Add(txtLabelML);
            container.Add(txtLabelMC);
            container.Add(txtLabelMR);

            container.Add(txtLabelBL);
            container.Add(txtLabelBC);
            container.Add(txtLabelBR);

            Win.Add(container);


            // Edit Text

            var editText = new TextView()
            {
                X           = 1,
                Y           = Pos.Bottom(container) + 1,
                Width       = Dim.Fill(10),
                Height      = Dim.Fill(1),
                ColorScheme = color2,
                Text        = txt
            };

            editText.MouseClick += (m) => {
                foreach (var v in txts)
                {
                    v.Text = editText.Text;
                }
                foreach (var v in mtxts)
                {
                    v.Text = editText.Text;
                }
            };

            Win.KeyUp += (m) => {
                foreach (var v in txts)
                {
                    v.Text = editText.Text;
                }
                foreach (var v in mtxts)
                {
                    v.Text = editText.Text;
                }
            };

            editText.SetFocus();

            Win.Add(editText);


            // JUSTIFY CHECKBOX

            var justifyCheckbox = new CheckBox("Justify")
            {
                X      = Pos.Right(container) + 1,
                Y      = Pos.Y(container) + 1,
                Width  = Dim.Fill(10),
                Height = 1
            };

            justifyCheckbox.Toggled += (prevtoggled) => {
                if (prevtoggled)
                {
                    foreach (var t in mtxts)
                    {
                        t.TextAlignment         = (TextAlignment)((dynamic)t.Data).h;
                        t.VerticalTextAlignment = (VerticalTextAlignment)((dynamic)t.Data).v;
                    }
                }
                else
                {
                    foreach (var t in mtxts)
                    {
                        if (TextFormatter.IsVerticalDirection(t.TextDirection))
                        {
                            t.VerticalTextAlignment = VerticalTextAlignment.Justified;
                            t.TextAlignment         = ((dynamic)t.Data).h;
                        }
                        else
                        {
                            t.TextAlignment         = TextAlignment.Justified;
                            t.VerticalTextAlignment = ((dynamic)t.Data).v;
                        }
                    }
                }
            };

            Win.Add(justifyCheckbox);


            // Direction Options

            var directionsEnum = Enum.GetValues(typeof(Terminal.Gui.TextDirection)).Cast <Terminal.Gui.TextDirection> ().ToList();

            var directionOptions = new RadioGroup(directionsEnum.Select(e => NStack.ustring.Make(e.ToString())).ToArray())
            {
                X               = Pos.Right(container) + 1,
                Y               = Pos.Bottom(justifyCheckbox) + 1,
                Width           = Dim.Fill(10),
                Height          = Dim.Fill(1),
                HotKeySpecifier = '\xffff'
            };

            directionOptions.SelectedItemChanged += (ev) => {
                foreach (var v in mtxts)
                {
                    v.TextDirection = (TextDirection)ev.SelectedItem;
                }
            };

            Win.Add(directionOptions);
        }
Ejemplo n.º 29
0
        public static void Main(string [] args)
        {
            Application.Init();

            menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_Close", "", () => Close()),
                    new MenuItem("_Quit", "", () => { Application.RequestStop(); })
                }),
                new MenuBarItem("_Edit", new MenuItem [] {
                    new MenuItem("_Copy", "", Copy),
                    new MenuItem("C_ut", "", Cut),
                    new MenuItem("_Paste", "", Paste)
                }),
            });

            var login = new Label("Login: "******"Password: "******"Test: ")
            {
                X = Pos.Left(login),
                Y = Pos.Bottom(password) + 1
            };

            var surface = new Surface()
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Percent(50),
                Height = Dim.Percent(50)
            };

            var loginText = new TextField("")
            {
                X           = Pos.Right(password),
                Y           = Pos.Top(login),
                Width       = Dim.Percent(90),
                ColorScheme = new ColorScheme()
                {
                    Focus     = Attribute.Make(Color.BrightYellow, Color.DarkGray),
                    Normal    = Attribute.Make(Color.Green, Color.BrightYellow),
                    HotFocus  = Attribute.Make(Color.BrightBlue, Color.Brown),
                    HotNormal = Attribute.Make(Color.Red, Color.BrightRed),
                },
            };

            loginText.MouseEnter += (e) => Text_MouseEnter(e, loginText);
            loginText.MouseLeave += (e) => Text_MouseLeave(e, loginText);
            loginText.Enter      += (e) => Text_Enter(e, loginText);
            loginText.Leave      += (e) => Text_Leave(e, loginText);

            var passText = new TextField("")
            {
                Secret = true,
                X      = Pos.Left(loginText),
                Y      = Pos.Top(password),
                Width  = Dim.Width(loginText)
            };

            var testText = new TextField("")
            {
                X     = Pos.Left(loginText),
                Y     = Pos.Top(test),
                Width = Dim.Width(loginText)
            };

            testText.MouseEnter += (e) => Text_MouseEnter(e, testText);
            testText.MouseLeave += (e) => Text_MouseLeave(e, testText);
            testText.Enter      += (e) => Text_Enter(e, testText);
            testText.Leave      += (e) => Text_Leave(e, testText);

            surface.Add(login, password, test, loginText, passText, testText);
            Application.Top.Add(menu, surface);
            Application.Run();
        }
Ejemplo n.º 30
0
        public DynamicMenuBarSample(ustring title) : base(title)
        {
            DataContext = new DynamicMenuItemModel();

            var _frmDelimiter = new FrameView("Shortcut Delimiter:")
            {
                X      = Pos.Center(),
                Y      = 3,
                Width  = 25,
                Height = 4
            };

            var _txtDelimiter = new TextField(MenuBar.ShortcutDelimiter.ToString())
            {
                X     = Pos.Center(),
                Width = 2,
            };

            _txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text;
            _frmDelimiter.Add(_txtDelimiter);

            Add(_frmDelimiter);

            var _frmMenu = new FrameView("Menus:")
            {
                Y      = 7,
                Width  = Dim.Percent(50),
                Height = Dim.Fill()
            };

            var _btnAddMenuBar = new Button("Add a MenuBar")
            {
                Y = 1,
            };

            _frmMenu.Add(_btnAddMenuBar);

            var _btnMenuBarUp = new Button("^")
            {
                X = Pos.Center()
            };

            _frmMenu.Add(_btnMenuBarUp);

            var _btnMenuBarDown = new Button("v")
            {
                X = Pos.Center(),
                Y = Pos.Bottom(_btnMenuBarUp)
            };

            _frmMenu.Add(_btnMenuBarDown);

            var _btnRemoveMenuBar = new Button("Remove a MenuBar")
            {
                Y = 1
            };

            _btnRemoveMenuBar.X = Pos.AnchorEnd() - (Pos.Right(_btnRemoveMenuBar) - Pos.Left(_btnRemoveMenuBar));
            _frmMenu.Add(_btnRemoveMenuBar);

            var _btnPrevious = new Button("<")
            {
                X = Pos.Left(_btnAddMenuBar),
                Y = Pos.Top(_btnAddMenuBar) + 2
            };

            _frmMenu.Add(_btnPrevious);

            var _btnAdd = new Button(" Add  ")
            {
                Y = Pos.Top(_btnPrevious) + 2,
            };

            _btnAdd.X = Pos.AnchorEnd() - (Pos.Right(_btnAdd) - Pos.Left(_btnAdd));
            _frmMenu.Add(_btnAdd);

            var _btnNext = new Button(">")
            {
                X = Pos.X(_btnAdd),
                Y = Pos.Top(_btnPrevious),
            };

            _frmMenu.Add(_btnNext);

            var _lblMenuBar = new Label()
            {
                ColorScheme   = Colors.Dialog,
                TextAlignment = TextAlignment.Centered,
                X             = Pos.Right(_btnPrevious) + 1,
                Y             = Pos.Top(_btnPrevious),
                Width         = Dim.Fill() - Dim.Width(_btnAdd) - 1,
                Height        = 1
            };

            _frmMenu.Add(_lblMenuBar);
            _lblMenuBar.WantMousePositionReports = true;
            _lblMenuBar.CanFocus = true;

            var _lblParent = new Label()
            {
                TextAlignment = TextAlignment.Centered,
                X             = Pos.Right(_btnPrevious) + 1,
                Y             = Pos.Top(_btnPrevious) + 1,
                Width         = Dim.Fill() - Dim.Width(_btnAdd) - 1
            };

            _frmMenu.Add(_lblParent);

            var _btnPreviowsParent = new Button("..")
            {
                X = Pos.Left(_btnAddMenuBar),
                Y = Pos.Top(_btnPrevious) + 1
            };

            _frmMenu.Add(_btnPreviowsParent);

            _lstMenus = new ListView(new List <DynamicMenuItemList> ())
            {
                ColorScheme = Colors.Dialog,
                X           = Pos.Right(_btnPrevious) + 1,
                Y           = Pos.Top(_btnPrevious) + 2,
                Width       = _lblMenuBar.Width,
                Height      = Dim.Fill(),
            };
            _frmMenu.Add(_lstMenus);

            _lblMenuBar.TabIndex = _btnPrevious.TabIndex + 1;
            _lstMenus.TabIndex   = _lblMenuBar.TabIndex + 1;
            _btnNext.TabIndex    = _lstMenus.TabIndex + 1;
            _btnAdd.TabIndex     = _btnNext.TabIndex + 1;

            var _btnRemove = new Button("Remove")
            {
                X = Pos.Left(_btnAdd),
                Y = Pos.Top(_btnAdd) + 1
            };

            _frmMenu.Add(_btnRemove);

            var _btnUp = new Button("^")
            {
                X = Pos.Right(_lstMenus) + 2,
                Y = Pos.Top(_btnRemove) + 2
            };

            _frmMenu.Add(_btnUp);

            var _btnDown = new Button("v")
            {
                X = Pos.Right(_lstMenus) + 2,
                Y = Pos.Top(_btnUp) + 1
            };

            _frmMenu.Add(_btnDown);

            Add(_frmMenu);


            var _frmMenuDetails = new DynamicMenuBarDetails("Menu Details:")
            {
                X      = Pos.Right(_frmMenu),
                Y      = Pos.Top(_frmMenu),
                Width  = Dim.Fill(),
                Height = Dim.Fill(2)
            };

            Add(_frmMenuDetails);

            _btnMenuBarUp.Clicked += () => {
                var i        = _currentSelectedMenuBar;
                var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
                if (menuItem != null)
                {
                    var menus = _menuBar.Menus;
                    if (i > 0)
                    {
                        menus [i]               = menus [i - 1];
                        menus [i - 1]           = menuItem;
                        _currentSelectedMenuBar = i - 1;
                        _menuBar.SetNeedsDisplay();
                    }
                }
            };

            _btnMenuBarDown.Clicked += () => {
                var i        = _currentSelectedMenuBar;
                var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
                if (menuItem != null)
                {
                    var menus = _menuBar.Menus;
                    if (i < menus.Length - 1)
                    {
                        menus [i]               = menus [i + 1];
                        menus [i + 1]           = menuItem;
                        _currentSelectedMenuBar = i + 1;
                        _menuBar.SetNeedsDisplay();
                    }
                }
            };

            _btnUp.Clicked += () => {
                var i        = _lstMenus.SelectedItem;
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    if (i > 0)
                    {
                        childrens [i]             = childrens [i - 1];
                        childrens [i - 1]         = menuItem;
                        DataContext.Menus [i]     = DataContext.Menus [i - 1];
                        DataContext.Menus [i - 1] = new DynamicMenuItemList(menuItem.Title, menuItem);
                        _lstMenus.SelectedItem    = i - 1;
                    }
                }
            };

            _btnDown.Clicked += () => {
                var i        = _lstMenus.SelectedItem;
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    if (i < childrens.Length - 1)
                    {
                        childrens [i]             = childrens [i + 1];
                        childrens [i + 1]         = menuItem;
                        DataContext.Menus [i]     = DataContext.Menus [i + 1];
                        DataContext.Menus [i + 1] = new DynamicMenuItemList(menuItem.Title, menuItem);
                        _lstMenus.SelectedItem    = i + 1;
                    }
                }
            };

            _btnPreviowsParent.Clicked += () => {
                if (_currentMenuBarItem != null && _currentMenuBarItem.Parent != null)
                {
                    var mi = _currentMenuBarItem;
                    _currentMenuBarItem = _currentMenuBarItem.Parent as MenuBarItem;
                    SetListViewSource(_currentMenuBarItem, true);
                    var i = ((MenuBarItem)_currentMenuBarItem).GetChildrenIndex(mi);
                    if (i > -1)
                    {
                        _lstMenus.SelectedItem = i;
                    }
                    if (_currentMenuBarItem.Parent != null)
                    {
                        DataContext.Parent = _currentMenuBarItem.Title;
                    }
                    else
                    {
                        DataContext.Parent = ustring.Empty;
                    }
                }
                else
                {
                    DataContext.Parent = ustring.Empty;
                }
            };


            var _btnOk = new Button("Ok")
            {
                X = Pos.Right(_frmMenu) + 20,
                Y = Pos.Bottom(_frmMenuDetails),
            };

            Add(_btnOk);

            var _btnCancel = new Button("Cancel")
            {
                X = Pos.Right(_btnOk) + 3,
                Y = Pos.Top(_btnOk),
            };

            _btnCancel.Clicked += () => {
                SetFrameDetails(_currentEditMenuBarItem);
            };
            Add(_btnCancel);

            _lstMenus.SelectedItemChanged += (e) => {
                SetFrameDetails();
            };

            _btnOk.Clicked += () => {
                if (ustring.IsNullOrEmpty(_frmMenuDetails._txtTitle.Text) && _currentEditMenuBarItem != null)
                {
                    MessageBox.ErrorQuery("Invalid title", "Must enter a valid title!.", "Ok");
                }
                else if (_currentEditMenuBarItem != null)
                {
                    var menuItem = new DynamicMenuItem(_frmMenuDetails._txtTitle.Text, _frmMenuDetails._txtHelp.Text,
                                                       _frmMenuDetails._txtAction.Text,
                                                       _frmMenuDetails._ckbIsTopLevel != null ? _frmMenuDetails._ckbIsTopLevel.Checked : false,
                                                       _frmMenuDetails._ckbSubMenu != null ? _frmMenuDetails._ckbSubMenu.Checked : false,
                                                       _frmMenuDetails._rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck :
                                                       _frmMenuDetails._rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked :
                                                       MenuItemCheckStyle.Radio,
                                                       _frmMenuDetails._txtShortcut.Text);
                    UpdateMenuItem(_currentEditMenuBarItem, menuItem, _lstMenus.SelectedItem);
                }
            };

            _btnAdd.Clicked += () => {
                if (MenuBar == null)
                {
                    MessageBox.ErrorQuery("Menu Bar Error", "Must add a MenuBar first!", "Ok");
                    _btnAddMenuBar.SetFocus();
                    return;
                }

                var frameDetails = new DynamicMenuBarDetails(null, _currentMenuBarItem != null);
                var item         = frameDetails.EnterMenuItem();
                if (item == null)
                {
                    return;
                }

                if (!(_currentMenuBarItem is MenuBarItem))
                {
                    var parent = _currentMenuBarItem.Parent as MenuBarItem;
                    var idx    = parent.GetChildrenIndex(_currentMenuBarItem);
                    _currentMenuBarItem           = new MenuBarItem(_currentMenuBarItem.Title, new MenuItem [] { }, _currentMenuBarItem.Parent);
                    _currentMenuBarItem.CheckType = item.checkStyle;
                    parent.Children [idx]         = _currentMenuBarItem;
                }
                else
                {
                    MenuItem newMenu     = CreateNewMenu(item, _currentMenuBarItem);
                    var      menuBarItem = _currentMenuBarItem as MenuBarItem;
                    if (menuBarItem == null)
                    {
                        menuBarItem = new MenuBarItem(_currentMenuBarItem.Title, new MenuItem [] { newMenu }, _currentMenuBarItem.Parent);
                    }
                    else if (menuBarItem.Children == null)
                    {
                        menuBarItem.Children = new MenuItem [] { newMenu };
                    }
                    else
                    {
                        var childrens = menuBarItem.Children;
                        Array.Resize(ref childrens, childrens.Length + 1);
                        childrens [childrens.Length - 1] = newMenu;
                        menuBarItem.Children             = childrens;
                    }
                    DataContext.Menus.Add(new DynamicMenuItemList(newMenu.Title, newMenu));
                    _lstMenus.MoveDown();
                }
            };

            _btnRemove.Clicked += () => {
                var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null;
                if (menuItem != null)
                {
                    var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
                    childrens [_lstMenus.SelectedItem] = null;
                    int i = 0;
                    foreach (var c in childrens)
                    {
                        if (c != null)
                        {
                            childrens [i] = c;
                            i++;
                        }
                    }
                    Array.Resize(ref childrens, childrens.Length - 1);
                    if (childrens.Length == 0)
                    {
                        if (_currentMenuBarItem.Parent == null)
                        {
                            ((MenuBarItem)_currentMenuBarItem).Children = null;
                            //_currentMenuBarItem.Action = _frmMenuDetails.CreateAction (_currentEditMenuBarItem, new DynamicMenuItem (_currentMenuBarItem.Title));
                        }
                        else
                        {
                            _currentMenuBarItem = new MenuItem(_currentMenuBarItem.Title, _currentMenuBarItem.Help, _frmMenuDetails.CreateAction(_currentEditMenuBarItem, new DynamicMenuItem(_currentEditMenuBarItem.Title)), null, _currentMenuBarItem.Parent);
                        }
                    }
                    else
                    {
                        ((MenuBarItem)_currentMenuBarItem).Children = childrens;
                    }
                    DataContext.Menus.RemoveAt(_lstMenus.SelectedItem);
                    if (_lstMenus.Source.Count > 0 && _lstMenus.SelectedItem > _lstMenus.Source.Count - 1)
                    {
                        _lstMenus.SelectedItem = _lstMenus.Source.Count - 1;
                    }
                    _lstMenus.SetNeedsDisplay();
                    SetFrameDetails();
                }
            };

            _lstMenus.OpenSelectedItem += (e) => {
                _currentMenuBarItem = DataContext.Menus [e.Item].MenuItem;
                if (!(_currentMenuBarItem is MenuBarItem))
                {
                    MessageBox.ErrorQuery("Menu Open Error", "Must allows sub menus first!", "Ok");
                    return;
                }
                DataContext.Parent = _currentMenuBarItem.Title;
                DataContext.Menus  = new List <DynamicMenuItemList> ();
                SetListViewSource(_currentMenuBarItem, true);
                var menuBarItem = DataContext.Menus.Count > 0 ? DataContext.Menus [0].MenuItem : null;
                SetFrameDetails(menuBarItem);
            };

            _lstMenus.Enter += (_) => {
                var menuBarItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null;
                SetFrameDetails(menuBarItem);
            };

            _btnNext.Clicked += () => {
                if (_menuBar != null && _currentSelectedMenuBar + 1 < _menuBar.Menus.Length)
                {
                    _currentSelectedMenuBar++;
                }
                SelectCurrentMenuBarItem();
            };

            _btnPrevious.Clicked += () => {
                if (_currentSelectedMenuBar - 1 > -1)
                {
                    _currentSelectedMenuBar--;
                }
                SelectCurrentMenuBarItem();
            };

            _lblMenuBar.Enter += (e) => {
                if (_menuBar?.Menus != null)
                {
                    _currentMenuBarItem = _menuBar.Menus [_currentSelectedMenuBar];
                    SetFrameDetails(_menuBar.Menus [_currentSelectedMenuBar]);
                }
            };

            _btnAddMenuBar.Clicked += () => {
                var frameDetails = new DynamicMenuBarDetails(null, false);
                var item         = frameDetails.EnterMenuItem();
                if (item == null)
                {
                    return;
                }

                if (MenuBar == null)
                {
                    _menuBar = new MenuBar();
                    Add(_menuBar);
                }
                var newMenu = CreateNewMenu(item) as MenuBarItem;

                var menus = _menuBar.Menus;
                Array.Resize(ref menus, menus.Length + 1);
                menus [^ 1]                              = newMenu;