static void Resolver(Dim[] lista, int N) { int[,] r = Calcular(lista, N); Mostrar("Resultado:", r, N); Console.WriteLine("Nº de multiplicaciones: " + r[0, N - 1]); Console.Write("Formula: "); MostrarFormula(r, lista, 0, N - 1); Console.WriteLine("\n"); }
public Fcm(int c, int n, double m, int num, int dim, List<Data> datas, double[,] u) { C = c; N = n; M = m; Num = num; T = 0; D = dim; Datas = datas; U = u; Centers=new Dim[c]; }
public void CalcV(double w, double c1, double c2, Dim[] globalPosition) { for (int c = 0; c< C; c++) { for (int d = 0; d < Velocity[c].Val.Length; d++) { double y1 = GeneralCom.GetRandom(0, 1); double y2 = GeneralCom.GetRandom(0, 1); double c1y1 = c1*y1; double c2y2 = c2*y2; Velocity[c].Val[d] = w * Velocity[c].Val[d] + c1y1 * (BestPosition[c].Val[d] - Position[c].Val[d]) + c2y2 * (globalPosition[c].Val[d] - Position[c].Val[d]); } } }
public void CalcCenter() { for (int j = 0; j < C; j++) { Centers[j] = new Dim(D); for (int dd = 0; dd < D; dd++) { double sigma1 = 0; for (int i = 0; i < N; i++) { sigma1 += Math.Pow(U[i, j], M) * Datas[i].DataDim.Val[dd]; } double sigma2 = 0; for (int i = 0; i < N; i++) { sigma2 += Math.Pow(U[i, j], M); } Centers[j].Val[dd] = sigma1 / sigma2; } } }
static void MostrarFormula(int[,] r, Dim[] d, int i, int j) { const char A = 'A'; if(i + 1 < j) { for(int k = i; k < j; k++) { if(r[i, j] == r[i, k] + r[k + 1, j] + d[i].alto * d[k].ancho * d[j].ancho) { Console.Write("("); MostrarFormula(r, d, i, k); Console.Write(" "); MostrarFormula(r, d, k + 1, j); Console.Write(")"); return; } } } else if(i < j) { Console.Write("(" + (char)(A + i) + " " + (char)(A + j) + ")"); } else if(i == j) { Console.Write("(" + (char)(A + i) + ")"); } }
static int[,] Calcular(Dim[] d, int N) { int[,] r = new int[N, N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if(i <= j) r[i, j] = 0; else r[i, j] = I; } } for(int i = N - 2; i >= 0; i--) { for(int j = i + 1; j < N; j++) { r[i, j] = I; for(int k = i; k < j; k++) { r[i, j] = Min(r[i, j], r[i, k] + r[k + 1, j] + d[i].alto * d[k].ancho * d[j].ancho); } } } return r; }
public override void Setup() { var statusBar = new StatusBar(new StatusItem[] { //new StatusItem(Key.ControlR, "~CTRL-R~ Refresh Data", () => RefreshScreen()), new StatusItem(Key.ControlQ, "~CTRL-Q~ Back/Quit", () => Quit()) }); LeftPane = new Window("Rooms") { X = 0, Y = 0, // for menu Width = 40, Height = Dim.Fill(), CanFocus = false, ColorScheme = Colors.TopLevel, }; try { if (STClient.GetAllRooms().Items?.Count > 0) { _viewRooms = STClient.GetAllRooms().Items .OrderBy(t => t.Name) .Select(t => new KeyValuePair <string, Room>(t.Name, t)) .ToDictionary(t => t.Key, t => t.Value); } else { SetErrorView($"You have no rooms configured"); } } catch (SmartThingsNet.Client.ApiException exp) { SetErrorView($"Error calling API: {exp.Source} {exp.ErrorCode} {exp.Message}"); } catch (System.Exception exp) { SetErrorView($"Unknown error calling API: {exp.Message}"); } ClassListView = new ListView(_viewRooms?.Keys?.ToList()) { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(), // for status bar AllowsMarking = false, ColorScheme = Colors.TopLevel, }; if (_viewRooms?.Keys?.Count > 0) { ClassListView.SelectedItemChanged += (args) => { ClearClass(CurrentView); var selectedItem = _viewRooms.Values.ToArray()[ClassListView.SelectedItem]; CurrentView = CreateJsonView(selectedItem.ToJson()); }; } LeftPane.Add(ClassListView); 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, HostPane); Top.Add(statusBar); if (_viewRooms?.Count > 0) { CurrentView = CreateJsonView(_viewRooms?.FirstOrDefault().Value?.ToJson()); } DisplayErrorView(); }
public Coordinate(string place = "New coordinate", int x = 0, int y = 64, int z = 0, Dim dimension = Dim.Overworld) { UseItemStyleForSubItems = false; Text = place; SubItems.Add(new ListViewSubItem(this, x.ToString())); SubItems.Add(new ListViewSubItem(this, y.ToString())); SubItems.Add(new ListViewSubItem(this, z.ToString())); SubItems.Add(new ListViewSubItem(this, dimension.ToString())); }
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; }
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(); }
public ConsoleGuiRunPipeline(IBasicActivateItems activator, IPipelineUseCase useCase, IPipeline pipeline) { Modal = true; this.activator = activator; this._useCase = useCase; this._pipeline = pipeline; ColorScheme = ConsoleMainWindow.ColorScheme; _compatiblePipelines = useCase.FilterCompatiblePipelines(activator.RepositoryLocator.CatalogueRepository.GetAllObjects <Pipeline>()).ToArray(); Width = Dim.Fill(); Height = Dim.Fill(); if (pipeline == null && _compatiblePipelines.Length == 1) { this._pipeline = _compatiblePipelines[0]; } Add(_lblPipeline = new Label("Pipeline:" + (this._pipeline?.Name ?? "<<NOT SELECTED>>")) { Width = Dim.Fill() - 20 }); var btnChoose = new Button("Choose Pipeline") { X = Pos.Right(_lblPipeline) }; btnChoose.Clicked += BtnChoose_Clicked; Add(btnChoose); var btnRun = new Button("Run") { Y = 1 }; btnRun.Clicked += BtnRun_Clicked; Add(btnRun); var btnCancel = new Button("Cancel") { Y = 1, X = Pos.Right(btnRun) }; btnCancel.Clicked += BtnCancel_Clicked; Add(btnCancel); var btnClose = new Button("Close") { Y = 1, X = Pos.Right(btnCancel) }; btnClose.Clicked += () => Application.RequestStop(); Add(btnClose); Add(_tableView = new TableView() { Y = 2, Width = Dim.Fill(), Height = 7 }); _tableView.Style.ShowHorizontalHeaderOverline = false; _tableView.Style.AlwaysShowHeaders = true; _tableView.Style.ShowVerticalCellLines = true; _tableView.Style.ShowHorizontalHeaderUnderline = false; progressDataTable = new DataTable(); progressDataTable.Columns.Add("Name"); progressDataTable.Columns.Add("Progress", typeof(int)); _tableView.Table = progressDataTable; Add(_results = new ListView(this) { Y = Pos.Bottom(_tableView), Width = Dim.Fill(), Height = Dim.Fill() }); _results.KeyPress += Results_KeyPress; }
public void generateTopologyConstraints(Dim k, RectPtrVector rs, SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t vars, SWIGTYPE_p_std__vectorT_vpsc__Constraint_p_t cs) { colaPINVOKE.OrthogonalEdgeConstraint_generateTopologyConstraints(swigCPtr, (int)k, RectPtrVector.getCPtr(rs), SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t.getCPtr(vars), SWIGTYPE_p_std__vectorT_vpsc__Constraint_p_t.getCPtr(cs)); if (colaPINVOKE.SWIGPendingException.Pending) throw colaPINVOKE.SWIGPendingException.Retrieve(); }
public override void Setup() { Top.Text = "Press CTRL-Q to Quit. This is the Text for the TopLevel View. TextAlignment.Centered was specified. It is intentionally very long to illustrate word wrap.\n" + "<-- There is a new line here to show a hard line break. You should see this text bleed underneath the subviews, which start at Y = 3."; Top.TextAlignment = TextAlignment.Centered; Top.ColorScheme = Colors.Base; string text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line."; string unicode = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου."; var unicodeCheckBox = new CheckBox("Unicode", Top.HotKeySpecifier == (Rune)' ') { X = 0, Y = 3, }; Top.Add(unicodeCheckBox); var alignments = Enum.GetValues(typeof(Terminal.Gui.TextAlignment)).Cast <Terminal.Gui.TextAlignment> ().ToList(); var singleLines = new Label [alignments.Count]; var multipleLines = new Label [alignments.Count]; var multiLineHeight = 5; foreach (var alignment in alignments) { singleLines [(int)alignment] = new Label(text) { TextAlignment = alignment, X = 0, Width = Dim.Fill(), Height = 1, ColorScheme = Colors.Dialog }; multipleLines [(int)alignment] = new Label(text) { TextAlignment = alignment, X = 0, Width = Dim.Fill(), Height = multiLineHeight, ColorScheme = Colors.Dialog }; } var label = new Label($"Demonstrating single-line (should clip):") { Y = Pos.Bottom(unicodeCheckBox) + 1 }; Top.Add(label); foreach (var alignment in alignments) { label = new Label($"{alignment}:") { Y = Pos.Bottom(label) }; Top.Add(label); singleLines [(int)alignment].Y = Pos.Bottom(label); Top.Add(singleLines [(int)alignment]); label = singleLines [(int)alignment]; } label = new Label($"Demonstrating multi-line and word wrap:") { Y = Pos.Bottom(label) }; Top.Add(label); foreach (var alignment in alignments) { label = new Label($"{alignment}:") { Y = Pos.Bottom(label) }; Top.Add(label); multipleLines [(int)alignment].Y = Pos.Bottom(label); Top.Add(multipleLines [(int)alignment]); label = multipleLines [(int)alignment]; } unicodeCheckBox.Toggled += (previous) => { foreach (var alignment in alignments) { singleLines [(int)alignment].Text = previous ? text : unicode; multipleLines [(int)alignment].Text = previous ? text : unicode; } }; }
static void Main(string[] args) { Application.Init(); menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_App", new MenuItem[] { new MenuItem("_Quit", "Close the app", Application.RequestStop), }), }) { X = 0, Y = 0, Width = Dim.Fill(), Height = 1, }; Application.Top.Add(menu); winMain = new Window() { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill(), Title = "DotChat", }; Application.Top.Add(winMain); winMessages = new Window() { X = 0, Y = 0, Width = winMain.Width, Height = winMain.Height - 2, }; winMain.Add(winMessages); labelUsername = new Label() { X = 0, Y = Pos.Bottom(winMain) - 5, Width = 15, Height = 1, Text = "Username:"******"Message:", TextAlignment = TextAlignment.Right, }; winMain.Add(labelMessage); fieldUsername = new TextField() { X = 15, Y = Pos.Bottom(winMain) - 5, Width = winMain.Width - 15, Height = 1, }; winMain.Add(fieldUsername); fieldMessage = new TextField() { X = 15, Y = Pos.Bottom(winMain) - 4, Width = winMain.Width - 15, Height = 1, }; winMain.Add(fieldMessage); btnSend = new Button() { X = Pos.Right(winMain) - 15, Y = Pos.Bottom(winMain) - 4, Width = 15, Height = 1, Text = " SEND ", }; btnSend.Clicked += OnBtnSendClick; winMain.Add(btnSend); //Создание цикла получения сообщений int lastMsgID = 1; string Timing = File.ReadLines("UpdateLoop.Json").Skip(4).First(); Timer updateLoop = new Timer(); int Interval = Convert.ToInt32(Timing); updateLoop.Interval = Interval; updateLoop.Elapsed += (object sender, ElapsedEventArgs e) => { Message msg = GetMessage(lastMsgID); if (msg != null) { messages.Add(msg); MessagesUpdate(); lastMsgID++; } }; updateLoop.Start(); Application.Run(); }
static void Main(string[] args) { Application.Init(); // Верхнеуровневый компонент var top = Application.Top; // Компонент меню menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_App", new MenuItem[] { new MenuItem("_Quit", "Close the app", Application.RequestStop), }), }); top.Add(menu); // Компонент главной формы winMain = new Window() { Title = "DotChat", // Позиция начала окна X = 0, Y = 1, //< Место под меню // Авто растягивание по размерам терминала Width = Dim.Fill(), Height = Dim.Fill() }; top.Add(winMain); // Компонент сообщений winMessages = new Window() { X = 0, Y = 0, Width = winMain.Width, Height = winMain.Height - 2, }; winMain.Add(winMessages); // Текст "Пользователь" labelUser = new Label() { X = 0, Y = Pos.Bottom(winMain) - 5, Width = 15, Height = 1, Text = "Username:"******"Сообщение" labelMessage = new Label() { X = 0, Y = Pos.Bottom(winMain) - 4, Width = 15, Height = 1, Text = "Message:", }; winMain.Add(labelMessage); // Поле ввода сообщения fieldMessage = new TextField() { X = 15, Y = Pos.Bottom(winMain) - 4, Width = winMain.Width - 14, Height = 1, }; winMain.Add(fieldMessage); // Кнопка отправки btnSend = new Button() { X = Pos.Right(winMain) - 10 - 5, Y = Pos.Bottom(winMain) - 4, Width = 10, Height = 1, Text = " Send ", }; winMain.Add(btnSend); // Обработка клика по кнопке btnSend.Clicked += OnBtnSendClick; // Запуск цикла проверки обновлений сообщений var updateLoop = new System.Timers.Timer(); updateLoop.Interval = 1000; int MessageID = 0; updateLoop.Elapsed += (sender, eventArgs) => { Message msg = API.GetMessage(MessageID); while (msg != null) { messages.Add(msg); UpdateMessages(); MessageID++; msg = API.GetMessage(MessageID); } }; updateLoop.Start(); Application.Run(); Console.Clear(); }
public void Initialized_Event_Comparing_With_Added_Event() { Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); var t = new Toplevel() { Id = "0", }; var w = new Window() { Id = "t", Width = Dim.Fill(), Height = Dim.Fill() }; var v1 = new View() { Id = "v1", Width = Dim.Fill(), Height = Dim.Fill() }; var v2 = new View() { Id = "v2", Width = Dim.Fill(), Height = Dim.Fill() }; var sv1 = new View() { Id = "sv1", Width = Dim.Fill(), Height = Dim.Fill() }; int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; w.Added += (e) => { Assert.Equal(e.Frame.Width, w.Frame.Width); Assert.Equal(e.Frame.Height, w.Frame.Height); }; v1.Added += (e) => { Assert.Equal(e.Frame.Width, v1.Frame.Width); Assert.Equal(e.Frame.Height, v1.Frame.Height); }; v2.Added += (e) => { Assert.Equal(e.Frame.Width, v2.Frame.Width); Assert.Equal(e.Frame.Height, v2.Frame.Height); }; sv1.Added += (e) => { Assert.Equal(e.Frame.Width, sv1.Frame.Width); Assert.Equal(e.Frame.Height, sv1.Frame.Height); }; t.Initialized += (s, e) => { tc++; Assert.Equal(1, tc); Assert.Equal(1, wc); Assert.Equal(1, v1c); Assert.Equal(1, v2c); Assert.Equal(1, sv1c); Assert.True(t.CanFocus); Assert.True(w.CanFocus); Assert.False(v1.CanFocus); Assert.False(v2.CanFocus); Assert.False(sv1.CanFocus); Application.Refresh(); }; w.Initialized += (s, e) => { wc++; Assert.Equal(t.Frame.Width, w.Frame.Width); Assert.Equal(t.Frame.Height, w.Frame.Height); }; v1.Initialized += (s, e) => { v1c++; Assert.Equal(t.Frame.Width, v1.Frame.Width); Assert.Equal(t.Frame.Height, v1.Frame.Height); }; v2.Initialized += (s, e) => { v2c++; Assert.Equal(t.Frame.Width, v2.Frame.Width); Assert.Equal(t.Frame.Height, v2.Frame.Height); }; sv1.Initialized += (s, e) => { sv1c++; Assert.Equal(t.Frame.Width, sv1.Frame.Width); Assert.Equal(t.Frame.Height, sv1.Frame.Height); Assert.False(sv1.CanFocus); Assert.Throws <InvalidOperationException> (() => sv1.CanFocus = true); Assert.False(sv1.CanFocus); }; v1.Add(sv1); w.Add(v1, v2); t.Add(w); Application.Iteration = () => { Application.Refresh(); t.Running = false; }; Application.Run(t); Application.Shutdown(); Assert.Equal(1, tc); Assert.Equal(1, wc); Assert.Equal(1, v1c); Assert.Equal(1, v2c); Assert.Equal(1, sv1c); Assert.True(t.CanFocus); Assert.True(w.CanFocus); Assert.False(v1.CanFocus); Assert.False(v2.CanFocus); Assert.False(sv1.CanFocus); v1.CanFocus = true; Assert.False(sv1.CanFocus); // False because sv1 was disposed and it isn't a subview of v1. }
public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically() { Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); var t = new Toplevel() { Id = "0", }; var w = new Window() { Id = "t", Width = Dim.Fill(), Height = Dim.Fill() }; var v1 = new View() { Id = "v1", Width = Dim.Fill(), Height = Dim.Fill() }; var v2 = new View() { Id = "v2", Width = Dim.Fill(), Height = Dim.Fill() }; int tc = 0, wc = 0, v1c = 0, v2c = 0, sv1c = 0; t.Initialized += (s, e) => { tc++; Assert.Equal(1, tc); Assert.Equal(1, wc); Assert.Equal(1, v1c); Assert.Equal(1, v2c); Assert.Equal(0, sv1c); // Added after t in the Application.Iteration. Assert.True(t.CanFocus); Assert.True(w.CanFocus); Assert.False(v1.CanFocus); Assert.False(v2.CanFocus); Application.Refresh(); }; w.Initialized += (s, e) => { wc++; Assert.Equal(t.Frame.Width, w.Frame.Width); Assert.Equal(t.Frame.Height, w.Frame.Height); }; v1.Initialized += (s, e) => { v1c++; Assert.Equal(t.Frame.Width, v1.Frame.Width); Assert.Equal(t.Frame.Height, v1.Frame.Height); }; v2.Initialized += (s, e) => { v2c++; Assert.Equal(t.Frame.Width, v2.Frame.Width); Assert.Equal(t.Frame.Height, v2.Frame.Height); }; w.Add(v1, v2); t.Add(w); Application.Iteration = () => { var sv1 = new View() { Id = "sv1", Width = Dim.Fill(), Height = Dim.Fill() }; sv1.Initialized += (s, e) => { sv1c++; Assert.NotEqual(t.Frame.Width, sv1.Frame.Width); Assert.NotEqual(t.Frame.Height, sv1.Frame.Height); Assert.False(sv1.CanFocus); Assert.Throws <InvalidOperationException> (() => sv1.CanFocus = true); Assert.False(sv1.CanFocus); }; v1.Add(sv1); Application.Refresh(); t.Running = false; }; Application.Run(t); Application.Shutdown(); Assert.Equal(1, tc); Assert.Equal(1, wc); Assert.Equal(1, v1c); Assert.Equal(1, v2c); Assert.Equal(1, sv1c); Assert.True(t.CanFocus); Assert.True(w.CanFocus); Assert.False(v1.CanFocus); Assert.False(v2.CanFocus); }
public void New_Initializes() { // Parameterless var r = new View(); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.Equal(Dim.Sized(0), r.Width); Assert.Equal(Dim.Sized(0), r.Height); // FIXED: Pos needs equality implemented Assert.Equal(Pos.At(0), r.X); Assert.Equal(Pos.At(0), r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Empty Rect r = new View(Rect.Empty); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Rect with values r = new View(new Rect(1, 2, 3, 4)); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=1,Y=2,Width=3,Height=4})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 3, 4), r.Bounds); Assert.Equal(new Rect(1, 2, 3, 4), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); Assert.NotNull(r.Height); Assert.NotNull(r.X); Assert.NotNull(r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Initializes a view with a vertical direction r = new View("Vertical View", TextDirection.TopBottom_LeftRight); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=1,Height=13})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 1, 13), r.Bounds); Assert.Equal(new Rect(0, 0, 1, 13), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.TopBottom_LeftRight, r.TextDirection); }
public static Dim conjugate(Dim d) { Dim ret = (Dim)colaPINVOKE.conjugate((int)d); return ret; }
public double[] Maxd { get; set; }//Matrix public Pso(int c, int n, double m, double w, double c1, double c2, int num, int dim, List<Data> datas,double[] maxd,Dim[] pastCenters=null) { Maxd = maxd; C = c; N = n; M = m; Num = num; T = 0; D = dim; Datas = datas; W = w; C1 = c1; C2 = c2; GloablBestError = double.MinValue; GloablBestFitness = double.MaxValue; GloablBestPosition=new Dim[c]; Particles = new List<Particle>(); for (int a = 0; a < Num; a++) { Particle p = new Particle { U = new double[N, c], C = c, N = n, Position = a == 0 && pastCenters != null ? pastCenters : new Dim[c], BestPosition = a == 0 && pastCenters != null ? pastCenters : new Dim[c], Velocity = new Dim[c], Error = Double.MinValue, BestError = Double.MinValue, Iteration = 0, Index = a, BestFitness = double.MaxValue, Fitness = double.MaxValue }; if (a == 0 && pastCenters != null) { p.Position = pastCenters; p.BestPosition = pastCenters; GloablBestPosition = pastCenters; for (int i = 0; i < c; i++) { p.Velocity[i] = new Dim(D); } } else { for (int i = 0; i < c; i++) { p.Position[i] = new Dim(D); p.Velocity[i] = new Dim(D); if (a == 0) { GloablBestPosition[i] = new Dim(D); } for (int j = 0; j < D; j++) { p.Position[i].Val[j] = GeneralCom.GetRandom(0, Maxd[j]); //p.Velocity[i].Val[j] = GeneralCom.GetRandom(0, Maxd[j]); if (a == 0) { GloablBestPosition[i].Val[j] = GeneralCom.GetRandom(0, Maxd[j]); } } } } p.BestPosition = p.Position; p.CalcU(datas, M); p.CalcV(W, C1, C2, GloablBestPosition); Particles.Add(p); } }
/// <summary> /// This shows the selection UI. Each time it is run, it calls Application.Init to reset everything. /// </summary> /// <returns></returns> private static Scenario GetScenarioToRun() { Application.UseSystemConsole = false; Application.Init(); // Set this here because not initialized until driver is loaded _baseColorScheme = Colors.Base; StringBuilder aboutMessage = new StringBuilder(); aboutMessage.AppendLine("UI Catalog is a comprehensive sample library for Terminal.Gui"); aboutMessage.AppendLine(@" _ "); aboutMessage.AppendLine(@" __ _ _ _(_) ___ ___ "); aboutMessage.AppendLine(@" / _` | | | | | / __/ __|"); aboutMessage.AppendLine(@"| (_| | |_| | || (__\__ \"); aboutMessage.AppendLine(@" \__, |\__,_|_(_)___|___/"); aboutMessage.AppendLine(@" |___/ "); aboutMessage.AppendLine(""); aboutMessage.AppendLine($"Version: {typeof (UICatalogApp).Assembly.GetName ().Version}"); aboutMessage.AppendLine($"Using Terminal.Gui Version: {typeof (Terminal.Gui.Application).Assembly.GetName ().Version}"); aboutMessage.AppendLine(""); _menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Quit", "", () => Application.RequestStop()) }), new MenuBarItem("_Color Scheme", CreateColorSchemeMenuItems()), new MenuBarItem("_Diagostics", CreateDiagnosticMenuItems()), new MenuBarItem("_About...", "About this app", () => MessageBox.Query("About UI Catalog", aboutMessage.ToString(), "_Ok")), }); _leftPane = new FrameView("Categories") { X = 0, Y = 1, // for menu Width = 25, Height = Dim.Fill(1), CanFocus = false, }; _categories = Scenario.GetAllCategories().OrderBy(c => c).ToList(); _categoryListView = new ListView(_categories) { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _categoryListView.OpenSelectedItem += (a) => { _top.SetFocus(_rightPane); }; _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged; _leftPane.Add(_categoryListView); _rightPane = new FrameView("Scenarios") { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = Dim.Fill(1), CanFocus = true, }; _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length; _scenarioListView = new ListView() { X = 0, Y = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = true, }; _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem; _rightPane.Add(_scenarioListView); _categoryListView.SelectedItem = _categoryListViewItem; _categoryListView.OnSelectedChanged(); _capslock = new StatusItem(Key.CharMask, "Caps", null); _numlock = new StatusItem(Key.CharMask, "Num", null); _scrolllock = new StatusItem(Key.CharMask, "Scroll", null); _statusBar = new StatusBar(new StatusItem [] { _capslock, _numlock, _scrolllock, new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), });
public void Internal_Tests() { var top = new Toplevel(); var eventInvoked = ""; top.ChildUnloaded += (e) => eventInvoked = "ChildUnloaded"; top.OnChildUnloaded(top); Assert.Equal("ChildUnloaded", eventInvoked); top.ChildLoaded += (e) => eventInvoked = "ChildLoaded"; top.OnChildLoaded(top); Assert.Equal("ChildLoaded", eventInvoked); top.Closed += (e) => eventInvoked = "Closed"; top.OnClosed(top); Assert.Equal("Closed", eventInvoked); top.Closing += (e) => eventInvoked = "Closing"; top.OnClosing(new ToplevelClosingEventArgs(top)); Assert.Equal("Closing", eventInvoked); top.AllChildClosed += () => eventInvoked = "AllChildClosed"; top.OnAllChildClosed(); Assert.Equal("AllChildClosed", eventInvoked); top.ChildClosed += (e) => eventInvoked = "ChildClosed"; top.OnChildClosed(top); Assert.Equal("ChildClosed", eventInvoked); top.Deactivate += (e) => eventInvoked = "Deactivate"; top.OnDeactivate(top); Assert.Equal("Deactivate", eventInvoked); top.Activate += (e) => eventInvoked = "Activate"; top.OnActivate(top); Assert.Equal("Activate", eventInvoked); top.Loaded += () => eventInvoked = "Loaded"; top.OnLoaded(); Assert.Equal("Loaded", eventInvoked); top.Ready += () => eventInvoked = "Ready"; top.OnReady(); Assert.Equal("Ready", eventInvoked); top.Unloaded += () => eventInvoked = "Unloaded"; top.OnUnloaded(); Assert.Equal("Unloaded", eventInvoked); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); top.RemoveMenuStatusBar(top.MenuBar); Assert.Null(top.MenuBar); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Application.Begin(top); Assert.Equal(top, Application.Top); // top is Application.Top without menu and status bar. var supView = top.EnsureVisibleBounds(top, 2, 2, out int nx, out int ny, out View mb, out View sb); Assert.Equal(Application.Top, supView); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.MenuBar); Assert.Null(top.MenuBar); // top is Application.Top without a menu and with a status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Assert.Null(top.MenuBar); var win = new Window() { Width = Dim.Fill(), Height = Dim.Fill() }; top.Add(win); top.LayoutSubviews(); // The SuperView is always the same regardless of the caller. supView = top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(Application.Top, supView); supView = win.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(Application.Top, supView); // top is Application.Top without menu and status bar. top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(win, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(win, 30, 20, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.MenuBar); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Assert.Null(top.MenuBar); top.Remove(win); win = new Window() { Width = 60, Height = 15 }; top.Add(win); // top is Application.Top without menu and status bar. top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(win, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(2, nx); Assert.Equal(2, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(win, 30, 20, out nx, out ny, out mb, out sb); Assert.Equal(20, nx); // 20+60=80 Assert.Equal(9, ny); // 9+15+1(mb)=25 Assert.NotNull(mb); Assert.NotNull(sb); top.PositionToplevels(); Assert.Equal(new Rect(0, 1, 60, 15), win.Frame); Assert.Null(Toplevel.dragPosition); win.MouseEvent(new MouseEvent() { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed }); Assert.Equal(new Point(6, 0), Toplevel.dragPosition); }
public void generateNonOverlapConstraints(Dim dim, SWIGTYPE_p_NonOverlapConstraints nonOverlapConstraints, RectPtrVector rs, SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t vars, SWIGTYPE_p_std__vectorT_vpsc__Constraint_p_t cs) { colaPINVOKE.Cluster_generateNonOverlapConstraints(swigCPtr, (int)dim, SWIGTYPE_p_NonOverlapConstraints.getCPtr(nonOverlapConstraints), RectPtrVector.getCPtr(rs), SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t.getCPtr(vars), SWIGTYPE_p_std__vectorT_vpsc__Constraint_p_t.getCPtr(cs)); if (colaPINVOKE.SWIGPendingException.Pending) throw colaPINVOKE.SWIGPendingException.Retrieve(); }
public void Application_Top_EnsureVisibleBounds_To_Driver_Rows_And_Cols() { var iterations = 0; Application.Iteration += () => { if (iterations == 0) { Assert.Equal("Top1", Application.Top.Text); Assert.Equal(0, Application.Top.Frame.X); Assert.Equal(0, Application.Top.Frame.Y); Assert.Equal(Application.Driver.Cols, Application.Top.Frame.Width); Assert.Equal(Application.Driver.Rows, Application.Top.Frame.Height); Application.Top.ProcessHotKey(new KeyEvent(Key.CtrlMask | Key.R, new KeyModifiers())); } else if (iterations == 1) { Assert.Equal("Top2", Application.Top.Text); Assert.Equal(0, Application.Top.Frame.X); Assert.Equal(0, Application.Top.Frame.Y); Assert.Equal(Application.Driver.Cols, Application.Top.Frame.Width); Assert.Equal(Application.Driver.Rows, Application.Top.Frame.Height); Application.Top.ProcessHotKey(new KeyEvent(Key.CtrlMask | Key.C, new KeyModifiers())); } else if (iterations == 3) { Assert.Equal("Top1", Application.Top.Text); Assert.Equal(0, Application.Top.Frame.X); Assert.Equal(0, Application.Top.Frame.Y); Assert.Equal(Application.Driver.Cols, Application.Top.Frame.Width); Assert.Equal(Application.Driver.Rows, Application.Top.Frame.Height); Application.Top.ProcessHotKey(new KeyEvent(Key.CtrlMask | Key.R, new KeyModifiers())); } else if (iterations == 4) { Assert.Equal("Top2", Application.Top.Text); Assert.Equal(0, Application.Top.Frame.X); Assert.Equal(0, Application.Top.Frame.Y); Assert.Equal(Application.Driver.Cols, Application.Top.Frame.Width); Assert.Equal(Application.Driver.Rows, Application.Top.Frame.Height); Application.Top.ProcessHotKey(new KeyEvent(Key.CtrlMask | Key.C, new KeyModifiers())); } else if (iterations == 6) { Assert.Equal("Top1", Application.Top.Text); Assert.Equal(0, Application.Top.Frame.X); Assert.Equal(0, Application.Top.Frame.Y); Assert.Equal(Application.Driver.Cols, Application.Top.Frame.Width); Assert.Equal(Application.Driver.Rows, Application.Top.Frame.Height); Application.Top.ProcessHotKey(new KeyEvent(Key.CtrlMask | Key.Q, new KeyModifiers())); } iterations++; }; Application.Run(Top1()); Toplevel Top1() { var top = Application.Top; top.Text = "Top1"; var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_Options", new MenuItem [] { new MenuItem("_Run Top2", "", () => Application.Run(Top2()), null, null, Key.CtrlMask | Key.R), new MenuItem("_Quit", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.Q) }) }); top.Add(menu); var statusBar = new StatusBar(new [] { new StatusItem(Key.CtrlMask | Key.R, "~^R~ Run Top2", () => Application.Run(Top2())), new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Application.RequestStop()) }); top.Add(statusBar); var t1 = new Toplevel(); top.Add(t1); return(top); } Toplevel Top2() { var top = new Toplevel(Application.Top.Frame); top.Text = "Top2"; var win = new Window() { Width = Dim.Fill(), Height = Dim.Fill() }; var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_Stage", new MenuItem [] { new MenuItem("_Close", "", () => Application.RequestStop(), null, null, Key.CtrlMask | Key.C) }) }); top.Add(menu); var statusBar = new StatusBar(new [] { new StatusItem(Key.CtrlMask | Key.C, "~^C~ Close", () => Application.RequestStop()), }); top.Add(statusBar); win.Add(new ListView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }); top.Add(win); return(top); } }
static void Main() { //Application.UseSystemConsole = true; Application.Init(); var top = Application.Top; var tframe = top.Frame; //Open (); #if true var win = new Window("Hello") { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill() }; #else var win = new Window(new Rect(0, 1, tframe.Width, tframe.Height - 1), "Hello"); #endif var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("Text Editor Demo", "", () => { Editor(top); }), new MenuItem("_New", "Creates new file", NewFile), new MenuItem("_Open", "", Open), new MenuItem("_Hex", "", () => ShowHex(top)), 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) }), new MenuBarItem("_List Demos", new MenuItem [] { new MenuItem("Select Items", "", ListSelectionDemo), }), }); ShowEntries(win); int count = 0; ml = new Label(new Rect(3, 17, 47, 1), "Mouse: "); Application.RootMouseEvent += delegate(MouseEvent me) { ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}"; }; var test = new Label(3, 18, "Se iniciará el análisis"); win.Add(test); win.Add(ml); // ShowTextAlignments (win); top.Add(win); top.Add(menu); Application.Run(); }
static void Main(string[] args) { _client = new IpcClient(new DefaultIpcEndpoint()); var answer = _client.GetRepositories(); var repositoryCount = answer?.Repositories?.Length ?? 0; if (repositoryCount == 0) { if (!string.IsNullOrEmpty(answer?.Answer)) { Console.WriteLine(answer.Answer); } else { Console.WriteLine("No repositories yet"); } return; } _repositoriesView = new RepositoriesView(answer.Repositories); Application.Init(); var filterLabel = new Label(1, 1, "Filter: "); _filterField = new TextField("") { X = Pos.Right(filterLabel) + 2, Y = Pos.Top(filterLabel), Width = Dim.Fill(margin: 1), }; _filterField.Changed += FilterField_Changed; _repositoryList = new ListView(_repositoriesView.Repositories) { X = Pos.Left(filterLabel), Y = Pos.Bottom(filterLabel) + 1, Width = Dim.Fill(margin: 1), Height = Dim.Fill() - 2 }; var win = new KeyPreviewWindow("grr: Git repositories of RepoZ") { filterLabel, _filterField, _repositoryList }; var buttonX = Pos.Left(filterLabel); var navigationButton = new Button("Navigate") { Clicked = Navigate, X = buttonX, Y = Pos.AnchorEnd(1), CanFocus = false }; if (!CanNavigate) { navigationButton.Clicked = CopyNavigationCommandAndQuit; } buttonX = buttonX + navigationButton.Text.Length + BUTTON_BORDER + BUTTON_DISTANCE; var copyPathButton = new Button("Copy") { Clicked = Copy, X = buttonX, Y = Pos.AnchorEnd(1), CanFocus = false }; buttonX = buttonX + copyPathButton.Text.Length + BUTTON_BORDER + BUTTON_DISTANCE; var browseButton = new Button("Browse") { Clicked = Browse, X = buttonX, Y = Pos.AnchorEnd(1), CanFocus = false }; var quitButton = new Button("Quit") { Clicked = Application.RequestStop, X = Pos.AnchorEnd("Quit".Length + BUTTON_BORDER + BUTTON_DISTANCE), Y = Pos.AnchorEnd(1), CanFocus = false }; win.Add(navigationButton, copyPathButton, browseButton, quitButton); win.DefineKeyAction(Key.Enter, () => win.SetFocus(_repositoryList)); win.DefineKeyAction(Key.Esc, () => { if (_filterField.HasFocus) { SetFilterText(""); } else { win.SetFocus(_filterField); } }); if (args?.Length > 0) { SetFilterText(String.Join(" ", args)); } Application.Top.Add(win); Application.Run(); }
public override void Setup() { _customRenderCB = new CheckBox("Render with columns") { X = 0, Y = 0, Height = 1, }; Win.Add(_customRenderCB); _customRenderCB.Toggled += _customRenderCB_Toggled; _allowMarkingCB = new CheckBox("Allow Marking") { X = Pos.Right(_customRenderCB) + 1, Y = 0, Height = 1, }; Win.Add(_allowMarkingCB); _allowMarkingCB.Toggled += AllowMarkingCB_Toggled; _allowMultipleCB = new CheckBox("Allow Multi-Select") { X = Pos.Right(_allowMarkingCB) + 1, Y = 0, Height = 1, Visible = _allowMarkingCB.Checked }; Win.Add(_allowMultipleCB); _allowMultipleCB.Toggled += AllowMultipleCB_Toggled; _listView = new ListView() { X = 1, Y = 2, Height = Dim.Fill(), Width = Dim.Fill(1), //ColorScheme = Colors.TopLevel, AllowsMarking = false, AllowsMultipleSelection = false }; Win.Add(_listView); var _scrollBar = new ScrollBarView(_listView, true); _scrollBar.ChangedPosition += () => { _listView.TopItem = _scrollBar.Position; if (_listView.TopItem != _scrollBar.Position) { _scrollBar.Position = _listView.TopItem; } _listView.SetNeedsDisplay(); }; _scrollBar.OtherScrollBarView.ChangedPosition += () => { _listView.LeftItem = _scrollBar.OtherScrollBarView.Position; if (_listView.LeftItem != _scrollBar.OtherScrollBarView.Position) { _scrollBar.OtherScrollBarView.Position = _listView.LeftItem; } _listView.SetNeedsDisplay(); }; _listView.DrawContent += (e) => { _scrollBar.Size = _listView.Source.Count - 1; _scrollBar.Position = _listView.TopItem; _scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1; _scrollBar.OtherScrollBarView.Position = _listView.LeftItem; _scrollBar.Refresh(); }; _listView.SetSource(_scenarios); var k = "Keep Content Always In Viewport"; var keepCheckBox = new CheckBox(k, _scrollBar.AutoHideScrollBars) { X = Pos.AnchorEnd(k.Length + 3), Y = 0, }; keepCheckBox.Toggled += (_) => _scrollBar.KeepContentAlwaysInViewport = keepCheckBox.Checked; Win.Add(keepCheckBox); }
public static Label CreateLabel(string Content, int X, int Y, Dim W, Dim H) { return(CreateLabel(Content, Pos.At(X), Pos.At(Y), W, H)); }
/// <summary> /// Initializes a new instance of <see cref="FileDialog"/> /// </summary> /// <param name="title">The title.</param> /// <param name="prompt">The prompt.</param> /// <param name="nameDirLabel">The name of the directory field label.</param> /// <param name="nameFieldLabel">The name of the file field label..</param> /// <param name="message">The message.</param> /// <param name="allowedTypes">The allowed types.</param> public FileDialog(ustring title, ustring prompt, ustring nameDirLabel, ustring nameFieldLabel, ustring message, List <string> allowedTypes = null) : 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); this.nameDirLabel = new Label(nameDirLabel.IsEmpty ? "Directory: " : $"{nameDirLabel}: ") { X = 1, Y = 1 + msgLines, AutoSize = true }; dirEntry = new TextField("") { X = Pos.Right(this.nameDirLabel), Y = 1 + msgLines, Width = Dim.Fill() - 1, }; dirEntry.TextChanged += (e) => { DirectoryPath = dirEntry.Text; nameEntry.Text = ustring.Empty; }; Add(this.nameDirLabel, dirEntry); this.nameFieldLabel = new Label(nameFieldLabel.IsEmpty ? "File: " : $"{nameFieldLabel}: ") { X = 1, Y = 3 + msgLines, AutoSize = true }; nameEntry = new TextField("") { X = Pos.Left(dirEntry), Y = 3 + msgLines, Width = Dim.Percent(70, true) }; Add(this.nameFieldLabel, nameEntry); cmbAllowedTypes = new ComboBox() { X = Pos.Right(nameEntry) + 2, Y = Pos.Top(nameEntry), Width = Dim.Fill(1), Height = allowedTypes != null ? allowedTypes.Count + 1 : 1, Text = allowedTypes?.Count > 0 ? allowedTypes [0] : string.Empty, ReadOnly = true }; cmbAllowedTypes.SetSource(allowedTypes ?? new List <string> ()); cmbAllowedTypes.OpenSelectedItem += (e) => AllowedFileTypes = cmbAllowedTypes.Text.ToString().Split(';'); Add(cmbAllowedTypes); 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); AllowedFileTypes = cmbAllowedTypes.Text.ToString().Split(';'); 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 += () => { Cancel(); }; AddButton(cancel); this.prompt = new Button(prompt.IsEmpty ? "Ok" : prompt) { IsDefault = true, Enabled = nameEntry.Text.IsEmpty ? false : true }; this.prompt.Clicked += () => { if (this is OpenDialog) { if (!dirListView.GetValidFilesName(nameEntry.Text.ToString(), out string res)) { nameEntry.Text = res; dirListView.SetNeedsDisplay(); return; } if (!dirListView.canChooseDirectories && !dirListView.ExecuteSelection(false)) { return; } } else if (this is SaveDialog) { var name = nameEntry.Text.ToString(); if (FilePath.IsEmpty || name.Split(',').Length > 1) { return; } var ext = name.EndsWith(cmbAllowedTypes.Text.ToString()) ? "" : cmbAllowedTypes.Text.ToString(); FilePath = Path.Combine(FilePath.ToString(), $"{name}{ext}"); } canceled = false; Application.RequestStop(); }; AddButton(this.prompt); nameEntry.TextChanged += (e) => { if (nameEntry.Text.IsEmpty) { this.prompt.Enabled = false; } else { this.prompt.Enabled = true; } }; Width = Dim.Percent(80); Height = Dim.Percent(80); // On success, we will set this to false. canceled = true; KeyPress += (e) => { if (e.KeyEvent.Key == Key.Esc) { Cancel(); e.Handled = true; } }; void Cancel() { canceled = true; Application.RequestStop(); } }
public static Button CreateButton(string Content, int X, int Y, Dim W, Dim H, Delegate act) { return(CreateButton(Content, Pos.At(X), Pos.At(Y), W, H, act)); }
public static Dialog CreateDialog(Action okAction) { PasswordGeneratorState state = new PasswordGeneratorState(); var ok = new Button(3, 14, LocMan.Get("Ok")); ok.Clicked += () => { okAction.Invoke(); }; var dialog = new Dialog(LocMan.Get("🎲 Random Password Generator"), 60, 20, ok); var passwordLengthLabel = new Label(1, 1, LocMan.Get("Password length:")); var positiveNumbersOnlyProvider = new TextRegexProvider("^[1-9]+[0-9]$") { ValidateOnInput = true }; var passwordLengthTextField = new TextValidateField(positiveNumbersOnlyProvider) { X = 1, Y = 2, Width = 4, Height = 1 }; passwordLengthTextField.Text = state.PasswordLength.ToString(); var useUppercase = new CheckBox(1, 4, "Upper-case latin characters (e.g. A, C, K, Z)", state.IncludeUpperCaseLatinLetters); useUppercase.Toggled += (bool old) => { state.IncludeUpperCaseLatinLetters = !old; }; var useLowercase = new CheckBox(1, 5, "Lower-case latin characters (e.g. a, c, k, z)", state.IncludeLowerCaseLatinLetters); useLowercase.Toggled += (bool old) => { state.IncludeLowerCaseLatinLetters = !old; }; var useDigits = new CheckBox(1, 6, "Digits (e.g. 4, 6, 9)", state.IncludeDigits); useDigits.Toggled += (bool old) => { state.IncludeDigits = !old; }; var useSpecialASCII = new CheckBox(1, 7, "Special characters ASCII", state.IncludeSpecialCharactersASCII); useSpecialASCII.Toggled += (bool old) => { state.IncludeSpecialCharactersASCII = !old; }; var useBasicEmojis = new CheckBox(1, 8, "Basic emoji (e.g. 😊)", state.IncludeEmojis); useBasicEmojis.Toggled += (bool old) => { state.IncludeEmojis = !old; }; var generatedPasswordLabel = new Label(1, 10, LocMan.Get("Generated password:"******"") { ReadOnly = true, X = 1, Y = 11, Width = Dim.Fill(), Height = 1 }; var copyToClipboardButton = new Button(3, 12, LocMan.Get("Copy to Clipboard")); var generateButton = new Button(25, 12, LocMan.Get("Generate")); generateButton.Clicked += () => { GenerateRandomPassword(state); generatedPasswordField.Text = state.GeneratedPassword; }; dialog.Add(passwordLengthLabel, passwordLengthTextField, useUppercase, useLowercase, useDigits, useSpecialASCII, useBasicEmojis, generatedPasswordLabel, generatedPasswordField, copyToClipboardButton, generateButton); return(dialog); }
/// <summary> /// Sets how much the generator should be scaled. /// </summary> /// <param name="dimension">The axis to scale on.</param> /// <param name="value">How much the generator should be scaled by.</param> public void SetScale(Dim dimension, float value) { API_DomainAxisScaleSetScale(_genID, (int)dimension, value); }
public override void Setup() { Win.Title = this.GetName(); Win.Y = 1; // menu Win.Height = Dim.Fill(1); // status bar Top.LayoutSubviews(); this.tableView = new TableView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(1), }; var menu = new MenuBar(new MenuBarItem [] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_OpenBigExample", "", () => OpenExample(true)), new MenuItem("_OpenSmallExample", "", () => OpenExample(false)), new MenuItem("_CloseExample", "", () => CloseExample()), new MenuItem("_Quit", "", () => Quit()), }), new MenuBarItem("_View", new MenuItem [] { miAlwaysShowHeaders = new MenuItem("_AlwaysShowHeaders", "", () => ToggleAlwaysShowHeader()) { Checked = tableView.Style.AlwaysShowHeaders, CheckType = MenuItemCheckStyle.Checked }, miHeaderOverline = new MenuItem("_HeaderOverLine", "", () => ToggleOverline()) { Checked = tableView.Style.ShowHorizontalHeaderOverline, CheckType = MenuItemCheckStyle.Checked }, miHeaderMidline = new MenuItem("_HeaderMidLine", "", () => ToggleHeaderMidline()) { Checked = tableView.Style.ShowVerticalHeaderLines, CheckType = MenuItemCheckStyle.Checked }, miHeaderUnderline = new MenuItem("_HeaderUnderLine", "", () => ToggleUnderline()) { Checked = tableView.Style.ShowHorizontalHeaderUnderline, CheckType = MenuItemCheckStyle.Checked }, miFullRowSelect = new MenuItem("_FullRowSelect", "", () => ToggleFullRowSelect()) { Checked = tableView.FullRowSelect, CheckType = MenuItemCheckStyle.Checked }, miCellLines = new MenuItem("_CellLines", "", () => ToggleCellLines()) { Checked = tableView.Style.ShowVerticalCellLines, CheckType = MenuItemCheckStyle.Checked }, new MenuItem("_AllLines", "", () => ToggleAllCellLines()), new MenuItem("_NoLines", "", () => ToggleNoCellLines()), new MenuItem("_ClearColumnStyles", "", () => ClearColumnStyles()), }), }); Top.Add(menu); var statusBar = new StatusBar(new StatusItem [] { new StatusItem(Key.F2, "~F2~ OpenExample", () => OpenExample(true)), new StatusItem(Key.F3, "~F3~ CloseExample", () => CloseExample()), new StatusItem(Key.F4, "~F4~ OpenSimple", () => OpenSimple(true)), new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Quit()), }); Top.Add(statusBar); Win.Add(tableView); var selectedCellLabel = new Label() { X = 0, Y = Pos.Bottom(tableView), Text = "0,0", Width = Dim.Fill(), TextAlignment = TextAlignment.Right }; Win.Add(selectedCellLabel); tableView.SelectedCellChanged += (e) => { selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}"; }; tableView.CellActivated += EditCurrentCell; tableView.KeyPress += TableViewKeyPress; SetupScrollBar(); }
public void updateBounds(Dim dim) { colaPINVOKE.Cluster_updateBounds(swigCPtr, (int)dim); }
internal static View Create() { var top = new Toplevel() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; var processesWindow = new Window("Processes") { X = 0, Y = 0, Width = Dim.Percent(50), Height = Dim.Percent(50) }; var detailsWindow = new Window("Details") { X = 0, Y = Pos.Percent(50), Width = Dim.Percent(50), Height = Dim.Fill() - 1 }; var detailsTextView = new ProcessDetailsTextView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), ReadOnly = true, CanFocus = true }; detailsWindow.Add(detailsTextView); var processesListView = new ProcessListView(new ProcessListDataSource(ProcessHelper.GetProcessList())) { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), }; processesListView.CanFocus = true; processesWindow.Add(processesListView); var countersWindows = new Window("Counters") { X = Pos.Percent(50), Y = 0, Width = Dim.Fill(), Height = Dim.Fill() - 1 }; var countersTextView = CountersTextView.Create(); countersWindows.Add(countersTextView); Object timeoutToken = new Object(); detailsTextView.YieldFocus += delegate() { countersTextView.Stop(); countersTextView.Text = ""; top.SetFocus(processesWindow); Application.MainLoop.RemoveTimeout(timeoutToken); }; processesListView.Select += delegate(Process process) { detailsTextView.Text = process.FormatDetailsAsString(); countersTextView.Start(process); detailsTextView.SetNeedsDisplay(); top.SetFocus(detailsTextView); timeoutToken = Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1), (eventLoop) => { countersTextView.Update(); return(true); }); }; top.Add(processesWindow, countersWindows, detailsWindow, StatusBarView.Create()); return(top); }
public void createVars(Dim dim, RectPtrVector rs, SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t vars) { colaPINVOKE.Cluster_createVars(swigCPtr, (int)dim, RectPtrVector.getCPtr(rs), SWIGTYPE_p_std__vectorT_vpsc__Variable_p_t.getCPtr(vars)); if (colaPINVOKE.SWIGPendingException.Pending) throw colaPINVOKE.SWIGPendingException.Retrieve(); }
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") ); }
public override void Setup() { var statusBar = new StatusBar(new StatusItem [] { new StatusItem(Key.CtrlMask | Key.Q, "~^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) => { _settingsPane.SetFocus(); }; _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), }; _xRadioGroup.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), }; _yRadioGroup.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), }; _wRadioGroup.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), }; _hRadioGroup.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); Top.LayoutSubviews(); _curView = CreateClass(_viewClasses.First().Value); }
// ReSharper disable once UnusedMember.Local private void OnExecute() { var loggerFactory = new LoggerFactory() .AddConsole(Verbosity); var analyzer = new DependencyAnalyzer(loggerFactory); var 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, 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); dependenciesView.SelectedItem = 0; UpdateLists(); dependenciesView.SelectedChanged += UpdateLists; Application.Run(); void UpdateLists() { var selectedNode = orderedDependencyList[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 void Render() { var Win = new Window("Productos") { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() - 1 }; State = "PRODUCTS"; List <ustring> items = GetListAsTableString(); View newView = new View(); ustring header = " STOCK#│ DESCRIPCION │ PRECIO.R │ PRECIO.V │MODEL│ PACK│"; // ListView var lbListView = new Label(header) { ColorScheme = Colors.TopLevel, X = 0, Y = 1, Width = Dim.Fill() - 1 }; var table = new ListView(items) { X = 0, Y = Pos.Bottom(lbListView) + 1, Height = Dim.Fill() - 2, Width = Dim.Fill() }; table.SelectedItemChanged += (ListViewItemEventArgs e) => { var res = (ustring)table.Source.ToList()[table.SelectedItem]; StockItemSelected = Convert.ToInt32(res.Split("│")[0]); }; table.KeyUp += (a) => { if (a.KeyEvent.KeyValue == 1048591 && State == "PRODUCTS") { State = "UPDATE_PRODUCT"; new ProductCreate(db).Render(); table.SetSource(GetListAsTableString()); State = "PRODUCTS"; } if (a.KeyEvent.KeyValue == 1048593 && State == "PRODUCTS") { State = "UPDATE_PRODUCT"; new ProductUpdate(db).Render(StockItemSelected); table.SetSource(GetListAsTableString()); State = "PRODUCTS"; } if (a.KeyEvent.KeyValue == 1048598 && State == "PRODUCTS") { State = "UPDATE_PRODUCT"; db.Products .Remove(db .Products .Where(x => x.StockNumber == StockItemSelected) .FirstOrDefault() ); db.SaveChanges(); table.SetSource(GetListAsTableString()); State = "PRODUCTS"; } }; var lblBottom = new Label("F5 para agregar " + "F7 para editar " + "F12 para eliminar " + "Ctrl + Q para salir") { X = 0, Y = Pos.Bottom(table) + 1 }; Win.Add(lbListView, table, lblBottom); Application.Run(Win); }
void DimPosChanged(View view) { if (view == null) { return; } var layout = view.LayoutStyle; try { view.LayoutStyle = LayoutStyle.Absolute; switch (_xRadioGroup.SelectedItem) { 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.SelectedItem) { 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.SelectedItem) { 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.SelectedItem) { 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"); } finally { view.LayoutStyle = layout; } UpdateTitle(view); }
public double pos(Dim dim) { double ret = colaPINVOKE.EdgePoint_pos(swigCPtr, (int)dim); return ret; }
View CreateClass(Type type) { // If we are to create a generic Type if (type.IsGenericType) { // For each of the <T> arguments List <Type> typeArguments = new List <Type> (); // use <object> foreach (var arg in type.GetGenericArguments()) { typeArguments.Add(typeof(object)); } // And change what type we are instantiating from MyClass<T> to MyClass<object> type = type.MakeGenericType(typeArguments.ToArray()); } // Instantiate view var view = (View)Activator.CreateInstance(type); //_curView.X = Pos.Center (); //_curView.Y = Pos.Center (); view.Width = Dim.Percent(75); view.Height = Dim.Percent(75); // Set the colorscheme to make it stand out if is null by default if (view.ColorScheme == null) { view.ColorScheme = Colors.Base; } // If the view supports a Text property, set it so we have something to look at if (view.GetType().GetProperty("Text") != null) { try { view.GetType().GetProperty("Text")?.GetSetMethod()?.Invoke(view, new [] { ustring.Make("Test Text") }); } catch (TargetInvocationException e) { MessageBox.ErrorQuery("Exception", e.InnerException.Message, "Ok"); view = null; } } // If the view supports a Title property, set it so we have something to look at if (view != null && view.GetType().GetProperty("Title") != null) { view?.GetType().GetProperty("Title")?.GetSetMethod()?.Invoke(view, new [] { ustring.Make("Test Title") }); } // If the view supports a Source property, set it so we have something to look at if (view != null && view.GetType().GetProperty("Source") != null && view.GetType().GetProperty("Source").PropertyType == typeof(Terminal.Gui.IListDataSource)) { var source = new ListWrapper(new List <ustring> () { ustring.Make("Test Text #1"), ustring.Make("Test Text #2"), ustring.Make("Test Text #3") }); view?.GetType().GetProperty("Source")?.GetSetMethod()?.Invoke(view, new [] { source }); } // Set Settings _computedCheckBox.Checked = view.LayoutStyle == LayoutStyle.Computed; // Add _hostPane.Add(view); //DimPosChanged (); _hostPane.LayoutSubviews(); _hostPane.Clear(); _hostPane.SetNeedsDisplay(); UpdateSettings(view); UpdateTitle(view); view.LayoutComplete += LayoutCompleteHandler; return(view); }
public void straighten(SWIGTYPE_p_std__vectorT_straightener__Edge_p_t arg0, Dim arg1) { colaPINVOKE.ConstrainedMajorizationLayout_straighten(swigCPtr, SWIGTYPE_p_std__vectorT_straightener__Edge_p_t.getCPtr(arg0), (int)arg1); if (colaPINVOKE.SWIGPendingException.Pending) throw colaPINVOKE.SWIGPendingException.Retrieve(); }