public void AnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel() { var viewWidth = 10; var viewHeight = 1; var tv = new TextView() { X = Pos.AnchorEnd(viewWidth), Y = Pos.AnchorEnd(viewHeight), Width = viewWidth, Height = viewHeight }; var win = new Window(); win.Add(tv); var menu = new MenuBar(); var status = new StatusBar(); var top = Application.Top; top.Add(win, menu, status); Application.Begin(top); Assert.Equal(new Rect(0, 0, 80, 25), top.Frame); Assert.Equal(new Rect(0, 0, 80, 1), menu.Frame); Assert.Equal(new Rect(0, 24, 80, 1), status.Frame); Assert.Equal(new Rect(0, 1, 80, 23), win.Frame); Assert.Equal(new Rect(1, 1, 78, 21), win.Subviews [0].Frame); Assert.Equal(new Rect(1, 1, 79, 22), new Rect( win.Subviews [0].Frame.Left, win.Subviews [0].Frame.Top, win.Subviews [0].Frame.Right, win.Subviews [0].Frame.Bottom)); Assert.Equal(new Rect(68, 20, 10, 1), tv.Frame); }
public void AnchorEnd_Negative_Throws() { Pos pos; var n = -1; Assert.Throws <ArgumentException> (() => pos = Pos.AnchorEnd(n)); }
public void AnchorEnd_Equal_Inside_Window() { var viewWidth = 10; var viewHeight = 1; var tv = new TextView() { X = Pos.AnchorEnd(viewWidth), Y = Pos.AnchorEnd(viewHeight), Width = viewWidth, Height = viewHeight }; var win = new Window(); win.Add(tv); var top = Application.Top; top.Add(win); Application.Begin(top); Assert.Equal(new Rect(0, 0, 80, 25), top.Frame); Assert.Equal(new Rect(0, 0, 80, 25), win.Frame); Assert.Equal(new Rect(1, 1, 78, 23), win.Subviews[0].Frame); Assert.Equal("ContentView()({X=1,Y=1,Width=78,Height=23})", win.Subviews [0].ToString()); Assert.Equal(new Rect(1, 1, 79, 24), new Rect( win.Subviews[0].Frame.Left, win.Subviews [0].Frame.Top, win.Subviews [0].Frame.Right, win.Subviews[0].Frame.Bottom)); Assert.Equal(new Rect(68, 22, 10, 1), tv.Frame); }
private void InitSearchButton() { fetchButton.X = Pos.AnchorEnd(11); fetchButton.Y = 1; fetchButton.Width = 10; fetchButton.Clicked = Fetch; this.Add(fetchButton); }
private void InitSearchButton() { searchButton.X = Pos.AnchorEnd(11); searchButton.Y = 1; searchButton.Width = 10; searchButton.Clicked = Search; this.Add(searchButton); }
/// <summary> /// Add UI components to <see cref="_window" /> /// </summary> public MainViewBuilder SetupControls() { var sourceLabel = new Label("Source Translation JSON Folder:") { X = 0, Y = 1 }; _sourceTextField = new TextField(_mainViewModel.SourceFolderPath) { X = Pos.Left(sourceLabel), Y = Pos.Top(sourceLabel) + 1 }; var originLabel = new Label("Origin Resource File:") { X = Pos.Left(sourceLabel), Y = Pos.Top(_sourceTextField) + 2 }; _originTextField = new TextField(_mainViewModel.OriginFilePath) { X = Pos.Left(originLabel), Y = Pos.Top(originLabel) + 1 }; var destinationLabel = new Label("Destination Resource Folder:") { X = Pos.Left(sourceLabel), Y = Pos.Top(_originTextField) + 4 }; _destinationTextField = new TextField(_mainViewModel.DestinationFolderPath) { X = Pos.Left(destinationLabel), Y = Pos.Top(destinationLabel) + 1 }; _runButton = new Button("Run") { X = Pos.Center(), Y = Pos.AnchorEnd(2) }; _window.Add( sourceLabel, _sourceTextField, originLabel, _originTextField, destinationLabel, _destinationTextField, _runButton); return(this); }
public void AnchorEnd_SetsValue() { var n = 0; var pos = Pos.AnchorEnd(); Assert.Equal($"Pos.AnchorEnd(margin={n})", pos.ToString()); n = 5; pos = Pos.AnchorEnd(n); Assert.Equal($"Pos.AnchorEnd(margin={n})", pos.ToString()); }
public void CreateUserInterface() { // Create server info labels _serverInfoFrameView = new FrameView { Width = Dim.Fill(), Height = 8 }; _upTimeLabel = new Label { Y = 0, Width = Dim.Fill(), Height = 1 }; _fpsLabel = new Label { Y = 1, Width = Dim.Fill(), Height = 1 }; _stateLabel = new Label { Y = 2, Width = Dim.Fill(), Height = 1 }; _playersLabel = new Label { Y = 3, Width = Dim.Fill(), Height = 1 }; _mapLabel = new Label { Y = 4, Width = Dim.Fill(), Height = 1 }; _modeLabel = new Label { Y = 5, Width = Dim.Fill(), Height = 1 }; _serverInfoFrameView.Add(_upTimeLabel); _serverInfoFrameView.Add(_fpsLabel); _serverInfoFrameView.Add(_stateLabel); _serverInfoFrameView.Add(_playersLabel); _serverInfoFrameView.Add(_mapLabel); _serverInfoFrameView.Add(_modeLabel); // Create logging/input elements _logList = new List <string>(); _logsListView = new ListView { X = 0, Y = 8, Width = Dim.Fill(), Height = Dim.Fill(1) }; _logsListView.SelectedItemChanged += LogsListView_SelectedItemChanged; _logsListView.SetSource(_logList); _logSelectedIndex = 0; _logAutoScrollEnabled = true; _inputTextField = new TextField { X = 0, Y = Pos.AnchorEnd(1), Width = Dim.Fill(), Height = 1 }; _inputTextField.EnsureFocus(); Add(_serverInfoFrameView); Add(_logsListView); Add(_inputTextField); }
public void AnchorEnd_Equal() { var n1 = 0; var n2 = 0; var pos1 = Pos.AnchorEnd(n1); var pos2 = Pos.AnchorEnd(n2); Assert.Equal(pos1, pos2); // Test inequality n2 = 5; pos2 = Pos.AnchorEnd(n2); Assert.NotEqual(pos1, pos2); }
public static StatusBarView Create() { var statusBar = new StatusBarView() { X = 0, Y = Pos.AnchorEnd(1), Width = Dim.Fill(), Height = 1 }; statusBar.Add( new Label(" ^C - Quit | ^R - Refresh process list | Enter - Show details | Esc - Return to process list") ); return(statusBar); }
private void Win_LayoutStarted(View.LayoutEventArgs obj) { miMultiline.Checked = textViewTopLeft.Multiline; miWrap.Checked = textViewTopLeft.WordWrap; SetMultilineStatusText(); SetWrapStatusText(); if (miMultiline.Checked) { height = 10; } else { height = 1; } textViewBottomLeft.Y = textViewBottomRight.Y = Pos.AnchorEnd(height); }
private void NarrowRunes() { UnsetClickedEvent(); _label.Text = "Enter your name:"; _text.Text = "gui.cs"; _button.Text = "Say Hello"; _button.Clicked += NarrowMessage; _labelR.X = Pos.AnchorEnd(19); _labelR.Y = 18; _labelR.Text = "This is a test text"; _labelV.X = Pos.AnchorEnd(19); _labelV.Y = Pos.Bottom(_labelR); _labelV.Text = "This is a test text"; _win.Title = "HACC Demo"; _lastRunesUsed = "Narrow"; Application.Refresh(); }
private void WideRunes() { UnsetClickedEvent(); _label.Text = "あなたの名前を入力してください:"; _text.Text = "ティラミス"; _button.Text = "こんにちはと言う"; _button.Clicked += WideMessage; _labelR.X = Pos.AnchorEnd(29); _labelR.Y = 18; _labelR.Text = "あなたの名前を入力してください"; _labelV.X = Pos.AnchorEnd(29); _labelV.Y = Pos.Bottom(_labelR); _labelV.Text = "あなたの名前を入力してください"; _win.Title = "デモエムポンズ"; _lastRunesUsed = "Wide"; Application.Refresh(); }
private void MixedRunes() { UnsetClickedEvent(); _label.Text = "Enter your name 你:"; _text.Text = "gui.cs 你:"; _button.Text = "Say Hello 你"; _button.Clicked += MixedMessage; _labelR.X = Pos.AnchorEnd(21); _labelR.Y = 18; _labelR.Text = "This is a test text 你"; _labelV.X = Pos.AnchorEnd(21); _labelV.Y = Pos.Bottom(_labelR); _labelV.Text = "This is a test text 你"; _win.Title = "HACC Demo 你"; _lastRunesUsed = "Mixed"; Application.Refresh(); }
public void Show_Ensures_Display_Inside_The_Container_Without_Overlap_The_Host() { var view = new View("View") { X = Pos.AnchorEnd(10), Y = Pos.AnchorEnd(1), Width = 10, Height = 1 }; var cm = new ContextMenu(view, new MenuBarItem(new MenuItem [] { new MenuItem("One", "", null), new MenuItem("Two", "", null) }) ); Application.Top.Add(view); Application.Begin(Application.Top); Assert.Equal(new Rect(70, 24, 10, 1), view.Frame); Assert.Equal(new Point(0, 0), cm.Position); cm.Show(); Assert.Equal(new Point(70, 24), cm.Position); Application.Top.Redraw(Application.Top.Bounds); var expected = @" ┌──────┐ │ One │ │ Two │ └──────┘ View "; var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output); Assert.Equal(new Rect(70, 20, 78, 5), pos); cm.Hide(); Assert.Equal(new Point(70, 24), cm.Position); }
/// <summary> /// Setup the scenario. /// </summary> public override void Setup() { // Scenario Window's. Win.Title = this.GetName(); // Forground ColorPicker. foregroundColorPicker = new ColorPicker("Foreground Color"); foregroundColorPicker.X = 0; foregroundColorPicker.Y = 0; foregroundColorPicker.ColorChanged += ForegroundColor_ColorChanged; Win.Add(foregroundColorPicker); foregroundColorLabel = new Label(); foregroundColorLabel.X = Pos.Left(foregroundColorPicker); foregroundColorLabel.Y = Pos.Bottom(foregroundColorPicker) + 1; Win.Add(foregroundColorLabel); // Background ColorPicker. backgroundColorPicker = new ColorPicker(); backgroundColorPicker.Text = "Background Color"; backgroundColorPicker.X = Pos.AnchorEnd() - (Pos.Right(backgroundColorPicker) - Pos.Left(backgroundColorPicker)); backgroundColorPicker.Y = 0; backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged; Win.Add(backgroundColorPicker); backgroundColorLabel = new Label(); backgroundColorLabel.X = Pos.AnchorEnd() - (Pos.Right(backgroundColorLabel) - Pos.Left(backgroundColorLabel)); backgroundColorLabel.Y = Pos.Bottom(backgroundColorPicker) + 1; Win.Add(backgroundColorLabel); // Demo Label. demoLabel = new Label("Lorem Ipsum"); demoLabel.X = Pos.Center(); demoLabel.Y = 1; Win.Add(demoLabel); // Set default colors. backgroundColorPicker.SelectedColor = demoLabel.SuperView.ColorScheme.Normal.Background; foregroundColorPicker.SelectedColor = demoLabel.SuperView.ColorScheme.Normal.Foreground; }
public Bar(Color BarColor, Color BackgroundColor) { DrawFrame(this.Bounds, 0, false); Label openingBraquet = new Label("[") { X = 0, Y = 0 }; Add(openingBraquet); Label closingBraquet = new Label("]") { X = Pos.AnchorEnd(7), Y = 0 }; Add(closingBraquet); percentBar = new Label(string.Empty) { X = Pos.Right(openingBraquet), Y = 0, Width = Dim.Fill(7) }; percentBar.TextColor = Terminal.Gui.Attribute.Make(BarColor, BackgroundColor); Add(percentBar); percentText = new Label(string.Empty) { X = Pos.Right(closingBraquet), Y = 0, }; Add(percentText); }
public IpRangeView() { Width = Dim.Fill(); Height = Dim.Sized(1); // Dim.Fill(); var firstIpLabel = new Label("First Ip "); var firstIpText = new TextField("") { X = Pos.Right(firstIpLabel), Width = 15 }; var lastIpLabel = new Label(" Last ") { X = Pos.Right(firstIpText) }; var lastIpText = new TextField("") { X = Pos.Right(lastIpLabel), Width = 15 }; var scanButton = new Button("Scan"); scanButton.X = Pos.AnchorEnd() - (Pos.Right(scanButton) - Pos.Left(scanButton)); Add(firstIpLabel, lastIpLabel, firstIpText, lastIpText, scanButton); }
public override void Setup() { var text = "Context Menu"; var width = 20; Win.Add(new Label("Press 'Ctrl + Space' to open the Window context menu.") { X = Pos.Center(), Y = 1 }); tfTopLeft = new TextField(text) { Width = width }; Win.Add(tfTopLeft); tfTopRight = new TextField(text) { X = Pos.AnchorEnd(width), Width = width }; Win.Add(tfTopRight); tfMiddle = new TextField(text) { X = Pos.Center(), Y = Pos.Center(), Width = width }; Win.Add(tfMiddle); tfBottomLeft = new TextField(text) { Y = Pos.AnchorEnd(1), Width = width }; Win.Add(tfBottomLeft); tfBottomRight = new TextField(text) { X = Pos.AnchorEnd(width), Y = Pos.AnchorEnd(1), Width = width }; Win.Add(tfBottomRight); Point mousePos = default; Win.KeyPress += (e) => { if (e.KeyEvent.Key == (Key.Space | Key.CtrlMask)) { ShowContextMenu(mousePos.X, mousePos.Y); e.Handled = true; } }; Win.MouseClick += (e) => { if (e.MouseEvent.Flags == contextMenu.MouseFlags) { ShowContextMenu(e.MouseEvent.X, e.MouseEvent.Y); e.Handled = true; } }; Application.RootMouseEvent += Application_RootMouseEvent; void Application_RootMouseEvent(MouseEvent me) { mousePos = new Point(me.X, me.Y); } Win.WantMousePositionReports = true; Top.Closed += (_) => { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Application.RootMouseEvent -= Application_RootMouseEvent; }; }
void DimPosChanged(View view) { if (view == null) { return; } try { switch (_xRadioGroup.Selected) { case 0: view.X = Pos.Percent(_xVal); break; case 1: view.X = Pos.AnchorEnd(_xVal); break; case 2: view.X = Pos.Center(); break; case 3: view.X = Pos.At(_xVal); break; } switch (_yRadioGroup.Selected) { case 0: view.Y = Pos.Percent(_yVal); break; case 1: view.Y = Pos.AnchorEnd(_yVal); break; case 2: view.Y = Pos.Center(); break; case 3: view.Y = Pos.At(_yVal); break; } switch (_wRadioGroup.Selected) { case 0: view.Width = Dim.Percent(_wVal); break; case 1: view.Width = Dim.Fill(_wVal); break; case 2: view.Width = Dim.Sized(_wVal); break; } switch (_hRadioGroup.Selected) { case 0: view.Height = Dim.Percent(_hVal); break; case 1: view.Height = Dim.Fill(_hVal); break; case 2: view.Height = Dim.Sized(_hVal); break; } } catch (Exception e) { MessageBox.ErrorQuery("Exception", e.Message, "Ok"); } UpdateTitle(view); }
public override void Setup() { var borderStyle = BorderStyle.Double; var drawMarginFrame = false; var borderThickness = new Thickness(1, 2, 3, 4); var borderBrush = Colors.Base.HotFocus.Foreground; var padding = new Thickness(1, 2, 3, 4); var background = Colors.Base.HotNormal.Foreground; var effect3D = true; var smartView = new Window() { X = Pos.Center(), Y = Pos.Center() - 7, Width = 40, Height = 20, Border = new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }, ColorScheme = Colors.TopLevel }; var tf1 = new TextField("1234567890") { Width = 10 }; var button = new Button("Press me!") { X = Pos.Center(), Y = Pos.Center(), }; button.Clicked += () => MessageBox.Query(20, 7, "Hi", "I'm a Window?", "Yes", "No"); var label = new Label("I'm a Window") { X = Pos.Center(), Y = Pos.Center() - 3, }; var tf2 = new TextField("1234567890") { X = Pos.AnchorEnd(10), Y = Pos.AnchorEnd(1), Width = 10 }; var tv = new TextView() { Y = Pos.AnchorEnd(2), Width = 10, Height = Dim.Fill(), ColorScheme = Colors.Dialog, Text = "1234567890" }; smartView.Add(tf1, button, label, tf2, tv); Win.Add(new Label("Padding:") { X = Pos.Center() - 23, }); var paddingTopEdit = new TextField("") { X = Pos.Center() - 22, Y = 1, Width = 5 }; paddingTopEdit.TextChanging += (e) => { try { smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, int.Parse(e.NewText.ToString()), smartView.Border.Padding.Right, smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingTopEdit.Text = $"{smartView.Border.Padding.Top}"; Win.Add(paddingTopEdit); var paddingLeftEdit = new TextField("") { X = Pos.Center() - 30, Y = 2, Width = 5 }; paddingLeftEdit.TextChanging += (e) => { try { smartView.Border.Padding = new Thickness(int.Parse(e.NewText.ToString()), smartView.Border.Padding.Top, smartView.Border.Padding.Right, smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingLeftEdit.Text = $"{smartView.Border.Padding.Left}"; Win.Add(paddingLeftEdit); var paddingRightEdit = new TextField("") { X = Pos.Center() - 15, Y = 2, Width = 5 }; paddingRightEdit.TextChanging += (e) => { try { smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, smartView.Border.Padding.Top, int.Parse(e.NewText.ToString()), smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingRightEdit.Text = $"{smartView.Border.Padding.Right}"; Win.Add(paddingRightEdit); var paddingBottomEdit = new TextField("") { X = Pos.Center() - 22, Y = 3, Width = 5 }; paddingBottomEdit.TextChanging += (e) => { try { smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, smartView.Border.Padding.Top, smartView.Border.Padding.Right, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingBottomEdit.Text = $"{smartView.Border.Padding.Bottom}"; Win.Add(paddingBottomEdit); var replacePadding = new Button("Replace all based on top") { X = Pos.Center() - 35, Y = 5 }; replacePadding.Clicked += () => { smartView.Border.Padding = new Thickness(smartView.Border.Padding.Top); if (paddingTopEdit.Text.IsEmpty) { paddingTopEdit.Text = "0"; } paddingBottomEdit.Text = paddingLeftEdit.Text = paddingRightEdit.Text = paddingTopEdit.Text; }; Win.Add(replacePadding); Win.Add(new Label("Border:") { X = Pos.Center() + 11, }); var borderTopEdit = new TextField("") { X = Pos.Center() + 12, Y = 1, Width = 5 }; borderTopEdit.TextChanging += (e) => { try { smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Right, smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderTopEdit.Text = $"{smartView.Border.BorderThickness.Top}"; Win.Add(borderTopEdit); var borderLeftEdit = new TextField("") { X = Pos.Center() + 5, Y = 2, Width = 5 }; borderLeftEdit.TextChanging += (e) => { try { smartView.Border.BorderThickness = new Thickness(int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderLeftEdit.Text = $"{smartView.Border.BorderThickness.Left}"; Win.Add(borderLeftEdit); var borderRightEdit = new TextField("") { X = Pos.Center() + 19, Y = 2, Width = 5 }; borderRightEdit.TextChanging += (e) => { try { smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderRightEdit.Text = $"{smartView.Border.BorderThickness.Right}"; Win.Add(borderRightEdit); var borderBottomEdit = new TextField("") { X = Pos.Center() + 12, Y = 3, Width = 5 }; borderBottomEdit.TextChanging += (e) => { try { smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderBottomEdit.Text = $"{smartView.Border.BorderThickness.Bottom}"; Win.Add(borderBottomEdit); var replaceBorder = new Button("Replace all based on top") { X = Pos.Center() + 1, Y = 5 }; replaceBorder.Clicked += () => { smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Top); if (borderTopEdit.Text.IsEmpty) { borderTopEdit.Text = "0"; } borderBottomEdit.Text = borderLeftEdit.Text = borderRightEdit.Text = borderTopEdit.Text; }; Win.Add(replaceBorder); Win.Add(new Label("BorderStyle:")); var borderStyleEnum = Enum.GetValues(typeof(BorderStyle)).Cast <BorderStyle> ().ToList(); var rbBorderStyle = new RadioGroup(borderStyleEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = 2, Y = 1, SelectedItem = (int)smartView.Border.BorderStyle }; Win.Add(rbBorderStyle); var cbDrawMarginFrame = new CheckBox("Draw Margin Frame", smartView.Border.DrawMarginFrame) { X = Pos.AnchorEnd(20), Y = 0, Width = 5 }; cbDrawMarginFrame.Toggled += (e) => { try { smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked; if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame; } } catch { } }; Win.Add(cbDrawMarginFrame); rbBorderStyle.SelectedItemChanged += (e) => { smartView.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartView.SetNeedsDisplay(); if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame; } }; var cbEffect3D = new CheckBox("Draw 3D effects", smartView.Border.Effect3D) { X = Pos.AnchorEnd(20), Y = 1, Width = 5 }; Win.Add(cbEffect3D); Win.Add(new Label("Effect3D Offset:") { X = Pos.AnchorEnd(20), Y = 2 }); Win.Add(new Label("X:") { X = Pos.AnchorEnd(19), Y = 3 }); var effect3DOffsetX = new TextField("") { X = Pos.AnchorEnd(16), Y = 3, Width = 5 }; effect3DOffsetX.TextChanging += (e) => { try { smartView.Border.Effect3DOffset = new Point(int.Parse(e.NewText.ToString()), smartView.Border.Effect3DOffset.Y); } catch { if (!e.NewText.IsEmpty && e.NewText != CultureInfo.CurrentCulture.NumberFormat.NegativeSign) { e.Cancel = true; } } }; effect3DOffsetX.Text = $"{smartView.Border.Effect3DOffset.X}"; Win.Add(effect3DOffsetX); Win.Add(new Label("Y:") { X = Pos.AnchorEnd(10), Y = 3 }); var effect3DOffsetY = new TextField("") { X = Pos.AnchorEnd(7), Y = 3, Width = 5 }; effect3DOffsetY.TextChanging += (e) => { try { smartView.Border.Effect3DOffset = new Point(smartView.Border.Effect3DOffset.X, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty && e.NewText != CultureInfo.CurrentCulture.NumberFormat.NegativeSign) { e.Cancel = true; } } }; effect3DOffsetY.Text = $"{smartView.Border.Effect3DOffset.Y}"; Win.Add(effect3DOffsetY); cbEffect3D.Toggled += (e) => { try { smartView.Border.Effect3D = effect3DOffsetX.Enabled = effect3DOffsetY.Enabled = cbEffect3D.Checked; } catch { } }; Win.Add(new Label("Background:") { Y = 5 }); var colorEnum = Enum.GetValues(typeof(Color)).Cast <Color> ().ToList(); var rbBackground = new RadioGroup(colorEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = 2, Y = 6, SelectedItem = (int)smartView.Border.Background }; rbBackground.SelectedItemChanged += (e) => { smartView.Border.Background = (Color)e.SelectedItem; }; Win.Add(rbBackground); Win.Add(new Label("BorderBrush:") { X = Pos.AnchorEnd(20), Y = 5 }); var rbBorderBrush = new RadioGroup(colorEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = Pos.AnchorEnd(18), Y = 6, SelectedItem = (int)smartView.Border.BorderBrush }; rbBorderBrush.SelectedItemChanged += (e) => { smartView.Border.BorderBrush = (Color)e.SelectedItem; }; Win.Add(rbBorderBrush); Win.Add(smartView); }
private void Draw() { var Window = new Window("Management", 1) { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill() }; Application.Top.Add(Window); var ServerBindingLabel = new Label("Server Binding: ") { X = 3, Y = 2, }; var ServerBindingText = new TextField(ServerOptions.CurrentValue.IPEndPoint.ToString()) { X = Pos.Right(ServerBindingLabel) + 2, Y = Pos.Top(ServerBindingLabel), Width = 30 }; var StartButton = new Button("Start Server", true) { X = Pos.AnchorEnd(37), Y = Pos.AnchorEnd(1), Clicked = async() => await StartServerAsync() }; var StopButton = new Button("Stop Server") { X = Pos.AnchorEnd(16), Y = Pos.AnchorEnd(1), Clicked = async() => await StopServerAsync() }; var MenuBar = new MenuBar(new[] { new MenuBarItem("SecureDNS", new [] { new MenuItem("Start", "Server", async() => await StartServerAsync()), new MenuItem("Stop", "Server", async() => await StopServerAsync()), new MenuItem("Quit", "System", Application.RequestStop), }), //new MenuBarItem ("Seq", new [] //{ // new MenuItem ("Browse", "", () => Browse(SeqEndPointText.Text.ToString())), //}), new MenuBarItem("About", new[] { new MenuItem("Browse", "GitHub", () => Browse("https://github.com/Texnomic/SecureDNS")), }) }); Application.Top.Add(MenuBar); var StatusListView = new ListView() { X = Pos.Left(ServerBindingLabel), Y = Pos.Top(ServerBindingLabel) + 5, Width = 40, Height = 15, }; StatusTimer.Elapsed += (Sender, Args) => StatusListView.SetSource(Server.Status().Distinct().ToList()); Window.Add(ServerBindingLabel, ServerBindingText, StartButton, StopButton, StatusListView, StatusListView); }
public StagingUIController() { X = Pos.Center(); Y = Pos.Center(); Width = Dim.Percent(85); Height = Dim.Percent(85); ColorScheme = Colors.Dialog; Title = "Run Worker"; label = new Label("Press start to do the work or close to exit.") { X = Pos.Center(), Y = 1, ColorScheme = Colors.Dialog }; Add(label); listView = new ListView() { X = 0, Y = 2, Width = Dim.Fill(), Height = Dim.Fill(2) }; Add(listView); start = new Button("Start") { IsDefault = true }; start.Clicked += () => { Staging = new Staging(DateTime.Now); RequestStop(); }; Add(start); close = new Button("Close"); close.Clicked += OnReportClosed; Add(close); KeyPress += (e) => { if (e.KeyEvent.Key == Key.Esc) { OnReportClosed(); } }; LayoutStarted += (_) => { var btnsWidth = start.Bounds.Width + close.Bounds.Width + 2 - 1; var shiftLeft = Math.Max((Bounds.Width - btnsWidth) / 2 - 2, 0); shiftLeft += close.Bounds.Width + 1; close.X = Pos.AnchorEnd(shiftLeft); close.Y = Pos.AnchorEnd(1); shiftLeft += start.Bounds.Width + 1; start.X = Pos.AnchorEnd(shiftLeft); start.Y = Pos.AnchorEnd(1); }; }
public void Start() { Application.UseSystemConsole = true; Application.Init(); Application.MainLoop.AddIdle(OnMainLoopIdle); var top = Application.Top; var topFrame = top.Frame; _logWindow = new Window("Debugger Log") { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill() - 3, CanFocus = false }; // _logView = new Filler( // new Rect(0, 0, 200, 200) // ); _textView = new LogView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), CanFocus = false }; _logWindow.Add(_textView); _scrollBar = new ScrollBarView(_textView, true); _scrollBar.ChangedPosition += () => { _textView.TopRow = _scrollBar.Position; if (_textView.TopRow != _scrollBar.Position) { _scrollBar.Position = _textView.TopRow; } _textView.SetNeedsDisplay(); }; _scrollBar.OtherScrollBarView.ChangedPosition += () => { _textView.LeftColumn = _scrollBar.OtherScrollBarView.Position; if (_textView.LeftColumn != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _textView.LeftColumn; } _textView.SetNeedsDisplay(); }; _textView.DrawContent += (e) => { _scrollBar.Size = _textView.Lines - 1; _scrollBar.Position = _textView.TopRow; _scrollBar.OtherScrollBarView.Size = _textView.Maxlength; _scrollBar.OtherScrollBarView.Position = _textView.LeftColumn; _scrollBar.LayoutSubviews(); _scrollBar.Refresh(); }; var commandBar = new View() { X = 0, Y = Pos.AnchorEnd(3), Width = Dim.Fill(), Height = 2 }; var commandBarText = new Label("Enter debugger commands") { X = 0, Y = 0, Width = Dim.Fill(), Height = 1 }; var commandLabel = new Label(">") { X = 0, Y = 1, Width = 1, Height = 1 }; var commandText = new CommandField { X = 1, Y = 1, Width = Dim.Fill(), Height = 1, CanFocus = true, TabIndex = 0, }; commandText.CommandEntered += (s, e) => { _parser?.Parse(e); commandBar.SetFocus(); }; commandBar.Add(commandBarText, commandLabel, commandText); _menuBar = new MenuBar( new MenuBarItem[] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Save", "Save program", SaveFile), new MenuItem("_Open", "Open program", OpenFile), new MenuItem("_Quit", "", () => { if (Quit()) { top.Running = false; } }) }), new MenuBarItem("_Debug", new MenuItem [] { new MenuItem("_Continue", "", null), new MenuItem("_Pause", "", null), new MenuItem("_Step", "", null) }) }); _statusBar = new StatusBar() { ColorScheme = Colors.TopLevel, Visible = true, Items = new StatusItem[] { _runMode, _A, _X, _Y, _PC, _SP, _C, _Z, _I, _D, _B, _B2, _V, _N } }; top.Add(_logWindow); top.Add(commandBar); top.Add(_menuBar); top.Add(_statusBar); Application.Run(); commandBar.SetFocus(); }
public ReplApp() : base($"{nameof(CSharpScriptRunner)} REPL, {BuildInfo.ReleaseTag}, EXPERIMENTAL") { ColorScheme = new() { Normal = new(Color.White, Color.Black), Focus = new(Color.White, Color.Black), Disabled = new(Color.White, Color.Black), HotNormal = new(Color.White, Color.Black), HotFocus = new(Color.White, Color.Black) }; Label labelInput = new() { X = 0, Y = Pos.AnchorEnd() - 1, Height = 1, Text = "> " }; _ctrlInput = new() { X = Pos.Right(labelInput), Y = Pos.AnchorEnd() - 1, Width = Dim.Fill(), Height = 1 }; _ctrlHistory = new() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() - Dim.Height(_ctrlInput), ReadOnly = true }; _ctrlIntellisense = new() { X = 0, Y = 0, Height = MaxIntellisenseHeight, Visible = false }; _ctrlIntellisense.ColorScheme = new() { Normal = new(Color.White, Color.DarkGray), HotNormal = new(Color.White, Color.Blue), Focus = new(Color.White, Color.DarkGray), HotFocus = new(Color.White, Color.Blue) }; Add(_ctrlHistory, _ctrlIntellisense, labelInput, _ctrlInput); _ctrlInput.SetFocus(); _ctrlHistory.KeyPress += OnKeyPressHistory; _ctrlInput.KeyPress += OnKeyPressInput; _ctrlInput.KeyUp += OnKeyUpInput; _ctrlInput.TextChanged += OnTextChangedInput; _script = CSharpScript.Create(string.Empty); // https://www.strathweb.com/2018/12/using-roslyn-c-completion-service-programmatically/ var host = MefHostServices.DefaultHost; _ws = new AdhocWorkspace(host); _projectId = ProjectId.CreateNewId(); var projectInfo = ProjectInfo.Create(_projectId, VersionStamp.Default, "Script", "Script", LanguageNames.CSharp, isSubmission: true) .WithCompilationOptions(_script.GetCompilation().Options) .WithMetadataReferences(_script.GetCompilation().References); var project = _ws.AddProject(projectInfo); var docInfo = DocumentInfo.Create(DocumentId.CreateNewId(_projectId), "Script", sourceCodeKind: SourceCodeKind.Script); _doc = _ws.AddDocument(docInfo); } void OnKeyPressHistory(View.KeyEventEventArgs args) { if (args.KeyEvent.Key == Key.Tab) { args.Handled = true; _ctrlInput.SetFocus(); } } void OnKeyPressInput(View.KeyEventEventArgs args) { if (_ctrlIntellisense.Visible) { switch (args.KeyEvent.Key) { default: return; case Key.CursorDown: if (_ctrlIntellisense.SelectedItem == _ctrlIntellisense.Source.Count - 1) { _ctrlIntellisense.MoveHome(); } else { _ctrlIntellisense.MoveDown(); } break; case Key.CursorUp: if (_ctrlIntellisense.SelectedItem == 0) { _ctrlIntellisense.MoveEnd(); } else { _ctrlIntellisense.MoveUp(); } break; case Key.Tab: var item = _ctrlIntellisense.Source.ToList()[_ctrlIntellisense.SelectedItem].ToString(); var text = _ctrlInput.Text.ToString(); var cursorsPos = text.Length + item.Length; text = text.Substring(0, _idxIntellisense) + item; _ctrlInput.Text = text; _ctrlInput.CursorPosition = cursorsPos; _ctrlIntellisense.Visible = false; break; } _ctrlIntellisense.SetNeedsDisplay(); args.Handled = true; } } async void OnKeyUpInput(View.KeyEventEventArgs args) { if (args.KeyEvent.Key == Key.Enter) { if (_ctrlInput.Text.IsEmpty || _isProcessing) { return; } _isProcessing = true; var code = _ctrlInput.Text.ToString().TrimEnd(); var newScript = _script.ContinueWith(code); var diagnostics = newScript.Compile(); var output = new List <string>(); output.Add($"> {code}"); var success = true; foreach (var diag in diagnostics) { if (diag.Severity == DiagnosticSeverity.Error) { success = false; } var loc = diag.Location.GetLineSpan(); output.Add($"{diag.Severity} ({loc.StartLinePosition.Line}, {loc.StartLinePosition.Character}): {diag.GetMessage()}"); } if (success) { var result = await newScript.RunAsync(); if (result.ReturnValue is string value) { value = SymbolDisplay.FormatLiteral(value, true); } else { value = result.ReturnValue?.ToString(); } if (!string.IsNullOrEmpty(value)) { output.Add(value); } _script = newScript; if (!code.EndsWith(';')) { code += ';'; } _scriptCode += code; } output.Add(string.Empty); _ctrlHistory.Text += string.Join(Environment.NewLine, output); _ctrlHistory.MoveEnd(); _ctrlInput.Text = string.Empty; _isProcessing = false; } else if (args.KeyEvent.Key == Key.CursorLeft || args.KeyEvent.Key == Key.CursorRight) { OnTextChangedInput(_ctrlInput.Text); } } async void OnTextChangedInput(NStack.ustring oldText) { if (_ctrlInput.Text.IsEmpty) { _ctrlIntellisense.Visible = false; return; } var code = _scriptCode + _ctrlInput.Text.ToString(); var doc = _doc.WithText(SourceText.From(code)); var service = CompletionService.GetService(doc); var completion = await service.GetCompletionsAsync(doc, Math.Min(_ctrlInput.CursorPosition + _scriptCode.Length, code.Length)); if (completion == null) { _ctrlIntellisense.Visible = false; return; } var items = completion.Items; if (items != null) { var filter = code.Substring(0, Math.Min(_ctrlInput.CursorPosition + _scriptCode.Length, code.Length)); var idx = filter.LastIndexOfAny(completion.Rules.DefaultCommitCharacters.ToArray()); if (idx > -1) { filter = filter.Substring(idx); } items = service.FilterItems(doc, items, filter); _idxIntellisense = idx + 1 - _scriptCode.Length; } if (items.Length == 0) { _ctrlIntellisense.Visible = false; } else { var completionItems = items.Select(x => x.DisplayText).ToList(); _ctrlIntellisense.SetSource(completionItems); _ctrlIntellisense.X = Pos.Left(_ctrlInput) + _idxIntellisense; _ctrlIntellisense.Y = Pos.Top(_ctrlInput) - Math.Min(completionItems.Count, MaxIntellisenseHeight); _ctrlIntellisense.Width = _ctrlIntellisense.Maxlength; // _ctrlIntellisense.Height = height; _ctrlIntellisense.Visible = true; } } } }
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;
public override void Init(Toplevel top, ColorScheme colorScheme) { Application.Init(); var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("Margin", new MenuItem [] { new MenuItem("With margin", "", WithMargin), new MenuItem("Without margin", "", WithoutMargin) }), new MenuBarItem("Draw Margin Frame", new MenuItem [] { new MenuItem("With draw", "", WithDrawMargin), new MenuItem("Without draw", "", WithoutDrawMargin) }), new MenuBarItem("Runes length", new MenuItem [] { new MenuItem("Wide", "", WideRunes), new MenuItem("Narrow", "", NarrowRunes), new MenuItem("Mixed", "", MixedRunes) }) }); _label = new Label() { X = Pos.Center(), Y = 0, ColorScheme = new ColorScheme() { Normal = Colors.Base.Focus } }; _text = new TextField() { X = Pos.Center(), Y = 2, Width = 20 }; _button = new Button() { X = Pos.Center(), Y = 4 }; _labelR = new Label() { X = Pos.AnchorEnd(30), Y = 18 }; _labelV = new Label() { TextDirection = TextDirection.TopBottom_LeftRight, X = Pos.AnchorEnd(30), Y = Pos.Bottom(_labelR) }; _win = new Window() { X = 5, Y = 5, Width = Dim.Fill(22), Height = Dim.Fill(5) }; _win.Add(_label, _text, _button, _labelR, _labelV); Application.Top.Add(menu, _win); WideRunes(); //NarrowRunes (); //MixedRunes (); Application.Run(); }
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;
// ReSharper disable once UnusedMember.Local private void OnExecute() { var loggerFactory = LoggerFactory.Create(builder => builder .SetMinimumLevel(Verbosity) .AddConsole()); var analyzer = new DependencyAnalyzer(loggerFactory); DependencyGraph graph; if (!string.IsNullOrEmpty(Package)) { graph = analyzer.Analyze(Package, Version, Framework); } else if (Path.GetExtension(Project).Equals(".sln", StringComparison.OrdinalIgnoreCase)) { graph = analyzer.AnalyzeSolution(Project, Framework); } else { graph = analyzer.Analyze(Project, Framework); } Application.Init(); var top = new CustomWindow(); var left = new FrameView("Dependencies") { Width = Dim.Percent(50), Height = Dim.Fill(1) }; var right = new View() { X = Pos.Right(left), Width = Dim.Fill(), Height = Dim.Fill(1) }; var helpText = new Label("Use arrow keys and Tab to move around. Ctrl+D to toggle assembly visibility. Esc to quit.") { Y = Pos.AnchorEnd(1) }; var runtimeDepends = new FrameView("Runtime depends") { Width = Dim.Fill(), Height = Dim.Percent(33f) }; var packageDepends = new FrameView("Package depends") { Y = Pos.Bottom(runtimeDepends), Width = Dim.Fill(), Height = Dim.Percent(50f) }; var reverseDepends = new FrameView("Reverse depends") { Y = Pos.Bottom(packageDepends), Width = Dim.Fill(), Height = Dim.Fill() }; var orderedDependencyList = graph.Nodes.OrderBy(x => x.Id).ToImmutableList(); var dependenciesView = new ListView(orderedDependencyList) { CanFocus = true, AllowsMarking = false }; left.Add(dependenciesView); var runtimeDependsView = new ListView(Array.Empty <Node>()) { CanFocus = true, AllowsMarking = false }; runtimeDepends.Add(runtimeDependsView); var packageDependsView = new ListView(Array.Empty <Node>()) { CanFocus = true, AllowsMarking = false }; packageDepends.Add(packageDependsView); var reverseDependsView = new ListView(Array.Empty <Node>()) { CanFocus = true, AllowsMarking = false }; reverseDepends.Add(reverseDependsView); right.Add(runtimeDepends, packageDepends, reverseDepends); top.Add(left, right, helpText); Application.Top.Add(top); top.Dependencies = orderedDependencyList; top.VisibleDependencies = orderedDependencyList; top.DependenciesView = dependenciesView; dependenciesView.SelectedItem = 0; UpdateLists(); dependenciesView.SelectedChanged += UpdateLists; Application.Run(); void UpdateLists() { var selectedNode = top.VisibleDependencies[dependenciesView.SelectedItem]; runtimeDependsView.SetSource(graph.Edges.Where(x => x.Start.Equals(selectedNode) && x.End is AssemblyReferenceNode) .Select(x => x.End).ToImmutableList()); packageDependsView.SetSource(graph.Edges.Where(x => x.Start.Equals(selectedNode) && x.End is PackageReferenceNode) .Select(x => $"{x.End}{(string.IsNullOrEmpty(x.Label) ? string.Empty : " (Wanted: " + x.Label + ")")}").ToImmutableList()); reverseDependsView.SetSource(graph.Edges.Where(x => x.End.Equals(selectedNode)) .Select(x => $"{x.Start}{(string.IsNullOrEmpty(x.Label) ? string.Empty : " (Wanted: " + x.Label + ")")}").ToImmutableList()); } }
public override void Setup() { var borderStyle = BorderStyle.Single; var drawMarginFrame = true; var borderThickness = new Thickness(2); var borderBrush = Color.Red; var padding = new Thickness(2); var background = Color.BrightGreen; var effect3D = true; var smartPanel = new PanelView() { X = Pos.Center() - 38, Y = Pos.Center() - 3, Width = 24, Height = 13, Border = new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }, }; smartPanel.Add(new Label() // Or smartPanel.Child = { X = 0, Y = 0, //Width = 24, commenting because now setting the size disable auto-size //Height = 13, ColorScheme = Colors.TopLevel, Text = "This is a test\nwith a \nPanelView", TextAlignment = TextAlignment.Centered }); // Can be initialized this way too. //var smartPanel = new PanelView (new Label () { // X = Pos.Center () - 38, // Y = Pos.Center () - 3, // Width = 24, // Height = 13, // Border = new Border () { // BorderStyle = borderStyle, // DrawMarginFrame = drawMarginFrame, // BorderThickness = borderThickness, // BorderBrush = borderBrush, // Padding = padding, // Background = background, // Effect3D = effect3D // }, // ColorScheme = Colors.TopLevel, // Text = "This is a test\nwith a \nPanelView", // TextAlignment = TextAlignment.Centered //}) { // X = Pos.Center () - 38, // Y = Pos.Center () - 3, // Width = 24, // Height = 13 //}; var smartView = new Label() { X = Pos.Center() + 10, Y = Pos.Center() + 2, Border = new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }, ColorScheme = Colors.TopLevel, Text = "This is a test\nwithout a \nPanelView", TextAlignment = TextAlignment.Centered }; smartView.Border.Child = smartView; Win.Add(new Label("Padding:") { X = Pos.Center() - 23, }); var paddingTopEdit = new TextField("") { X = Pos.Center() - 22, Y = 1, Width = 5 }; paddingTopEdit.TextChanging += (e) => { try { smartPanel.Child.Border.Padding = new Thickness(smartPanel.Child.Border.Padding.Left, int.Parse(e.NewText.ToString()), smartPanel.Child.Border.Padding.Right, smartPanel.Child.Border.Padding.Bottom); smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, int.Parse(e.NewText.ToString()), smartView.Border.Padding.Right, smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingTopEdit.Text = $"{smartView.Border.Padding.Top}"; Win.Add(paddingTopEdit); var paddingLeftEdit = new TextField("") { X = Pos.Center() - 30, Y = 2, Width = 5 }; paddingLeftEdit.TextChanging += (e) => { try { smartPanel.Child.Border.Padding = new Thickness(int.Parse(e.NewText.ToString()), smartPanel.Child.Border.Padding.Top, smartPanel.Child.Border.Padding.Right, smartPanel.Child.Border.Padding.Bottom); smartView.Border.Padding = new Thickness(int.Parse(e.NewText.ToString()), smartView.Border.Padding.Top, smartView.Border.Padding.Right, smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingLeftEdit.Text = $"{smartView.Border.Padding.Left}"; Win.Add(paddingLeftEdit); var paddingRightEdit = new TextField("") { X = Pos.Center() - 15, Y = 2, Width = 5 }; paddingRightEdit.TextChanging += (e) => { try { smartPanel.Child.Border.Padding = new Thickness(smartPanel.Child.Border.Padding.Left, smartPanel.Child.Border.Padding.Top, int.Parse(e.NewText.ToString()), smartPanel.Child.Border.Padding.Bottom); smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, smartView.Border.Padding.Top, int.Parse(e.NewText.ToString()), smartView.Border.Padding.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingRightEdit.Text = $"{smartView.Border.Padding.Right}"; Win.Add(paddingRightEdit); var paddingBottomEdit = new TextField("") { X = Pos.Center() - 22, Y = 3, Width = 5 }; paddingBottomEdit.TextChanging += (e) => { try { smartPanel.Child.Border.Padding = new Thickness(smartPanel.Child.Border.Padding.Left, smartPanel.Child.Border.Padding.Top, smartPanel.Child.Border.Padding.Right, int.Parse(e.NewText.ToString())); smartView.Border.Padding = new Thickness(smartView.Border.Padding.Left, smartView.Border.Padding.Top, smartView.Border.Padding.Right, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; paddingBottomEdit.Text = $"{smartView.Border.Padding.Bottom}"; Win.Add(paddingBottomEdit); var replacePadding = new Button("Replace all based on top") { X = Pos.Center() - 35, Y = 5 }; replacePadding.Clicked += () => { smartPanel.Child.Border.Padding = new Thickness(smartPanel.Child.Border.Padding.Top); smartView.Border.Padding = new Thickness(smartView.Border.Padding.Top); if (paddingTopEdit.Text.IsEmpty) { paddingTopEdit.Text = "0"; } paddingBottomEdit.Text = paddingLeftEdit.Text = paddingRightEdit.Text = paddingTopEdit.Text; }; Win.Add(replacePadding); var cbUseUsePanelFrame = new CheckBox("UsePanelFrame") { X = Pos.X(replacePadding), Y = Pos.Y(replacePadding) + 3, Checked = smartPanel.UsePanelFrame }; cbUseUsePanelFrame.Toggled += (e) => smartPanel.UsePanelFrame = !e; Win.Add(cbUseUsePanelFrame); Win.Add(new Label("Border:") { X = Pos.Center() + 11, }); var borderTopEdit = new TextField("") { X = Pos.Center() + 12, Y = 1, Width = 5 }; borderTopEdit.TextChanging += (e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness(smartPanel.Child.Border.BorderThickness.Left, int.Parse(e.NewText.ToString()), smartPanel.Child.Border.BorderThickness.Right, smartPanel.Child.Border.BorderThickness.Bottom); smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Right, smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderTopEdit.Text = $"{smartView.Border.BorderThickness.Top}"; Win.Add(borderTopEdit); var borderLeftEdit = new TextField("") { X = Pos.Center() + 5, Y = 2, Width = 5 }; borderLeftEdit.TextChanging += (e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness(int.Parse(e.NewText.ToString()), smartPanel.Child.Border.BorderThickness.Top, smartPanel.Child.Border.BorderThickness.Right, smartPanel.Child.Border.BorderThickness.Bottom); smartView.Border.BorderThickness = new Thickness(int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderLeftEdit.Text = $"{smartView.Border.BorderThickness.Left}"; Win.Add(borderLeftEdit); var borderRightEdit = new TextField("") { X = Pos.Center() + 19, Y = 2, Width = 5 }; borderRightEdit.TextChanging += (e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness(smartPanel.Child.Border.BorderThickness.Left, smartPanel.Child.Border.BorderThickness.Top, int.Parse(e.NewText.ToString()), smartPanel.Child.Border.BorderThickness.Bottom); smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, int.Parse(e.NewText.ToString()), smartView.Border.BorderThickness.Bottom); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderRightEdit.Text = $"{smartView.Border.BorderThickness.Right}"; Win.Add(borderRightEdit); var borderBottomEdit = new TextField("") { X = Pos.Center() + 12, Y = 3, Width = 5 }; borderBottomEdit.TextChanging += (e) => { try { smartPanel.Child.Border.BorderThickness = new Thickness(smartPanel.Child.Border.BorderThickness.Left, smartPanel.Child.Border.BorderThickness.Top, smartPanel.Child.Border.BorderThickness.Right, int.Parse(e.NewText.ToString())); smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Left, smartView.Border.BorderThickness.Top, smartView.Border.BorderThickness.Right, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty) { e.Cancel = true; } } }; borderBottomEdit.Text = $"{smartView.Border.BorderThickness.Bottom}"; Win.Add(borderBottomEdit); var replaceBorder = new Button("Replace all based on top") { X = Pos.Center() + 1, Y = 5 }; replaceBorder.Clicked += () => { smartPanel.Child.Border.BorderThickness = new Thickness(smartPanel.Child.Border.BorderThickness.Top); smartView.Border.BorderThickness = new Thickness(smartView.Border.BorderThickness.Top); if (borderTopEdit.Text.IsEmpty) { borderTopEdit.Text = "0"; } borderBottomEdit.Text = borderLeftEdit.Text = borderRightEdit.Text = borderTopEdit.Text; }; Win.Add(replaceBorder); Win.Add(new Label("BorderStyle:")); var borderStyleEnum = Enum.GetValues(typeof(BorderStyle)).Cast <BorderStyle> ().ToList(); var rbBorderStyle = new RadioGroup(borderStyleEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = 2, Y = 1, SelectedItem = (int)smartView.Border.BorderStyle }; Win.Add(rbBorderStyle); var cbDrawMarginFrame = new CheckBox("Draw Margin Frame", smartView.Border.DrawMarginFrame) { X = Pos.AnchorEnd(20), Y = 0, Width = 5 }; cbDrawMarginFrame.Toggled += (e) => { try { smartPanel.Child.Border.DrawMarginFrame = cbDrawMarginFrame.Checked; smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked; if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame; } } catch { } }; Win.Add(cbDrawMarginFrame); rbBorderStyle.SelectedItemChanged += (e) => { smartPanel.Child.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartView.Border.BorderStyle = (BorderStyle)e.SelectedItem; smartView.SetNeedsDisplay(); if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) { cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame; } }; var cbEffect3D = new CheckBox("Draw 3D effects", smartView.Border.Effect3D) { X = Pos.AnchorEnd(20), Y = 1, Width = 5 }; Win.Add(cbEffect3D); Win.Add(new Label("Effect3D Offset:") { X = Pos.AnchorEnd(20), Y = 2 }); Win.Add(new Label("X:") { X = Pos.AnchorEnd(19), Y = 3 }); var effect3DOffsetX = new TextField("") { X = Pos.AnchorEnd(16), Y = 3, Width = 5 }; effect3DOffsetX.TextChanging += (e) => { try { smartPanel.Child.Border.Effect3DOffset = new Point(int.Parse(e.NewText.ToString()), smartPanel.Child.Border.Effect3DOffset.Y); smartView.Border.Effect3DOffset = new Point(int.Parse(e.NewText.ToString()), smartView.Border.Effect3DOffset.Y); } catch { if (!e.NewText.IsEmpty && e.NewText != CultureInfo.CurrentCulture.NumberFormat.NegativeSign) { e.Cancel = true; } } }; effect3DOffsetX.Text = $"{smartView.Border.Effect3DOffset.X}"; Win.Add(effect3DOffsetX); Win.Add(new Label("Y:") { X = Pos.AnchorEnd(10), Y = 3 }); var effect3DOffsetY = new TextField("") { X = Pos.AnchorEnd(7), Y = 3, Width = 5 }; effect3DOffsetY.TextChanging += (e) => { try { smartPanel.Child.Border.Effect3DOffset = new Point(smartPanel.Child.Border.Effect3DOffset.X, int.Parse(e.NewText.ToString())); smartView.Border.Effect3DOffset = new Point(smartView.Border.Effect3DOffset.X, int.Parse(e.NewText.ToString())); } catch { if (!e.NewText.IsEmpty && e.NewText != CultureInfo.CurrentCulture.NumberFormat.NegativeSign) { e.Cancel = true; } } }; effect3DOffsetY.Text = $"{smartView.Border.Effect3DOffset.Y}"; Win.Add(effect3DOffsetY); cbEffect3D.Toggled += (e) => { try { smartPanel.Child.Border.Effect3D = smartView.Border.Effect3D = effect3DOffsetX.Enabled = effect3DOffsetY.Enabled = cbEffect3D.Checked; } catch { } }; Win.Add(new Label("Background:") { Y = 5 }); var colorEnum = Enum.GetValues(typeof(Color)).Cast <Color> ().ToList(); var rbBackground = new RadioGroup(colorEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = 2, Y = 6, SelectedItem = (int)smartView.Border.Background }; rbBackground.SelectedItemChanged += (e) => { smartPanel.Child.Border.Background = smartView.Border.Background = (Color)e.SelectedItem; }; Win.Add(rbBackground); Win.Add(new Label("BorderBrush:") { X = Pos.AnchorEnd(20), Y = 5 }); var rbBorderBrush = new RadioGroup(colorEnum.Select( e => NStack.ustring.Make(e.ToString())).ToArray()) { X = Pos.AnchorEnd(18), Y = 6, SelectedItem = (int)smartView.Border.BorderBrush }; rbBorderBrush.SelectedItemChanged += (e) => { smartPanel.Child.Border.BorderBrush = smartView.Border.BorderBrush = (Color)e.SelectedItem; }; Win.Add(rbBorderBrush); Win.Add(smartPanel); Win.Add(smartView); Win.BringSubviewToFront(smartPanel); }