Beispiel #1
0
 public ChatPanel(Rect frame, ustring title, string me) : base(frame, title)
 {
     Me = me;
     InitView();
 }
Beispiel #2
0
 /// <summary>
 ///   Public constructor: creates a label at the given
 ///   coordinate with the given string, computes the bounding box
 ///   based on the size of the string, assumes that the string contains
 ///   newlines for multiple lines, no special breaking rules are used.
 /// </summary>
 public Label(int x, int y, ustring text) : this(CalcRect(x, y, text), text)
 {
 }
Beispiel #3
0
        public override void Setup()
        {
            var statusBar = new StatusBar(new StatusItem [] {
                new StatusItem(Key.ControlQ, "~^Q~ Quit", () => Quit()),
                new StatusItem(Key.F2, "~F2~ Toggle Frame Ruler", () => {
                    ConsoleDriver.Diagnostics ^= ConsoleDriver.DiagnosticFlags.FrameRuler;
                    Top.SetNeedsDisplay();
                }),
                new StatusItem(Key.F3, "~F3~ Toggle Frame Padding", () => {
                    ConsoleDriver.Diagnostics ^= ConsoleDriver.DiagnosticFlags.FramePadding;
                    Top.SetNeedsDisplay();
                }),
            });

            Top.Add(statusBar);

            _viewClasses = GetAllViewClassesCollection()
                           .OrderBy(t => t.Name)
                           .Select(t => new KeyValuePair <string, Type> (t.Name, t))
                           .ToDictionary(t => t.Key, t => t.Value);

            _leftPane = new Window("Classes")
            {
                X           = 0,
                Y           = 0,
                Width       = 15,
                Height      = Dim.Fill(1),             // for status bar
                CanFocus    = false,
                ColorScheme = Colors.TopLevel,
            };

            _classListView = new ListView(_viewClasses.Keys.ToList())
            {
                X             = 0,
                Y             = 0,
                Width         = Dim.Fill(0),
                Height        = Dim.Fill(0),
                AllowsMarking = false,
                ColorScheme   = Colors.TopLevel,
            };
            _classListView.OpenSelectedItem += (a) => {
                Top.SetFocus(_settingsPane);
            };
            _classListView.SelectedItemChanged += (args) => {
                ClearClass(_curView);
                _curView = CreateClass(_viewClasses.Values.ToArray() [_classListView.SelectedItem]);
            };
            _leftPane.Add(_classListView);

            _settingsPane = new FrameView("Settings")
            {
                X           = Pos.Right(_leftPane),
                Y           = 0,       // for menu
                Width       = Dim.Fill(),
                Height      = 10,
                CanFocus    = false,
                ColorScheme = Colors.TopLevel,
            };
            _computedCheckBox = new CheckBox("Computed Layout", true)
            {
                X = 0, Y = 0
            };
            _computedCheckBox.Toggled += (previousState) => {
                if (_curView != null)
                {
                    _curView.LayoutStyle = previousState ? LayoutStyle.Absolute : LayoutStyle.Computed;
                    _hostPane.LayoutSubviews();
                }
            };
            _settingsPane.Add(_computedCheckBox);

            var radioItems = new ustring [] { "Percent(x)", "AnchorEnd(x)", "Center", "At(x)" };

            _locationFrame = new FrameView("Location (Pos)")
            {
                X      = Pos.Left(_computedCheckBox),
                Y      = Pos.Bottom(_computedCheckBox),
                Height = 3 + radioItems.Length,
                Width  = 36,
            };
            _settingsPane.Add(_locationFrame);

            var label = new Label("x:")
            {
                X = 0, Y = 0
            };

            _locationFrame.Add(label);
            _xRadioGroup = new RadioGroup(radioItems)
            {
                X = 0,
                Y = Pos.Bottom(label),
                SelectedItemChanged = (selected) => DimPosChanged(_curView),
            };
            _xText = new TextField($"{_xVal}")
            {
                X = Pos.Right(label) + 1, Y = 0, Width = 4
            };
            _xText.TextChanged += (args) => {
                try {
                    _xVal = int.Parse(_xText.Text.ToString());
                    DimPosChanged(_curView);
                } catch {
                }
            };
            _locationFrame.Add(_xText);

            _locationFrame.Add(_xRadioGroup);

            radioItems = new ustring [] { "Percent(y)", "AnchorEnd(y)", "Center", "At(y)" };
            label      = new Label("y:")
            {
                X = Pos.Right(_xRadioGroup) + 1, Y = 0
            };
            _locationFrame.Add(label);
            _yText = new TextField($"{_yVal}")
            {
                X = Pos.Right(label) + 1, Y = 0, Width = 4
            };
            _yText.TextChanged += (args) => {
                try {
                    _yVal = int.Parse(_yText.Text.ToString());
                    DimPosChanged(_curView);
                } catch {
                }
            };
            _locationFrame.Add(_yText);
            _yRadioGroup = new RadioGroup(radioItems)
            {
                X = Pos.X(label),
                Y = Pos.Bottom(label),
                SelectedItemChanged = (selected) => DimPosChanged(_curView),
            };
            _locationFrame.Add(_yRadioGroup);

            _sizeFrame = new FrameView("Size (Dim)")
            {
                X      = Pos.Right(_locationFrame),
                Y      = Pos.Y(_locationFrame),
                Height = 3 + radioItems.Length,
                Width  = 40,
            };

            radioItems = new ustring [] { "Percent(width)", "Fill(width)", "Sized(width)" };
            label      = new Label("width:")
            {
                X = 0, Y = 0
            };
            _sizeFrame.Add(label);
            _wRadioGroup = new RadioGroup(radioItems)
            {
                X = 0,
                Y = Pos.Bottom(label),
                SelectedItemChanged = (selected) => DimPosChanged(_curView)
            };
            _wText = new TextField($"{_wVal}")
            {
                X = Pos.Right(label) + 1, Y = 0, Width = 4
            };
            _wText.TextChanged += (args) => {
                try {
                    _wVal = int.Parse(_wText.Text.ToString());
                    DimPosChanged(_curView);
                } catch {
                }
            };
            _sizeFrame.Add(_wText);
            _sizeFrame.Add(_wRadioGroup);

            radioItems = new ustring [] { "Percent(height)", "Fill(height)", "Sized(height)" };
            label      = new Label("height:")
            {
                X = Pos.Right(_wRadioGroup) + 1, Y = 0
            };
            _sizeFrame.Add(label);
            _hText = new TextField($"{_hVal}")
            {
                X = Pos.Right(label) + 1, Y = 0, Width = 4
            };
            _hText.TextChanged += (args) => {
                try {
                    _hVal = int.Parse(_hText.Text.ToString());
                    DimPosChanged(_curView);
                } catch {
                }
            };
            _sizeFrame.Add(_hText);

            _hRadioGroup = new RadioGroup(radioItems)
            {
                X = Pos.X(label),
                Y = Pos.Bottom(label),
                SelectedItemChanged = (selected) => DimPosChanged(_curView),
            };
            _sizeFrame.Add(_hRadioGroup);

            _settingsPane.Add(_sizeFrame);

            _hostPane = new FrameView("")
            {
                X           = Pos.Right(_leftPane),
                Y           = Pos.Bottom(_settingsPane),
                Width       = Dim.Fill(),
                Height      = Dim.Fill(1),             // + 1 for status bar
                ColorScheme = Colors.Dialog,
            };

            Top.Add(_leftPane, _settingsPane, _hostPane);

            _curView = CreateClass(_viewClasses.First().Value);
        }
