private void InitControls() { #region Init Elements var userList = new ListView(source: users) { Y = 1, X = 1, Width = Dim.Fill(), Height = Dim.Fill() - 5, }; Add(userList); var editButton = new Button("Edytuj") { X = Pos.Center() - 6, Y = Pos.Percent(100) - 3 }; Add(editButton); var addButton = new Button("Usuń") { X = Pos.Center() - 20, Y = Pos.Percent(100) - 3 }; Add(addButton); var deleteButton = new Button("Usuń") { X = Pos.Center() + 8, Y = Pos.Percent(100) - 3 }; Add(deleteButton); var backButton = new Button("Cofnij") { X = Pos.Center() - 6, Y = Pos.Percent(100) - 1 }; Add(backButton); #endregion userList.FocusFirst(); userList.OpenSelectedItem += (a) => { var tempUser = users[userList.SelectedItem]; MessageBox.Query(25, 11, "Szczegóły", $"Nazwa użytkownika: {tempUser.UserName}\nEmail: {tempUser.Email}\nNumer Telefonu: {tempUser.Phone}\nUlica: {tempUser.Adres1}\nMiejscowość: {tempUser.Adres2}\nKod pocztowy: {tempUser.Adres3}\nStatus: {Controller.HelpMethods.GetEnumDescription(tempUser.Rola)}", "Ok"); return; }; #region button operation addButton.Clicked += () => { OnAdd?.Invoke(); }; editButton.Clicked += () => { OnEdit?.Invoke(users[userList.SelectedItem]); }; deleteButton.Clicked += () => { var n = MessageBox.Query(25, 8, "Usuń", "Czy napewno chcesz usunąć wybranego użytkownika?", "Anuluj", "Ok"); if (n == 1) { OnRemove?.Invoke(users[userList.SelectedItem].UserId); } }; backButton.Clicked += () => { OnBack?.Invoke(); }; #endregion }
public override void Setup() { // Add a label & text field so we can demo IsDefault var editLabel = new Label("TextField (to demo IsDefault):") { X = 0, Y = 0, }; Win.Add(editLabel); var edit = new TextField("") { X = Pos.Right(editLabel) + 1, Y = Pos.Top(editLabel), Width = Dim.Fill(2), }; Win.Add(edit); // This is the default button (IsDefault = true); if user presses ENTER in the TextField // the scenario will quit var defaultButton = new Button("Quit") { X = Pos.Center(), //TODO: Change to use Pos.AnchorEnd() Y = Pos.Bottom(Win) - 3, IsDefault = true, Clicked = () => Application.RequestStop(), }; Win.Add(defaultButton); var y = 2; var button = new Button(10, y, "Base Color") { ColorScheme = Colors.Base, Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }; Win.Add(button); y += 2; Win.Add(new Button(10, y, "Error Color") { ColorScheme = Colors.Error, Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; Win.Add(new Button(10, y, "Dialog Color") { ColorScheme = Colors.Dialog, Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; Win.Add(new Button(10, y, "Menu Color") { ColorScheme = Colors.Menu, Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; Win.Add(new Button(10, y, "TopLevel Color") { ColorScheme = Colors.TopLevel, Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; Win.Add(new Button(10, y, "A super long button that will probably expose a bug in clipping or wrapping of text. Will it?") { Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; // Note the 'N' in 'Newline' will be the hotkey Win.Add(new Button(10, y, "a Newline\nin the button") { Clicked = () => MessageBox.Query(30, 7, "Message", "Question?", "Yes", "No") }); y += 2; // BUGBUG: Buttons don't support specifying hotkeys with _?!? Win.Add(button = new Button("Te_xt Changer") { X = 10, Y = y }); button.Clicked = () => button.Text += $"{y++}"; Win.Add(new Button("Lets see if this will move as \"Text Changer\" grows") { X = Pos.Right(button) + 10, Y = y, }); y += 2; Win.Add(new Button(10, y, "Delete") { ColorScheme = Colors.Error, Clicked = () => Win.Remove(button) }); y += 2; Win.Add(new Button(10, y, "Change Default") { Clicked = () => { defaultButton.IsDefault = !defaultButton.IsDefault; button.IsDefault = !button.IsDefault; }, }); }
private void Init() { ColorScheme = Colors.Error; // Creates the top-level window to show var win = new Window("TUIManager") { 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() }; win.ColorScheme = Colors.ColorSchemes["Dialog"]; Add(win); // Creates a menubar, the item "New" has a help menu. var menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_Options", new MenuItem [] { new MenuItem("_Change Config", "", () => { ChangeConfig(); }), new MenuItem("_Quit", "", () => { Application.RequestStop(); }) }) }); Add(menu); // Window Content _serialPortLabel = new Label("Serial Port:") { X = 2, Y = 1, Width = Dim.Fill() }; _comparisonLevelLabel = new Label("Comparison Level: 0") { X = Pos.Left(_serialPortLabel), Y = Pos.Bottom(_serialPortLabel), Width = Dim.Fill() }; _userCountLabel = new Label("Users: 0") { X = Pos.Left(_comparisonLevelLabel), Y = Pos.Bottom(_comparisonLevelLabel), Width = Dim.Fill() }; var userCountButton = new Button("Query _User Count") { X = Pos.Center(), Y = 7 }; userCountButton.Clicked += UserCountButton_Clicked; var readFingerprintButton = new Button("_Read Fingerprint") { X = Pos.Center(), Y = Pos.Bottom(userCountButton) + 1 }; readFingerprintButton.Clicked += ReadFingerprintButton_Clicked; var readEigenvaluesButton = new Button("Read _Eigenvalues") { X = Pos.Center(), Y = Pos.Bottom(readFingerprintButton) }; readEigenvaluesButton.Clicked += ReadEigenvaluesButton_Clicked; var readImageButton = new Button("Read _Image") { X = Pos.Center(), Y = Pos.Bottom(readEigenvaluesButton) }; readImageButton.Clicked += ReadImageButton_Clicked; var addFingerprintButton = new Button("_Add Fingerprint") { X = Pos.Center(), Y = Pos.Bottom(readImageButton) + 1 }; addFingerprintButton.Clicked += AddFingerprintButton_Clicked; var deleteAFingerprint = new Button("_Delete a Fingerprint") { X = Pos.Center(), Y = Pos.Bottom(addFingerprintButton) }; deleteAFingerprint.Clicked += DeleteAFingerprint_Clicked; var clearFingerprintsButton = new Button("_Clear Fingerprints") { X = Pos.Center(), Y = Pos.Bottom(deleteAFingerprint) }; clearFingerprintsButton.Clicked += ClearFingerprintsButton_Clicked; var setComparisonLevelButton = new Button("Set Comparison _Level") { X = Pos.Center(), Y = Pos.Bottom(clearFingerprintsButton) + 1 }; setComparisonLevelButton.Clicked += SetComparisonLevelButton_Clicked; var sleepButton = new Button("_Sleep Mode") { X = Pos.Center(), Y = Pos.Bottom(setComparisonLevelButton) + 1 }; sleepButton.Clicked += SleepButton_Clicked; var quitButton = new Button("_Quit") { X = Pos.Center(), Y = Pos.Percent(95) }; quitButton.Clicked += Quit_Clicked; win.Add( _serialPortLabel, _comparisonLevelLabel, _userCountLabel, userCountButton, readFingerprintButton, readEigenvaluesButton, readImageButton, addFingerprintButton, deleteAFingerprint, clearFingerprintsButton, setComparisonLevelButton, sleepButton, quitButton ); // Init Sensor if (!File.Exists(SettingsFilePath)) { Application.Run(new SettingsDisplay()); } InitSensor(); // Update gui UpdateSerialPort(); UpdateUserCount(); UpdateComparisonLevel(); }
public override void Setup() { var frame = new FrameView("MessageBox Options") { X = Pos.Center(), Y = 1, Width = Dim.Percent(75), Height = 10 }; Win.Add(frame); var label = new Label("width:") { X = 0, Y = 0, Width = 15, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var widthEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(widthEdit); label = new Label("height:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var heightEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(heightEdit); frame.Add(new Label("If height & width are both 0,") { X = Pos.Right(widthEdit) + 2, Y = Pos.Top(widthEdit), }); frame.Add(new Label("the MessageBox will be sized automatically.") { X = Pos.Right(heightEdit) + 2, Y = Pos.Top(heightEdit), }); label = new Label("Title:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var titleEdit = new TextField("Title") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = Dim.Fill(), Height = 1 }; frame.Add(titleEdit); label = new Label("Message:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var messageEdit = new TextView() { Text = "Message", X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = Dim.Fill(), Height = 5, ColorScheme = Colors.Dialog, }; frame.Add(messageEdit); label = new Label("Num Buttons:") { X = 0, Y = Pos.Bottom(messageEdit), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var numButtonsEdit = new TextField("3") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(numButtonsEdit); label = new Label("Style:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" }) { X = Pos.Right(label) + 1, Y = Pos.Top(label), }; frame.Add(styleRadioGroup); frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit) + Dim.Height(numButtonsEdit) + Dim.Height(styleRadioGroup) + 2; label = new Label("Button Pressed:") { X = Pos.Center(), Y = Pos.Bottom(frame) + 2, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; Win.Add(label); var buttonPressedLabel = new Label("") { X = Pos.Center(), Y = Pos.Bottom(frame) + 4, Width = 25, Height = 1, ColorScheme = Colors.Error, }; var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" }; var showMessageBoxButton = new Button("Show MessageBox") { X = Pos.Center(), Y = Pos.Bottom(frame) + 2, IsDefault = true, Clicked = () => { try { int width = int.Parse(widthEdit.Text.ToString()); int height = int.Parse(heightEdit.Text.ToString()); int numButtons = int.Parse(numButtonsEdit.Text.ToString()); var btns = new List <ustring> (); for (int i = 0; i < numButtons; i++) { btns.Add(btnText[i % 10]); } if (styleRadioGroup.SelectedItem == 0) { buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}"; } else { buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}"; } } catch (FormatException) { buttonPressedLabel.Text = "Invalid Options"; } }, }; Win.Add(showMessageBoxButton); Win.Add(buttonPressedLabel); }
public override void Setup() { var label = new Label("Insert the text to send:") { X = Pos.Center(), Y = Pos.Center() - 6 }; Win.Add(label); var txtInput = new TextField("MockKeyPresses") { X = Pos.Center(), Y = Pos.Center() - 5, Width = 20 }; Win.Add(txtInput); var ckbShift = new CheckBox("Shift") { X = Pos.Center(), Y = Pos.Center() - 4 }; Win.Add(ckbShift); var ckbAlt = new CheckBox("Alt") { X = Pos.Center(), Y = Pos.Center() - 3 }; Win.Add(ckbAlt); var ckbControl = new CheckBox("Control") { X = Pos.Center(), Y = Pos.Center() - 2 }; Win.Add(ckbControl); label = new Label("Result keys:") { X = Pos.Center(), Y = Pos.Center() + 1 }; Win.Add(label); var txtResult = new TextField() { X = Pos.Center(), Y = Pos.Center() + 2, Width = 20, }; Win.Add(txtResult); var rKeys = ""; var rControlKeys = ""; var IsShift = false; var IsAlt = false; var IsCtrl = false; txtResult.KeyPress += (e) => { rKeys += (char)e.KeyEvent.Key; if (!IsShift && e.KeyEvent.IsShift) { rControlKeys += " Shift "; IsShift = true; } if (!IsAlt && e.KeyEvent.IsAlt) { rControlKeys += " Alt "; IsAlt = true; } if (!IsCtrl && e.KeyEvent.IsCtrl) { rControlKeys += " Ctrl "; IsCtrl = true; } }; var lblShippedKeys = new Label() { X = Pos.Center(), Y = Pos.Center() + 3, AutoSize = true }; Win.Add(lblShippedKeys); var lblShippedControlKeys = new Label() { X = Pos.Center(), Y = Pos.Center() + 5, AutoSize = true }; Win.Add(lblShippedControlKeys); var button = new Button("Process keys") { X = Pos.Center(), Y = Pos.Center() + 7, IsDefault = true }; Win.Add(button); void ProcessInput() { rKeys = ""; rControlKeys = ""; txtResult.Text = ""; IsShift = false; IsAlt = false; IsCtrl = false; txtResult.SetFocus(); foreach (var r in txtInput.Text.ToString()) { var ck = char.IsLetter(r) ? (ConsoleKey)char.ToUpper(r) : (ConsoleKey)r; Application.Driver.SendKeys(r, ck, ckbShift.Checked, ckbAlt.Checked, ckbControl.Checked); } lblShippedKeys.Text = rKeys; lblShippedControlKeys.Text = rControlKeys; txtInput.SetFocus(); } button.Clicked += () => ProcessInput(); Win.KeyPress += (e) => { if (e.KeyEvent.Key == Key.Enter) { ProcessInput(); e.Handled = true; } }; }
public void LeftTopBottomRight_Win_ShouldNotThrow() { // Setup Fake driver (Window win, Button button) setup() { Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); Application.Iteration = () => { Application.RequestStop(); }; var win = new Window("window") { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), }; Application.Top.Add(win); var button = new Button("button") { X = Pos.Center(), }; win.Add(button); return(win, button); } Application.RunState rs; void cleanup(Application.RunState rs) { // Cleanup Application.End(rs); // Shutdown must be called to safely clean up Application if Init has been called Application.Shutdown(); } // Test cases: var app = setup(); app.button.Y = Pos.Left(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); app = setup(); app.button.Y = Pos.X(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); app = setup(); app.button.Y = Pos.Top(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); app = setup(); app.button.Y = Pos.Y(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); app = setup(); app.button.Y = Pos.Bottom(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); app = setup(); app.button.Y = Pos.Right(app.win); rs = Application.Begin(Application.Top); // If Application.RunState is used then we must use Application.RunLoop with the rs parameter Application.RunLoop(rs); cleanup(rs); }
public Toplevel settingsUI() { var settingsTop = new Toplevel(); var window = new Window("Settings") { X = Pos.Center(), Y = Pos.Center(), Width = 40, Height = 20, }; //var labelLength = new Label(1, 1, "Length (hours):"); var labelName = new Label(1, 3, "Contest Name:"); var labelET = new Label(1, 5, "Exchange type:"); var labelMode = new Label(1, 8, "Mode:"); var labelPower = new Label(20, 8, "Power:"); var labelBand = new Label(1, 12, "Band:"); var ContestName = new TextField(20, 3, 15, ""); var exchange = new RadioGroup(20, 5, new[] { "_Constant", "_Serial" }); var mode = new RadioGroup(7, 8, new[] { "PH", "CW", "DIGI" }); var power = new RadioGroup(27, 8, new[] { "HIGH", "LOW", "QRP" }); var band = new TextField(20, 12, 15, "40M"); var ok = new Button(30, 17, "OK") { Clicked = () => { sessionSettings.Length = 0; sessionSettings.ContestName = ContestName.Text.ToString(); sessionSettings.Band = band.Text.ToString(); sessionSettings.IncramentalExchg = Convert.ToBoolean(exchange.Selected); switch (mode.Selected) { case 0: sessionSettings.Mode = "PH"; break; case 1: sessionSettings.Mode = "CW"; break; case 2: sessionSettings.Mode = "DIGI"; break; } switch (power.Selected) { case 0: sessionSettings.Power = "HIGH"; break; case 1: sessionSettings.Power = "LOW"; break; case 2: sessionSettings.Power = "QRP"; break; } var top = new Toplevel(); top = MainUIToplevel(); Application.Run(top); } }; window.Add(//labelLength, labelName, labelET, labelMode, labelPower, labelBand, ContestName, exchange, mode, power, band, ok); settingsTop.Add(window); return(settingsTop); }
public Toplevel introUITopLevel() { window = new Window("New Log") { X = Pos.Center(), Y = Pos.Center(), Width = 40, Height = 20, }; var labelCallsign = new Label(1, 1, "Your Callsign:"); var labelITU = new Label(1, 3, "ITU Zone:"); var labelCQ = new Label(1, 5, "CQ Zone:"); var labelDB = new Label(1, 7, "Database Name:"); var labelSD = new Label(1, 9, "Log Start Date:"); var labelContestMode = new Label(1, 11, "Contest Mode?:"); callsignEntry = new TextField(20, 1, 12, ""); DatabaseName = new TextField(20, 7, 12, ""); StartDate = new DateField(20, 9, DateTime.Now, false); contestMode = new RadioGroup(20, 11, new[] { "_No", "_Yes" }); var ok = new Button(30, 17, "OK") { Clicked = () => { if (callsignEntry.Text != string.Empty && DatabaseName.Text != string.Empty) { settings.Callsign = callsignEntry.Text.ToString().ToUpper(); settings.ItuZone = Convert.ToInt32(ITUEntry.Text.ToString()); settings.CqZone = Convert.ToInt32(CQEntry.Text.ToString()); settings.CurrentDatabaseName = DatabaseName.Text.ToString(); settings.PreviousDatabaseName = settings.CurrentDatabaseName; //settings.LogStartDate = null; var SessionDatabase = new Database(settings.CurrentDatabaseName); //Load DB from DB name in settings var MainGui = new GUI.GUIClass(settings, SessionDatabase, locationLookup); Application.RequestStop(); Application.Init(); if (contestMode.Selected == 1) { settings.ContestMode = true; var top = MainGui.settingsUI(); Application.Run(top); } else { settings.ContestMode = false; var top = MainGui.MainUIToplevel(); Application.Run(top); } } else { Label label; var ok = new Button("ok") { Clicked = () => { Application.RequestStop(); } }; var dialog = new Dialog("Error", 60, 7, ok); if (callsignEntry.Text == string.Empty) { label = new Label("No callsign included"); } else if (DatabaseName.Text == string.Empty) { label = new Label("No database name included"); } else { label = new Label("Undefined error"); } dialog.Add(label); Application.Run(dialog); } } }; var cancel = new Button(45, 17, "Cancel") { Clicked = () => { Application.RequestStop(); Environment.Exit(1); } }; window.Add( labelCallsign, labelITU, labelCQ, labelDB, labelSD, labelContestMode, callsignEntry, DatabaseName, StartDate, contestMode, ok, cancel); callsignEntry.Changed += CallsignEntry_Changed; var introTop = Application.Top; introTop.Add(window); return(introTop); }
public MainWindow() : base("Codesanook") { X = 0; Y = 0; Width = Dim.Fill(); Height = Dim.Fill(); var topContainer = new View() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Percent(25), }; var middleContainer = new View() { X = 0, Y = Pos.Bottom(topContainer), Width = Dim.Fill(), Height = Dim.Percent(80), }; var bottomContainer = new View() { X = 0, Y = Pos.Bottom(middleContainer), Width = Dim.Fill(), Height = Dim.Fill() }; var leftContainer = new View() { X = 0, Y = 0, Width = Dim.Percent(50), Height = Dim.Fill(), }; leftPanel = new Panel("Left Panel"); leftContainer.Add(leftPanel); var rightContainer = new View() { X = Pos.Right(leftContainer), // Read as "position at right of left container" Y = 0, Width = Dim.Fill(), //fill of left area Height = Dim.Fill(), }; rightPanel = new Panel("right Panel"); rightContainer.Add(rightPanel); middleContainer.Add(leftContainer, rightContainer); var button = new Button("ok") { X = Pos.Center(), Y = Pos.Center(), }; bottomContainer.Add(button); //https://github.com/migueldeicaza/gui.cs/blob/master/Terminal.Gui/Views/RadioGroup.cs radioGroup = new RadioGroup(0, 0, new[] { "Read Uncommited", "Read Committed", "Non Repeatable Read", "Repeatable Read", "Phantom New Row", "Serializable", "Snapshot", "Read Committed Snapshot", }); topContainer.Add(radioGroup); Add(topContainer, middleContainer, bottomContainer); button.Clicked = ClickAsync; }
/// <summary> /// Creats and add a listView with all Pull Request to the GUI asynchronous /// </summary> private static async Task ListPullRequest() { var PRDialog = new Dialog("Pull Requests", 0, 0) { Width = Dim.Percent(90), Height = Dim.Percent(90) }; var PRList = new List <string>(); var PrView = new ListView(PRList) { X = 1, Y = 4, Width = Dim.Fill() - 4, Height = Dim.Fill() - 1 }; PRDialog.Add(PrView); var seperator = "--------------------------------------------------------------------------------------------------"; var response = new PullRequestResponse(); try { response = await PullRequestService.GetAllPR(orgTokList, settings); if (response != null) { foreach (var org in response.Organizations) { if (org.Success) { PRList.Add(seperator); var organization = "************ Org Name: " + org.OrganizationName + " ***************"; PRList.Add(organization); foreach (var rep in org.Repositories) { if (rep.PullRequests.Length != 0) { var repoName = "--REPO NAME--: " + rep.Name; PRList.Add(repoName); foreach (var pr in rep.PullRequests) { var pullReqcont = " contributor: " + pr.DisplayName; var pullReqTitleDesc = " Title/Description: " + pr.Title + "/" + pr.Description; var pullReqUri = " Uri: " + pr.Url; PRList.Add(pullReqcont); PRList.Add(pullReqTitleDesc); PRList.Add(pullReqUri); } } } PRList.Add(seperator); } else { var errorMessage = "Organiazation with name: " + "'" + org.OrganizationName + "' could not be found"; var adviceMessage = "Please check name spelling and access token"; PRList.Add(seperator); PRList.Add(errorMessage); PRList.Add(adviceMessage); PRList.Add(seperator); } } } else if (response == null && orgTokList.Count != 0) { PRList.Add("CONNECTION ERROR, Check settings or internet connection"); } else if (response == null && orgTokList.Count == 0) { PRList.Add("NO ORGANIZATIONS ARE ADDED"); } else { if (PRList.Count == 0) { PRList.Add("NO PULL REQEUSTS ARE AVAILABLE AT THE MOMOENT"); } } } catch (Exception ex) { PRList.Add("Warning: Please check app Settings or internet Connection! "); PRList.Add("Http exception: " + ex.Message); } Button retrn = new Button("Return") { X = Pos.Center(), Y = Pos.AnchorEnd(1), Clicked = () => { Application.RequestStop(); } }; PRDialog.Add(retrn); Application.Run(PRDialog); }
/// <summary> /// Creates a Dialog that allow user to view and edit API settings /// </summary> private static void CreateSettingEditDialog() { var editSettingDialog = new Dialog("Edit Settings", 100, 100) { Height = Dim.Percent(50) }; List <string> sourceList = new List <string>(); var settingsListView = new ListViewSelection(sourceList) { X = 1, Y = 2, Width = Dim.Fill(6), Height = Dim.Fill() - 4 }; if (settings == null) { sourceList.Add("No Settings Added Yet"); settingsListView.SetSource(sourceList); } else { sourceList.Add($"URI: {settings.BaseUrl}"); sourceList.Add($"Key: {settings.ApiKey}"); settingsListView.SetSource(sourceList); } var add = new Button("Edit Settings") { X = Pos.Center() - 20, Y = Pos.AnchorEnd(2), Clicked = () => { if (settings != null) { CreateInputDialog("Api", "Key", settings.BaseUrl, settings.ApiKey); } else { CreateInputDialog("Api", "Key"); } if (settings != null) { sourceList.Clear(); sourceList.Add($"URI: {settings.BaseUrl}"); sourceList.Add($"Key: {settings.ApiKey}"); settingsListView.SetSource(sourceList); } } }; Button retrn = new Button("Return") { X = Pos.Center() + 10, Y = Pos.AnchorEnd(2), Clicked = () => { Application.RequestStop(); } }; editSettingDialog.Add(settingsListView, add, retrn); Application.Run(editSettingDialog); }
private void InitControls() { #region Init Elements var reservationList = new ListView(source: reservations) { Y = 1, X = 1, Width = Dim.Fill(), Height = Dim.Fill() - 5, }; Add(reservationList); var editButton = new Button("Edytuj") { X = Pos.Center() - 6, Y = Pos.Percent(100) - 3 }; Add(editButton); var addButton = new Button("Dodaj") { X = Pos.Center() - 20, Y = Pos.Percent(100) - 3 }; Add(addButton); var deleteButton = new Button("Usuń") { X = Pos.Center() + 8, Y = Pos.Percent(100) - 3 }; Add(deleteButton); var backButton = new Button("Cofnij") { X = Pos.Center() - 6, Y = Pos.Percent(100) - 1 }; Add(backButton); #endregion reservationList.FocusFirst(); reservationList.OpenSelectedItem += (a) => { var tempReservation = reservations[reservationList.SelectedItem]; MessageBox.Query(25, 12, "Szczegóły", $"Użytkownik: {tempReservation.User}\nSamochód: {tempReservation.Car}\nData od: {tempReservation.DateFrom}\nData do: {tempReservation.DateTo}\nUwagi: {tempReservation.Comments}\nKoszt: {tempReservation.Cost} PLN\nKaucja: {tempReservation.Car.CarBail} PLN\nStatus: {Controller.HelpMethods.GetEnumDescription(tempReservation.Status)}", "Ok"); return; }; #region button operation addButton.Clicked += () => { OnAdd?.Invoke(); }; editButton.Clicked += () => { OnEdit?.Invoke(reservations[reservationList.SelectedItem]); }; deleteButton.Clicked += () => { var n = MessageBox.Query(25, 8, "Usuń", "Czy napewno chcesz usunąć wybraną rezerwację?", "Anuluj", "Ok"); if (n == 1) { OnRemove?.Invoke(reservations[reservationList.SelectedItem].ReservationId); reservations.Remove(reservations[reservationList.SelectedItem]); } }; backButton.Clicked += () => { OnBack?.Invoke(); }; #endregion }
public override void Setup() { const float fractionStep = 0.01F; const int pbWidth = 20; var pbFormatEnum = Enum.GetValues(typeof(ProgressBarFormat)).Cast <ProgressBarFormat> ().ToList(); var rbPBFormat = new RadioGroup(pbFormatEnum.Select(e => NStack.ustring.Make(e.ToString())).ToArray()) { X = Pos.Center(), Y = 1 }; Win.Add(rbPBFormat); var ckbBidirectional = new CheckBox("BidirectionalMarquee", true) { X = Pos.Center(), Y = Pos.Bottom(rbPBFormat) + 1 }; Win.Add(ckbBidirectional); var label = new Label("Blocks") { X = Pos.Center(), Y = Pos.Bottom(ckbBidirectional) + 1 }; Win.Add(label); var blocksPB = new ProgressBar() { X = Pos.Center(), Y = Pos.Y(label) + 1, Width = pbWidth }; Win.Add(blocksPB); label = new Label("Continuous") { X = Pos.Center(), Y = Pos.Bottom(blocksPB) + 1 }; Win.Add(label); var continuousPB = new ProgressBar() { X = Pos.Center(), Y = Pos.Y(label) + 1, Width = pbWidth, ProgressBarStyle = ProgressBarStyle.Continuous }; Win.Add(continuousPB); var button = new Button("Start timer") { X = Pos.Center(), Y = Pos.Bottom(continuousPB) + 1 }; button.Clicked += () => { if (_fractionTimer == null) { button.Enabled = false; blocksPB.Fraction = 0; continuousPB.Fraction = 0; float fractionSum = 0; _fractionTimer = new Timer((_) => { fractionSum += fractionStep; blocksPB.Fraction = fractionSum; continuousPB.Fraction = fractionSum; if (fractionSum > 1) { _fractionTimer.Dispose(); _fractionTimer = null; button.Enabled = true; } Application.MainLoop.Driver.Wakeup(); }, null, 0, _timerTick); } }; Win.Add(button); label = new Label("Marquee Blocks") { X = Pos.Center(), Y = Pos.Y(button) + 3 }; Win.Add(label); var marqueesBlocksPB = new ProgressBar() { X = Pos.Center(), Y = Pos.Y(label) + 1, Width = pbWidth, ProgressBarStyle = ProgressBarStyle.MarqueeBlocks }; Win.Add(marqueesBlocksPB); label = new Label("Marquee Continuous") { X = Pos.Center(), Y = Pos.Bottom(marqueesBlocksPB) + 1 }; Win.Add(label); var marqueesContinuousPB = new ProgressBar() { X = Pos.Center(), Y = Pos.Y(label) + 1, Width = pbWidth, ProgressBarStyle = ProgressBarStyle.MarqueeContinuous }; Win.Add(marqueesContinuousPB); rbPBFormat.SelectedItemChanged += (e) => { blocksPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; continuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; marqueesBlocksPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; marqueesContinuousPB.ProgressBarFormat = (ProgressBarFormat)e.SelectedItem; }; ckbBidirectional.Toggled += (e) => { ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = !e; }; _pulseTimer = new Timer((_) => { marqueesBlocksPB.Text = marqueesContinuousPB.Text = DateTime.Now.TimeOfDay.ToString(); marqueesBlocksPB.Pulse(); marqueesContinuousPB.Pulse(); Application.MainLoop.Driver.Wakeup(); }, null, 0, 300); Top.Unloaded += Top_Unloaded; void Top_Unloaded() { if (_pulseTimer != null) { _pulseTimer.Dispose(); _pulseTimer = null; Top.Unloaded -= Top_Unloaded; } } }
private static void Main(string[] args) { Application.Init(); var top = Application.Top; var win = new Window("Factorino Toolbox") { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill() - 1 }; var welcome = new Label("Welcome to the Factorino toolbox") { X = Pos.Center(), Y = Pos.Center() - 2, Height = 1, }; win.Add(welcome); var produceBtn = new Button("Produce events") { X = Pos.Center(), Y = Pos.Center() + 1, Height = 1, }; produceBtn.Clicked += delegate() { var producer = new SelectEventDialog(); Application.Run(producer); }; win.Add(produceBtn); var startKitBtn = new Button("Give Starter Kit") { X = Pos.Center(), Y = Pos.Center() + 3, Height = 1, }; startKitBtn.Clicked += delegate() { var starterKitDialog = new StarterKitDialog(); Application.Run(starterKitDialog); }; win.Add(startKitBtn); var quitBtn = new Button("Quit") { X = Pos.Center(), Y = Pos.Center() + 5, Height = 1, }; quitBtn.Clicked += delegate() { top.Running = false; }; win.Add(quitBtn); top.Add(win); Application.Run(); }
public override void Setup() { var text = "Hello World"; var color = Colors.Dialog; var labelH = new Label(text, TextDirection.LeftRight_TopBottom) { X = 1, Y = 1, ColorScheme = color }; Win.Add(labelH); var labelV = new Label(text, TextDirection.TopBottom_LeftRight) { X = 70, Y = 1, ColorScheme = color }; Win.Add(labelV); var editText = new TextView() { X = Pos.Center(), Y = Pos.Center(), Width = 20, Height = 5, ColorScheme = color, Text = text }; editText.SetFocus(); Win.Add(editText); var ckbDirection = new CheckBox("Toggle Direction") { X = Pos.Center(), Y = Pos.Center() + 3 }; ckbDirection.Toggled += (_) => { if (labelH.TextDirection == TextDirection.LeftRight_TopBottom) { labelH.TextDirection = TextDirection.TopBottom_LeftRight; labelV.TextDirection = TextDirection.LeftRight_TopBottom; } else { labelH.TextDirection = TextDirection.LeftRight_TopBottom; labelV.TextDirection = TextDirection.TopBottom_LeftRight; } }; Win.Add(ckbDirection); var ckbAutoSize = new CheckBox("Auto Size") { X = Pos.Center(), Y = Pos.Center() + 5, Checked = labelH.AutoSize = labelV.AutoSize }; ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = ckbAutoSize.Checked; Win.Add(ckbAutoSize); Win.KeyUp += (_) => labelH.Text = labelV.Text = text = editText.Text.ToString(); }
public override void Init(Toplevel top, ColorScheme colorScheme) { top.Dispose(); Application.Init(); top = Application.Top; 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 win = new Window(new Rect(5, 5, 40, 20), "Test", 8, new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }); 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 tv = new TextView() { Y = Pos.AnchorEnd(2), Width = 10, Height = Dim.Fill(), ColorScheme = Colors.Dialog, Text = "1234567890" }; var tf2 = new TextField("1234567890") { X = Pos.AnchorEnd(10), Y = Pos.AnchorEnd(1), Width = 10 }; win.Add(tf1, button, label, tv, tf2); top.Add(win); var top2 = new Border.ToplevelContainer(new Rect(50, 5, 40, 20), new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }, "Test2") { ColorScheme = Colors.Base, }; var tf3 = new TextField("1234567890") { Width = 10 }; var button2 = new Button("Press me!") { X = Pos.Center(), Y = Pos.Center(), }; button2.Clicked += () => MessageBox.Query(20, 7, "Hi", "I'm a Toplevel?", "Yes", "No"); var label2 = new Label("I'm a Toplevel") { X = Pos.Center(), Y = Pos.Center() - 3, }; var tv2 = new TextView() { Y = Pos.AnchorEnd(2), Width = 10, Height = Dim.Fill(), ColorScheme = Colors.Dialog, Text = "1234567890" }; var tf4 = new TextField("1234567890") { X = Pos.AnchorEnd(10), Y = Pos.AnchorEnd(1), Width = 10 }; top2.Add(tf3, button2, label2, tv2, tf4); top.Add(top2); var frm = new FrameView(new Rect(95, 5, 40, 20), "Test3", null, new Border() { BorderStyle = borderStyle, DrawMarginFrame = drawMarginFrame, BorderThickness = borderThickness, BorderBrush = borderBrush, Padding = padding, Background = background, Effect3D = effect3D }) { ColorScheme = Colors.Base }; var tf5 = new TextField("1234567890") { Width = 10 }; var button3 = new Button("Press me!") { X = Pos.Center(), Y = Pos.Center(), }; button3.Clicked += () => MessageBox.Query(20, 7, "Hi", "I'm a FrameView?", "Yes", "No"); var label3 = new Label("I'm a FrameView") { X = Pos.Center(), Y = Pos.Center() - 3, }; var tv3 = new TextView() { Y = Pos.AnchorEnd(2), Width = 10, Height = Dim.Fill(), ColorScheme = Colors.Dialog, Text = "1234567890" }; var tf6 = new TextField("1234567890") { X = Pos.AnchorEnd(10), Y = Pos.AnchorEnd(1), Width = 10 }; frm.Add(tf5, button3, label3, tv3, tf6); top.Add(frm); Application.Run(); }
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 FrameView() { 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 FrameView?", "Yes", "No"); var label = new Label("I'm a FrameView") { 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); }
public override void Setup() { var frame = new FrameView("MessageBox Options") { X = Pos.Center(), Y = 1, Width = Dim.Percent(75), Height = 10 }; Win.Add(frame); var label = new Label("width:") { X = 0, Y = 0, Width = 15, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var widthEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(widthEdit); label = new Label("height:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var heightEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(heightEdit); frame.Add(new Label("If height & width are both 0,") { X = Pos.Right(widthEdit) + 2, Y = Pos.Top(widthEdit), }); frame.Add(new Label("the MessageBox will be sized automatically.") { X = Pos.Right(heightEdit) + 2, Y = Pos.Top(heightEdit), }); label = new Label("Title:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var titleEdit = new TextField("Title") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = Dim.Fill(), Height = 1 }; frame.Add(titleEdit); label = new Label("Message:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var messageEdit = new TextView() { Text = "Message", X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = Dim.Fill(), Height = 5, ColorScheme = Colors.Dialog, }; frame.Add(messageEdit); label = new Label("Num Buttons:") { X = 0, Y = Pos.Bottom(messageEdit), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var numButtonsEdit = new TextField("3") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(numButtonsEdit); label = new Label("Default Button:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var defaultButtonEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(defaultButtonEdit); label = new Label("Style:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" }) { X = Pos.Right(label) + 1, Y = Pos.Top(label), }; frame.Add(styleRadioGroup); var border = new Border() { Effect3D = true, BorderStyle = BorderStyle.Single }; var ckbEffect3D = new CheckBox("Effect3D", true) { X = Pos.Right(label) + 1, Y = Pos.Top(label) + 2 }; ckbEffect3D.Toggled += (e) => { border.Effect3D = !e; }; frame.Add(ckbEffect3D); void Top_Loaded() { frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit) + Dim.Height(numButtonsEdit) + Dim.Height(defaultButtonEdit) + Dim.Height(styleRadioGroup) + 2 + Dim.Height(ckbEffect3D); Top.Loaded -= Top_Loaded; } Top.Loaded += Top_Loaded; label = new Label("Button Pressed:") { X = Pos.Center(), Y = Pos.Bottom(frame) + 4, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; Win.Add(label); var buttonPressedLabel = new Label(" ") { X = Pos.Center(), Y = Pos.Bottom(frame) + 5, Width = 25, Height = 1, ColorScheme = Colors.Error, TextAlignment = Terminal.Gui.TextAlignment.Centered }; //var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" }; var showMessageBoxButton = new Button("Show MessageBox") { X = Pos.Center(), Y = Pos.Bottom(frame) + 2, IsDefault = true, }; showMessageBoxButton.Clicked += () => { try { int width = int.Parse(widthEdit.Text.ToString()); int height = int.Parse(heightEdit.Text.ToString()); int numButtons = int.Parse(numButtonsEdit.Text.ToString()); int defaultButton = int.Parse(defaultButtonEdit.Text.ToString()); var btns = new List <ustring> (); for (int i = 0; i < numButtons; i++) { //btns.Add(btnText[i % 10]); btns.Add(NumberToWords.Convert(i)); } if (styleRadioGroup.SelectedItem == 0) { buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}"; } else { buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}"; } } catch (FormatException) { buttonPressedLabel.Text = "Invalid Options"; } }; Win.Add(showMessageBoxButton); Win.Add(buttonPressedLabel); }
public void Center_SetsValue() { var pos = Pos.Center(); Assert.Equal("Pos.Center", pos.ToString()); }
private uint _mainLooopTimeoutTick = 1000; // ms public override void Setup() { // Demo #1 - Use System.Timer (and threading) var systemTimerDemo = new ProgressDemo("System.Timer (threads)") { X = 0, Y = 0, Width = Dim.Percent(100), }; systemTimerDemo.StartBtnClick = () => { _systemTimer?.Dispose(); _systemTimer = null; systemTimerDemo.ActivityProgressBar.Fraction = 0F; systemTimerDemo.PulseProgressBar.Fraction = 0F; _systemTimer = new Timer((o) => { // Note the check for Mainloop being valid. System.Timers can run after they are Disposed. // This code must be defensive for that. Application.MainLoop?.Invoke(() => systemTimerDemo.Pulse()); }, null, 0, _systemTimerTick); }; systemTimerDemo.StopBtnClick = () => { _systemTimer?.Dispose(); _systemTimer = null; systemTimerDemo.ActivityProgressBar.Fraction = 1F; systemTimerDemo.PulseProgressBar.Fraction = 1F; }; systemTimerDemo.Speed.Text = $"{_systemTimerTick}"; systemTimerDemo.Speed.Changed += (sender, a) => { uint result; if (uint.TryParse(systemTimerDemo.Speed.Text.ToString(), out result)) { _systemTimerTick = result; System.Diagnostics.Debug.WriteLine($"{_systemTimerTick}"); if (systemTimerDemo.Started) { systemTimerDemo.Start(); } } else { System.Diagnostics.Debug.WriteLine("bad entry"); } }; Win.Add(systemTimerDemo); // Demo #2 - Use Application.MainLoop.AddTimeout (no threads) var mainLoopTimeoutDemo = new ProgressDemo("Application.AddTimer (no threads)") { X = 0, Y = Pos.Bottom(systemTimerDemo), Width = Dim.Percent(100), }; mainLoopTimeoutDemo.StartBtnClick = () => { mainLoopTimeoutDemo.StopBtnClick(); mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 0F; mainLoopTimeoutDemo.PulseProgressBar.Fraction = 0F; _mainLoopTimeout = Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(_mainLooopTimeoutTick), (loop) => { mainLoopTimeoutDemo.Pulse(); return(true); }); }; mainLoopTimeoutDemo.StopBtnClick = () => { if (_mainLoopTimeout != null) { Application.MainLoop.RemoveTimeout(_mainLoopTimeout); _mainLoopTimeout = null; } mainLoopTimeoutDemo.ActivityProgressBar.Fraction = 1F; mainLoopTimeoutDemo.PulseProgressBar.Fraction = 1F; }; mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}"; mainLoopTimeoutDemo.Speed.Changed += (sender, a) => { uint result; if (uint.TryParse(mainLoopTimeoutDemo.Speed.Text.ToString(), out result)) { _mainLooopTimeoutTick = result; if (mainLoopTimeoutDemo.Started) { mainLoopTimeoutDemo.Start(); } } }; Win.Add(mainLoopTimeoutDemo); var startBoth = new Button("Start Both") { X = Pos.Center(), Y = Pos.Bottom(mainLoopTimeoutDemo) + 1, }; startBoth.Clicked = () => { systemTimerDemo.Start(); mainLoopTimeoutDemo.Start(); }; Win.Add(startBoth); }
public void Start() { string _contentLabelText = ""; Application.Init(); List <string> _contentListViewList = new List <string>(); TextView contentLabel = new TextView() { Width = Dim.Fill(), Height = 1, CanFocus = false }; contentLabel.Text = _contentLabelText; Colors.Base.Normal = Application.Driver.MakeAttribute(Color.White, Color.Black); FrameView _selectFrame = new FrameView() { X = 0, Y = 0, Width = Dim.Fill(1), Height = 9, CanFocus = false }; FrameView _contentFrame = new FrameView() { X = 0, Y = 9, Height = Dim.Fill(0), Width = Dim.Fill(1), CanFocus = false }; ListView _contentListView = new ListView(_contentListViewList) { Y = 2, X = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), AllowsMarking = false, CanFocus = false }; TextField _ipInputField = new TextField() { Y = 1, X = 0, Width = Dim.Fill(0), Height = Dim.Fill(0), CanFocus = false }; Button[] selectors = new Button[3]; Button _send = new Button("Send") { Y = Pos.Bottom(_selectFrame) - 3, CanFocus = true }; Button _incoming = new Button("Incoming") { X = Pos.Center(), Y = Pos.Bottom(_selectFrame) - 3, CanFocus = true }; Button _quit = new Button("Quit") { X = Pos.Right(_selectFrame) - "Quit".Length - 6, Y = Pos.Bottom(_selectFrame) - 3, CanFocus = true }; _send.Enter += (a) => { contentLabel.Text = "Select to send a document"; //contentLabel.Redraw(new Rect(0, 0, 1, _contentLabelText.Length)); }; _incoming.Enter += (a) => { contentLabel.Text = "View Incoming or Recieved messages"; }; _quit.Enter += (a) => { contentLabel.Text = "Quit the program"; }; selectors[0] = _send; selectors[1] = _incoming; selectors[2] = _quit; _selectFrame.Add(selectors); _selectFrame.Add(new Label(Logo()) { X = Pos.Center() }); _contentFrame.Add(_contentListView); _contentFrame.Add(contentLabel); _contentFrame.Add(_ipInputField); //_contentFrame.Add(); Application.Top.Add(_selectFrame); Application.Top.Add(_contentFrame); _send.Clicked += () => SendButton(contentLabel, _contentListView, _ipInputField); _quit.Clicked += () => { Application.Shutdown(); Environment.Exit(0); }; _incoming.Clicked += () => RecieveFileList(contentLabel, _contentListView); _contentFrame.Leave += (a) => ClearListView(_contentListView, _contentFrame, _send, _ipInputField); _contentListView.OpenSelectedItem += (a) => ClearListView(_contentListView, _contentFrame, _send, _ipInputField); Application.Run(); string Logo() { StringBuilder titleString = new StringBuilder(); titleString.AppendLine(" _|_|_| _| _| _| _| _| _| "); titleString.AppendLine(" _| _|_|_| _|_|_| _| _|_| _|_| _|_|_| _| "); titleString.AppendLine(" _|_| _| _| _| _| _| _| _| _| _| _| _| _| _| "); titleString.AppendLine(" _| _| _| _| _| _| _| _| _| _| _| _| _| "); titleString.AppendLine(" _|_|_| _| _| _|_|_| _| _| _| _| _|_|_| _| _| "); return(titleString.ToString()); } }
private void InitControls() { #region Staff Panel var staffTitle = new Label("___Panel Pracownika___") { X = Pos.Center() - 11, Y = Pos.Percent(10), }; var reservationManageButton = new Button("Zarządzaj rezerwacjami [F1]") { X = Pos.Percent(33) - 11, Y = Pos.Percent(20), }; var carManageButton = new Button("Zarządzaj samochodami [F2]") { X = Pos.Percent(66) - 11, Y = Pos.Percent(20), }; var modelManageButton = new Button("Zarządzaj modelami [F3]") { X = Pos.Percent(33) - 9, Y = Pos.Percent(30), }; var markManageButton = new Button("Zarządzaj markami [F4]") { X = Pos.Percent(66) - 9, Y = Pos.Percent(30), }; var settingsButton = new Button("Ustawienia Aplikacji [F5]") { X = Pos.Center() - 10, Y = Pos.Percent(40), }; Add(staffTitle); Add(reservationManageButton); Add(carManageButton); Add(modelManageButton); Add(markManageButton); Add(settingsButton); #endregion #region Admin Panel var adminTitle = new Label("___Panel Administratora___") { X = Pos.Center() - 13, Y = Pos.Percent(50), }; var userManageButton = new Button("Zarządzaj użytkownikami") { X = Pos.Center() - 12, Y = Pos.Percent(60), }; if (user.Rola == Model.UserRole.Admin) { Add(adminTitle); Add(userManageButton); } #endregion #region Logout and Exit Button var exitButton = new Button("Wyjdź [F6]") { X = Pos.Percent(50) - 15, Y = Pos.Percent(100) - 2, }; Add(exitButton); var logoutButton = new Button("Wyloguj [F7]") { X = Pos.Percent(50) + 5, Y = Pos.Percent(100) - 2, }; Add(logoutButton); #endregion #region bind-button-events exitButton.Clicked += () => { //Close(); OnExit?.Invoke(); }; logoutButton.Clicked += () => { //Close(); OnLogout?.Invoke(); }; reservationManageButton.Clicked += () => { //Close(); OnSelect?.Invoke(1); }; carManageButton.Clicked += () => { //Close(); OnSelect?.Invoke(2); }; modelManageButton.Clicked += () => { //Close(); OnSelect?.Invoke(3); }; markManageButton.Clicked += () => { //Close(); OnSelect?.Invoke(4); }; userManageButton.Clicked += () => { //Close(); OnSelect?.Invoke(5); }; settingsButton.Clicked += () => { OnSelect?.Invoke(6); }; KeyDown += (a) => { switch (a.KeyEvent.Key) { case Key.F1: OnSelect?.Invoke(1); break; case Key.F2: OnSelect?.Invoke(2); break; case Key.F3: OnSelect?.Invoke(3); break; case Key.F4: OnSelect?.Invoke(4); break; case Key.F5: OnSelect?.Invoke(6); break; case Key.F6: OnExit?.Invoke(); break; case Key.F7: OnLogout?.Invoke(); break; default: break; } }; #endregion }
private void RunWorker() { worker = new BackgroundWorker() { WorkerSupportsCancellation = true }; var cancel = new Button("Cancel Worker"); cancel.Clicked += () => { if (worker == null) { log.Add($"Worker is not running at {DateTime.Now}!"); listLog.SetNeedsDisplay(); return; } log.Add($"Worker {startStaging}.{startStaging:fff} is canceling at {DateTime.Now}!"); listLog.SetNeedsDisplay(); worker.CancelAsync(); }; startStaging = DateTime.Now; log.Add($"Worker is started at {startStaging}.{startStaging:fff}"); listLog.SetNeedsDisplay(); var md = new Dialog($"Running Worker started at {startStaging}.{startStaging:fff}", cancel); md.Add(new Label("Wait for worker to finish...") { X = Pos.Center(), Y = Pos.Center() }); worker.DoWork += (s, e) => { var stageResult = new List <string>(); for (int i = 0; i < 500; i++) { stageResult.Add($"Worker {i} started at {DateTime.Now}"); e.Result = stageResult; Thread.Sleep(1); if (worker.CancellationPending) { e.Cancel = true; return; } } }; worker.RunWorkerCompleted += (s, e) => { if (md.IsCurrentTop) { //Close the dialog Application.RequestStop(); } if (e.Error != null) { // Failed log.Add( $"Exception occurred {e.Error.Message} on Worker {startStaging}.{startStaging:fff} at {DateTime.Now}"); listLog.SetNeedsDisplay(); } else if (e.Cancelled) { // Canceled log.Add($"Worker {startStaging}.{startStaging:fff} was canceled at {DateTime.Now}!"); listLog.SetNeedsDisplay(); } else { // Passed log.Add($"Worker {startStaging}.{startStaging:fff} was completed at {DateTime.Now}."); listLog.SetNeedsDisplay(); Application.Refresh(); var builderUI = new StagingUiController(startStaging, e.Result as List <string>); builderUI.Load(); } worker = null; }; worker.RunWorkerAsync(); Application.Run(md); }
public override void Setup() { var frame = new FrameView("Dialog Options") { X = Pos.Center(), Y = 1, Width = Dim.Percent(75), Height = 10 }; Win.Add(frame); var label = new Label("width:") { X = 0, Y = 0, Width = 15, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var widthEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(widthEdit); label = new Label("height:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var heightEdit = new TextField("0") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(heightEdit); frame.Add(new Label("If height & width are both 0,") { X = Pos.Right(widthEdit) + 2, Y = Pos.Top(widthEdit), }); frame.Add(new Label("the Dialog will size to 80% of container.") { X = Pos.Right(heightEdit) + 2, Y = Pos.Top(heightEdit), }); label = new Label("Title:") { X = 0, Y = Pos.Bottom(label), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var titleEdit = new TextField("Title") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = Dim.Fill(), Height = 1 }; frame.Add(titleEdit); label = new Label("Num Buttons:") { X = 0, Y = Pos.Bottom(titleEdit), Width = Dim.Width(label), Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; frame.Add(label); var numButtonsEdit = new TextField("3") { X = Pos.Right(label) + 1, Y = Pos.Top(label), Width = 5, Height = 1 }; frame.Add(numButtonsEdit); void Top_Loaded() { frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(numButtonsEdit) + 2; Top.Loaded -= Top_Loaded; } Top.Loaded += Top_Loaded; label = new Label("Button Pressed:") { X = Pos.Center(), Y = Pos.Bottom(frame) + 4, Height = 1, TextAlignment = Terminal.Gui.TextAlignment.Right, }; Win.Add(label); var buttonPressedLabel = new Label(" ") { X = Pos.Center(), Y = Pos.Bottom(frame) + 5, Width = 25, Height = 1, ColorScheme = Colors.Error, }; //var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" }; var showDialogButton = new Button("Show Dialog") { X = Pos.Center(), Y = Pos.Bottom(frame) + 2, IsDefault = true, }; showDialogButton.Clicked += () => { try { int width = int.Parse(widthEdit.Text.ToString()); int height = int.Parse(heightEdit.Text.ToString()); int numButtons = int.Parse(numButtonsEdit.Text.ToString()); var buttons = new List <Button> (); var clicked = -1; for (int i = 0; i < numButtons; i++) { var buttonId = i; //var button = new Button (btnText [buttonId % 10], // is_default: buttonId == 0); var button = new Button(NumberToWords.Convert(buttonId), is_default: buttonId == 0); button.Clicked += () => { clicked = buttonId; Application.RequestStop(); }; buttons.Add(button); } // This tests dynamically adding buttons; ensuring the dialog resizes if needed and // the buttons are laid out correctly var dialog = new Dialog(titleEdit.Text, width, height, buttons.ToArray()); var add = new Button("Add a button") { X = Pos.Center(), Y = Pos.Center() }; add.Clicked += () => { var buttonId = buttons.Count; //var button = new Button (btnText [buttonId % 10], // is_default: buttonId == 0); var button = new Button(NumberToWords.Convert(buttonId), is_default: buttonId == 0); button.Clicked += () => { clicked = buttonId; Application.RequestStop(); }; buttons.Add(button); dialog.AddButton(button); button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1; }; dialog.Add(add); Application.Run(dialog); buttonPressedLabel.Text = $"{clicked}"; } catch (FormatException) { buttonPressedLabel.Text = "Invalid Options"; } }; Win.Add(showDialogButton); Win.Add(buttonPressedLabel); }
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); }; }
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); }
private void InitControls() { #region User Panel var showCarsButton = new Button("Przeglądaj samochody [F1] ") { X = Pos.Percent(33) - 12, Y = Pos.Percent(10), }; var rentCarButton = new Button("Wypożycz samochód [F2] ") { X = Pos.Percent(66) - 11, Y = Pos.Percent(10), }; var historyButton = new Button("Historia wypożyczeń [F3] ") { X = Pos.Percent(33) - 12, Y = Pos.Percent(20), }; var accountButton = new Button("Moje Konto [F4] ") { X = Pos.Percent(66) - 7, Y = Pos.Percent(20), }; var setingsButton = new Button("Ustawienia [F5] ") { X = Pos.Percent(33) - 7, Y = Pos.Percent(30), }; var exitButton = new Button("Wyjdź [F6] ") { X = Pos.Percent(66) - 5, Y = Pos.Percent(30), }; Add(showCarsButton); Add(rentCarButton); Add(historyButton); Add(accountButton); Add(setingsButton); Add(exitButton); StringBuilder carImage = new StringBuilder(); carImage.AppendLine(@" yNNNNNNNNNNNNNNNNNNNNNNy "); carImage.AppendLine(@" .MM MM. "); carImage.AppendLine(@" :Md dM: "); carImage.AppendLine(@" oMy yMo "); carImage.AppendLine(@" yMdssssssssssssssssssssdMy "); carImage.AppendLine(@"omMNdmMMMMMMMMMMMMMMMMMMmdNMmo"); carImage.AppendLine(@"MMy /MMMMMMMMMMMMMMMM/ yMM"); carImage.AppendLine(@"MMh. `sMMMMMMMMMMMMMMMMs` .hMM"); carImage.AppendLine(@"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"); carImage.AppendLine(@"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"); carImage.AppendLine(@"+mMMMMMMMMMMMMMMMMMMMMMMMMMMm+"); carImage.AppendLine(@" sMMMm mMMMs "); carImage.AppendLine(@" sMMMm mMMMs "); carImage.AppendLine(@" :mMN+ +mNd- "); carImage.AppendLine(""); var imageLabel = new Label(carImage.ToString()) { X = Pos.Percent(38), Y = Pos.Percent(40), }; Add(imageLabel); #endregion #region Logout Button var logoutButton = new Button("Wyloguj [F7] ") { X = Pos.Center() - 7, Y = Pos.Percent(100) - 2, }; Add(logoutButton); #endregion #region bind-button-events exitButton.Clicked += () => { //Close(); OnExit?.Invoke(); }; logoutButton.Clicked += () => { //Close(); OnLogout?.Invoke(); }; showCarsButton.Clicked += () => { //Close(); OnSelect?.Invoke(1); }; rentCarButton.Clicked += () => { //Close(); OnSelect?.Invoke(2); }; historyButton.Clicked += () => { //Close(); OnSelect?.Invoke(3); }; accountButton.Clicked += () => { //Close(); OnSelect?.Invoke(4); }; setingsButton.Clicked += () => { //Close(); OnSelect?.Invoke(5); }; #endregion KeyDown += (a) => { switch (a.KeyEvent.Key) { case Key.F1: OnSelect?.Invoke(1); break; case Key.F2: OnSelect?.Invoke(2); break; case Key.F3: OnSelect?.Invoke(3); break; case Key.F4: OnSelect?.Invoke(4); break; case Key.F5: OnSelect?.Invoke(5); break; case Key.F6: OnExit?.Invoke(); break; case Key.F7: OnLogout?.Invoke(); break; default: break; } }; }
private static void SetupItemSetBlock() { var itemsetView = new FrameView("Itemset") { X = Pos.Percent(50), Y = Pos.Bottom(ItemDetailsView), // Leave place for top level menu and Summoner search // By using Dim.Fill(), it will automatically resize without manual intervention Width = Dim.Fill(), Height = Dim.Fill() }; ItemSetView = itemsetView; NStack.ustring[] blocks = new NStack.ustring[] { "1 ", "2 ", "3 ", "4 " }; var blockRadio = new RadioGroup(blocks) { X = Pos.Percent(40), Y = Pos.Percent(3), Width = Dim.Fill(), Height = 1 }; blockRadio.DisplayMode = DisplayModeLayout.Horizontal; ItemSetView.Add(blockRadio); var blockFrameView1 = new FrameView("Block1") { X = Pos.Percent(0), Y = Pos.Bottom(blockRadio), Width = Dim.Percent(50), Height = Dim.Percent(45) }; var blockListView1 = new ListView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; Blocks[0] = blockListView1; blockFrameView1.Add(Blocks[0]); var blockFrameView2 = new FrameView("Block2") { X = Pos.Right(blockFrameView1), Y = Pos.Bottom(blockRadio), Width = Dim.Fill(), Height = Dim.Percent(45) }; var blockListView2 = new ListView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; Blocks[1] = blockListView2; blockFrameView2.Add(Blocks[1]); var blockFrameView3 = new FrameView("Block3") { X = Pos.Percent(0), Y = Pos.Bottom(blockFrameView1), Width = Dim.Percent(50), Height = Dim.Fill() - 1 }; var blockListView3 = new ListView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; Blocks[2] = blockListView3; blockFrameView3.Add(Blocks[2]); var blockFrameView4 = new FrameView("Block4") { X = Pos.Right(blockFrameView3), Y = Pos.Bottom(blockFrameView2), Width = Dim.Fill(), Height = Dim.Fill() - 1 }; var blockListView4 = new ListView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; Blocks[3] = blockListView4; blockFrameView4.Add(Blocks[3]); ItemSetView.Add(blockFrameView1); ItemSetView.Add(blockFrameView2); ItemSetView.Add(blockFrameView3); ItemSetView.Add(blockFrameView4); SelectedBlockId = 0; Blocks[0].ColorScheme = Colors.Dialog; blockRadio.SelectedItemChanged += BlockRadio_SelectedItemChanged; Blocks[0].OpenSelectedItem += Block0openSelectedItem; Blocks[1].OpenSelectedItem += Block1openSelectedItem; Blocks[2].OpenSelectedItem += Block2openSelectedItem; Blocks[3].OpenSelectedItem += Block3openSelectedItem; var exportButton = new Button("Export") { X = Pos.Center(), Y = Pos.Bottom(blockFrameView3) }; exportButton.Clicked += ExportButton_Clicked; ItemSetView.Add(exportButton); }
public override void Setup() { var longTime = new TimeField(DateTime.Now.TimeOfDay) { X = Pos.Center(), Y = 2, IsShortFormat = false, ReadOnly = false, }; longTime.TimeChanged += TimeChanged; Win.Add(longTime); var shortTime = new TimeField(DateTime.Now.TimeOfDay) { X = Pos.Center(), Y = Pos.Bottom(longTime) + 1, IsShortFormat = true, ReadOnly = false, }; shortTime.TimeChanged += TimeChanged; Win.Add(shortTime); var shortDate = new DateField(DateTime.Now) { X = Pos.Center(), Y = Pos.Bottom(shortTime) + 1, IsShortFormat = true, ReadOnly = true, }; shortDate.DateChanged += DateChanged; Win.Add(shortDate); var longDate = new DateField(DateTime.Now) { X = Pos.Center(), Y = Pos.Bottom(shortDate) + 1, IsShortFormat = false, ReadOnly = true, }; longDate.DateChanged += DateChanged; Win.Add(longDate); lblOldTime = new Label("Old Time: ") { X = Pos.Center(), Y = Pos.Bottom(longDate) + 1, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblOldTime); lblNewTime = new Label("New Time: ") { X = Pos.Center(), Y = Pos.Bottom(lblOldTime) + 1, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblNewTime); lblTimeFmt = new Label("Time Format: ") { X = Pos.Center(), Y = Pos.Bottom(lblNewTime) + 1, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblTimeFmt); lblOldDate = new Label("Old Date: ") { X = Pos.Center(), Y = Pos.Bottom(lblTimeFmt) + 2, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblOldDate); lblNewDate = new Label("New Date: ") { X = Pos.Center(), Y = Pos.Bottom(lblOldDate) + 1, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblNewDate); lblDateFmt = new Label("Date Format: ") { X = Pos.Center(), Y = Pos.Bottom(lblNewDate) + 1, TextAlignment = TextAlignment.Centered, Width = Dim.Fill(), }; Win.Add(lblDateFmt); var swapButton = new Button("Swap Long/Short & Read/Read Only") { X = Pos.Center(), Y = Pos.Bottom(Win) - 5, }; swapButton.Clicked += () => { longTime.ReadOnly = !longTime.ReadOnly; shortTime.ReadOnly = !shortTime.ReadOnly; longTime.IsShortFormat = !longTime.IsShortFormat; shortTime.IsShortFormat = !shortTime.IsShortFormat; longDate.ReadOnly = !longDate.ReadOnly; shortDate.ReadOnly = !shortDate.ReadOnly; longDate.IsShortFormat = !longDate.IsShortFormat; shortDate.IsShortFormat = !shortDate.IsShortFormat; }; Win.Add(swapButton); }
public DynamicStatusBarSample(ustring title) : base(title) { DataContext = new DynamicStatusItemModel(); var _frmDelimiter = new FrameView("Shortcut Delimiter:") { X = Pos.Center(), Y = 0, Width = 25, Height = 4 }; var _txtDelimiter = new TextField(StatusBar.ShortcutDelimiter.ToString()) { X = Pos.Center(), Width = 2, }; _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text; _frmDelimiter.Add(_txtDelimiter); Add(_frmDelimiter); var _frmStatusBar = new FrameView("Items:") { Y = 5, Width = Dim.Percent(50), Height = Dim.Fill(2) }; var _btnAddStatusBar = new Button("Add a StatusBar") { Y = 1, }; _frmStatusBar.Add(_btnAddStatusBar); var _btnRemoveStatusBar = new Button("Remove a StatusBar") { Y = 1 }; _btnRemoveStatusBar.X = Pos.AnchorEnd() - (Pos.Right(_btnRemoveStatusBar) - Pos.Left(_btnRemoveStatusBar)); _frmStatusBar.Add(_btnRemoveStatusBar); var _btnAdd = new Button(" Add ") { Y = Pos.Top(_btnRemoveStatusBar) + 2, }; _btnAdd.X = Pos.AnchorEnd() - (Pos.Right(_btnAdd) - Pos.Left(_btnAdd)); _frmStatusBar.Add(_btnAdd); _lstItems = new ListView(new List <DynamicStatusItemList> ()) { ColorScheme = Colors.Dialog, Y = Pos.Top(_btnAddStatusBar) + 2, Width = Dim.Fill() - Dim.Width(_btnAdd) - 1, Height = Dim.Fill(), }; _frmStatusBar.Add(_lstItems); var _btnRemove = new Button("Remove") { X = Pos.Left(_btnAdd), Y = Pos.Top(_btnAdd) + 1 }; _frmStatusBar.Add(_btnRemove); var _btnUp = new Button("^") { X = Pos.Right(_lstItems) + 2, Y = Pos.Top(_btnRemove) + 2 }; _frmStatusBar.Add(_btnUp); var _btnDown = new Button("v") { X = Pos.Right(_lstItems) + 2, Y = Pos.Top(_btnUp) + 1 }; _frmStatusBar.Add(_btnDown); Add(_frmStatusBar); var _frmStatusBarDetails = new DynamicStatusBarDetails("StatusBar Item Details:") { X = Pos.Right(_frmStatusBar), Y = Pos.Top(_frmStatusBar), Width = Dim.Fill(), Height = Dim.Fill(4) }; Add(_frmStatusBarDetails); _btnUp.Clicked += () => { var i = _lstItems.SelectedItem; var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; if (statusItem != null) { var items = _statusBar.Items; if (i > 0) { items [i] = items [i - 1]; items [i - 1] = statusItem; DataContext.Items [i] = DataContext.Items [i - 1]; DataContext.Items [i - 1] = new DynamicStatusItemList(statusItem.Title, statusItem); _lstItems.SelectedItem = i - 1; _statusBar.SetNeedsDisplay(); } } }; _btnDown.Clicked += () => { var i = _lstItems.SelectedItem; var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null; if (statusItem != null) { var items = _statusBar.Items; if (i < items.Length - 1) { items [i] = items [i + 1]; items [i + 1] = statusItem; DataContext.Items [i] = DataContext.Items [i + 1]; DataContext.Items [i + 1] = new DynamicStatusItemList(statusItem.Title, statusItem); _lstItems.SelectedItem = i + 1; _statusBar.SetNeedsDisplay(); } } }; var _btnOk = new Button("Ok") { X = Pos.Right(_frmStatusBar) + 20, Y = Pos.Bottom(_frmStatusBarDetails), }; Add(_btnOk); var _btnCancel = new Button("Cancel") { X = Pos.Right(_btnOk) + 3, Y = Pos.Top(_btnOk), }; _btnCancel.Clicked += () => { SetFrameDetails(_currentEditStatusItem); }; Add(_btnCancel); _lstItems.SelectedItemChanged += (e) => { SetFrameDetails(); }; _btnOk.Clicked += () => { if (ustring.IsNullOrEmpty(_frmStatusBarDetails._txtTitle.Text) && _currentEditStatusItem != null) { MessageBox.ErrorQuery("Invalid title", "Must enter a valid title!.", "Ok"); } else if (_currentEditStatusItem != null) { _frmStatusBarDetails._txtTitle.Text = SetTitleText( _frmStatusBarDetails._txtTitle.Text, _frmStatusBarDetails._txtShortcut.Text); var statusItem = new DynamicStatusItem(_frmStatusBarDetails._txtTitle.Text, _frmStatusBarDetails._txtAction.Text, _frmStatusBarDetails._txtShortcut.Text); UpdateStatusItem(_currentEditStatusItem, statusItem, _lstItems.SelectedItem); } }; _btnAdd.Clicked += () => { if (StatusBar == null) { MessageBox.ErrorQuery("StatusBar Bar Error", "Must add a StatusBar first!", "Ok"); _btnAddStatusBar.SetFocus(); return; } var frameDetails = new DynamicStatusBarDetails(); var item = frameDetails.EnterStatusItem(); if (item == null) { return; } StatusItem newStatusItem = CreateNewStatusBar(item); _currentSelectedStatusBar++; _statusBar.AddItemAt(_currentSelectedStatusBar, newStatusItem); DataContext.Items.Add(new DynamicStatusItemList(newStatusItem.Title, newStatusItem)); _lstItems.MoveDown(); }; _btnRemove.Clicked += () => { var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null; if (statusItem != null) { _statusBar.RemoveItem(_currentSelectedStatusBar); DataContext.Items.RemoveAt(_lstItems.SelectedItem); if (_lstItems.Source.Count > 0 && _lstItems.SelectedItem > _lstItems.Source.Count - 1) { _lstItems.SelectedItem = _lstItems.Source.Count - 1; } _lstItems.SetNeedsDisplay(); SetFrameDetails(); } }; _lstItems.Enter += (_) => { var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null; SetFrameDetails(statusItem); }; _btnAddStatusBar.Clicked += () => { if (_statusBar != null) { return; } _statusBar = new StatusBar(); Add(_statusBar); }; _btnRemoveStatusBar.Clicked += () => { if (_statusBar == null) { return; } Remove(_statusBar); _statusBar = null; DataContext.Items = new List <DynamicStatusItemList> (); _currentStatusItem = null; _currentSelectedStatusBar = -1; SetListViewSource(_currentStatusItem, true); SetFrameDetails(null); }; SetFrameDetails(); var ustringConverter = new UStringValueConverter(); var listWrapperConverter = new ListWrapperConverter(); var lstItems = new Binding(this, "Items", _lstItems, "Source", listWrapperConverter); void SetFrameDetails(StatusItem statusItem = null) { StatusItem newStatusItem; if (statusItem == null) { newStatusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null; } else { newStatusItem = statusItem; } _currentEditStatusItem = newStatusItem; _frmStatusBarDetails.EditStatusItem(newStatusItem); var f = _btnOk.Enabled == _frmStatusBarDetails.Enabled; if (!f) { _btnOk.Enabled = _frmStatusBarDetails.Enabled; _btnCancel.Enabled = _frmStatusBarDetails.Enabled; } } void SetListViewSource(StatusItem _currentStatusItem, bool fill = false) { DataContext.Items = new List <DynamicStatusItemList> (); var statusItem = _currentStatusItem; if (!fill) { return; } if (statusItem != null) { foreach (var si in _statusBar.Items) { DataContext.Items.Add(new DynamicStatusItemList(si.Title, si)); } } } StatusItem CreateNewStatusBar(DynamicStatusItem item) { StatusItem newStatusItem; newStatusItem = new StatusItem(ShortcutHelper.GetShortcutFromTag( item.shortcut, StatusBar.ShortcutDelimiter), item.title, _frmStatusBarDetails.CreateAction(item)); return(newStatusItem); } void UpdateStatusItem(StatusItem _currentEditStatusItem, DynamicStatusItem statusItem, int index) { _currentEditStatusItem = CreateNewStatusBar(statusItem); _statusBar.Items [index] = _currentEditStatusItem; if (DataContext.Items.Count == 0) { DataContext.Items.Add(new DynamicStatusItemList(_currentEditStatusItem.Title, _currentEditStatusItem)); } DataContext.Items [index] = new DynamicStatusItemList(_currentEditStatusItem.Title, _currentEditStatusItem); SetFrameDetails(_currentEditStatusItem); } //_frmStatusBarDetails.Initialized += (s, e) => _frmStatusBarDetails.Enabled = false; }