Beispiel #4
0
 /// <summary>
 ///   Initializes a new instance of <see cref="Label"/> at the given
 ///   coordinate with the given string and uses the specified
 ///   frame for the string.
 /// </summary>
 public Label(Rect rect, ustring text) : base(rect)
 {
     this.text = text;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new <see cref="StatusItem"/>.
 /// </summary>
 /// <param name="shortcut">Shortcut to activate the <see cref="StatusItem"/>.</param>
 /// <param name="title">Title for the <see cref="StatusItem"/>.</param>
 /// <param name="action">Action to invoke when the <see cref="StatusItem"/> is activated.</param>
 public StatusItem(Key shortcut, ustring title, Action action)
 {
     Title    = title ?? "";
     Shortcut = shortcut;
     Action   = action;
 }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of <see cref="FileDialog"/>
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="prompt">The prompt.</param>
        /// <param name="nameFieldLabel">The name field label.</param>
        /// <param name="message">The message.</param>
        public FileDialog(ustring title, ustring prompt, ustring nameFieldLabel, ustring message) : base(title)          //, Driver.Cols - 20, Driver.Rows - 5, null)
        {
            this.message = new Label(message)
            {
                X = 1,
                Y = 0,
            };
            Add(this.message);
            var msgLines = TextFormatter.MaxLines(message, Driver.Cols - 20);

            dirLabel = new Label("Directory: ")
            {
                X = 1,
                Y = 1 + msgLines
            };

            dirEntry = new TextField("")
            {
                X     = Pos.Right(dirLabel),
                Y     = 1 + msgLines,
                Width = Dim.Fill() - 1,
            };
            dirEntry.TextChanged += (e) => {
                DirectoryPath  = dirEntry.Text;
                nameEntry.Text = ustring.Empty;
            };
            Add(dirLabel, dirEntry);

            this.nameFieldLabel = new Label("Open: ")
            {
                X = 6,
                Y = 3 + msgLines,
            };
            nameEntry = new TextField("")
            {
                X     = Pos.Left(dirEntry),
                Y     = 3 + msgLines,
                Width = Dim.Fill() - 1
            };
            Add(this.nameFieldLabel, nameEntry);

            dirListView = new DirListView(this)
            {
                X      = 1,
                Y      = 3 + msgLines + 2,
                Width  = Dim.Fill() - 1,
                Height = Dim.Fill() - 2,
            };
            DirectoryPath = Path.GetFullPath(Environment.CurrentDirectory);
            Add(dirListView);
            dirListView.DirectoryChanged = (dir) => { nameEntry.Text = ustring.Empty; dirEntry.Text = dir; };
            dirListView.FileChanged      = (file) => nameEntry.Text = file == ".." ? "" : file;
            dirListView.SelectedChanged  = (file) => nameEntry.Text = file.Item1 == ".." ? "" : file.Item1;
            this.cancel          = new Button("Cancel");
            this.cancel.Clicked += () => {
                canceled = true;
                Application.RequestStop();
            };
            AddButton(cancel);

            this.prompt = new Button(prompt)
            {
                IsDefault = true,
            };
            this.prompt.Clicked += () => {
                canceled = false;
                Application.RequestStop();
            };
            AddButton(this.prompt);

            Width  = Dim.Percent(80);
            Height = Dim.Percent(80);

            // On success, we will set this to false.
            canceled = true;
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning
 /// and with an optional set of <see cref="Button"/>s to display
 /// </summary>
 /// <param name="title">Title for the dialog.</param>
 /// <param name="buttons">Optional buttons to lay out at the bottom of the dialog.</param>
 /// <remarks>
 /// if <c>width</c> and <c>height</c> are both 0, the Dialog will be vertically and horizontally centered in the
 /// container and the size will be 85% of the container.
 /// After initialzation use <c>X</c>, <c>Y</c>, <c>Width</c>, and <c>Height</c> to override this with a location or size.
 /// </remarks>
 public Dialog(ustring title, params Button [] buttons) : this(title : title, width : 0, height : 0, buttons : buttons)
 {
 }
Beispiel #8
0
 public void LoadString(ustring content)
 {
     lines = StringToRunes(content);
 }
Beispiel #9
0
        /// <summary>
        /// Constructor for the OpenDialog and the SaveDialog.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="prompt">The prompt.</param>
        /// <param name="nameFieldLabel">The name field label.</param>
        /// <param name="message">The message.</param>
        public FileDialog(ustring title, ustring prompt, ustring nameFieldLabel, ustring message) : base(title, Driver.Cols - 20, Driver.Rows - 5, null)
        {
            this.message = new Label(Rect.Empty, "MESSAGE" + message);
            var msgLines = Label.MeasureLines(message, Driver.Cols - 20);

            dirLabel = new Label("Directory: ")
            {
                X = 1,
                Y = 1 + msgLines
            };

            dirEntry = new TextField("")
            {
                X     = Pos.Right(dirLabel),
                Y     = 1 + msgLines,
                Width = Dim.Fill() - 1
            };
            Add(dirLabel, dirEntry);

            this.nameFieldLabel = new Label("Open: ")
            {
                X = 6,
                Y = 3 + msgLines,
            };
            nameEntry = new TextField("")
            {
                X     = Pos.Left(dirEntry),
                Y     = 3 + msgLines,
                Width = Dim.Fill() - 1
            };
            Add(this.nameFieldLabel, nameEntry);

            dirListView = new DirListView(this)
            {
                X      = 1,
                Y      = 3 + msgLines + 2,
                Width  = Dim.Fill() - 3,
                Height = Dim.Fill() - 2,
            };
            DirectoryPath = Path.GetFullPath(Environment.CurrentDirectory);
            Add(dirListView);
            dirListView.DirectoryChanged = (dir) => dirEntry.Text = dir;
            dirListView.FileChanged      = (file) => nameEntry.Text = file;

            this.cancel          = new Button("Cancel");
            this.cancel.Clicked += () => {
                canceled = true;
                Application.RequestStop();
            };
            AddButton(cancel);

            this.prompt = new Button(prompt)
            {
                IsDefault = true,
            };
            this.prompt.Clicked += () => {
                dirListView.ExecuteSelection();
                canceled = false;
                Application.RequestStop();
            };
            AddButton(this.prompt);

            // On success, we will set this to false.
            canceled = true;
        }