public void Focus() { using (var win = new Window()) { var w = CreateWidget(); HBox box = new HBox(); TextEntry e = new TextEntry(); box.PackStart(e); box.PackStart(w); win.Content = box; win.Show(); win.Present(); Application.MainLoop.DispatchPendingEvents(); e.SetFocus(); Application.MainLoop.DispatchPendingEvents(); Assert.IsFalse(w.HasFocus); // Assert.IsTrue (w.CanGetFocus); int gotFocus = 0; w.GotFocus += delegate { gotFocus++; }; w.SetFocus(); if (w.CanGetFocus) { Assert.IsTrue(w.HasFocus); Assert.AreEqual(1, gotFocus); int lostFocus = 0; w.LostFocus += delegate { lostFocus++; }; e.SetFocus(); Assert.IsFalse(w.HasFocus); // Assert.AreEqual (1, lostFocus); } else { Assert.IsFalse(w.HasFocus); Assert.AreEqual(0, gotFocus); } } }
public void Focus() { var win = new Window(); var w = CreateWidget(); Run(delegate { HBox box = new HBox(); TextEntry e = new TextEntry(); box.PackStart(e); box.PackStart(w); win.Content = box; win.Show(); win.Present(); // for (int n=0; n < 500; n++) { Application.DispatchPendingEvents(); // System.Threading.Thread.Sleep (10); // } e.SetFocus(); Application.DispatchPendingEvents(); Assert.IsFalse(w.HasFocus); // Assert.IsTrue (w.CanGetFocus); int gotFocus = 0; w.GotFocus += delegate { gotFocus++; }; w.SetFocus(); Assert.IsTrue(w.HasFocus); Assert.AreEqual(1, gotFocus); int lostFocus = 0; w.LostFocus += delegate { lostFocus++; }; e.SetFocus(); Assert.IsFalse(w.HasFocus); // Assert.AreEqual (1, lostFocus); win.Dispose(); }); }
public void Focus() { using (var win = new Window ()) { var w = CreateWidget (); HBox box = new HBox (); TextEntry e = new TextEntry (); box.PackStart (e); box.PackStart (w); win.Content = box; win.Show (); win.Present (); Application.MainLoop.DispatchPendingEvents (); e.SetFocus (); Application.MainLoop.DispatchPendingEvents (); Assert.IsFalse (w.HasFocus); // Assert.IsTrue (w.CanGetFocus); int gotFocus = 0; w.GotFocus += delegate { gotFocus++; }; w.SetFocus (); if (w.CanGetFocus) { Assert.IsTrue (w.HasFocus); Assert.AreEqual (1, gotFocus); int lostFocus = 0; w.LostFocus += delegate { lostFocus++; }; e.SetFocus (); Assert.IsFalse (w.HasFocus); // Assert.AreEqual (1, lostFocus); } else { Assert.IsFalse (w.HasFocus); Assert.AreEqual (0, gotFocus); } } }
public Login() { var table = new Table (); var image = new ImageView { Image = Icons.UserInfo.WithBoxSize (96), }; userEntry = new TextEntry { PlaceholderText = Catalog.GetString ("User"), }; passwordEntry = new PasswordEntry { PlaceholderText = Catalog.GetString ("Password"), }; var userLabel = new Label { Text = Catalog.GetString ("User"), TextAlignment = Alignment.Center, }; var passwordLabel = new Label { Text = Catalog.GetString ("Password"), TextAlignment = Alignment.Center, }; info = new Label { TextAlignment = Alignment.Center, TextColor = new Color (1, 0, 0), Visible = false, }; userEntry.Activated += delegate { passwordEntry.SetFocus (); }; passwordEntry.Activated += OnAutenticate; table.Add (image, 0, 0, 4); table.Add (userLabel, 1, 0); table.Add (userEntry, 1, 1); table.Add (passwordLabel, 1, 2); table.Add (passwordEntry, 1, 3); table.Add (info, 0, 4, colspan: 2); Content = table; userEntry.SetFocus (); Resizable = false; ShowInTaskbar = false; Title = Catalog.GetString ("Login"); Icon = Image.FromResource (GetType (), Resources.Icon); }
public WidgetFocus () { var text = new TextEntry (); var check = new CheckBox ("CheckBox"); var slider = new HSlider (); ListStore store = new ListStore (value); var list = new ListView (store); list.Columns.Add ("Value", value); list.HeadersVisible = false; for (int n=0; n<10; n++) { var r = store.AddRow (); store.SetValue (r, value, "Value " + n); } var btn1 = new Button ("TextEnty"); var btn2 = new Button ("Checkbox"); var btn3 = new Button ("Slider"); var btn4 = new Button ("ListBox"); var btn5 = new Button ("Button"); btn1.Clicked += (sender, e) => text.SetFocus (); btn2.Clicked += (sender, e) => check.SetFocus (); btn3.Clicked += (sender, e) => slider.SetFocus (); btn4.Clicked += (sender, e) => list.SetFocus (); btn5.Clicked += (sender, e) => btn1.SetFocus (); var btnBox = new HBox (); btnBox.PackStart (btn1); btnBox.PackStart (btn2); btnBox.PackStart (btn3); btnBox.PackStart (btn4); btnBox.PackStart (btn5); var focusBox = new HBox (); var vbox = new VBox (); vbox.PackStart (text); vbox.PackStart (check); vbox.PackStart (slider); focusBox.PackStart (vbox); focusBox.PackStart (list, true); PackStart (btnBox); PackStart (focusBox, true); }
TextEntry BuildRow(Table table, int index, string labelText, string placeholder) { Label label = new Label (labelText); table.Add (label, 0, index); TextEntry entry = new TextEntry { MultiLine = false, PlaceholderText = placeholder }; table.Add (entry, 1, index); label.LinkClicked += (sender, args) => entry.SetFocus (); return entry; }
/// <summary> /// Create list item with specific conditions. /// </summary> public EmailListItem(EmailList parent, Email s, Color bgColor) { // Set height MinHeight = EmailList.ROW_HEIGHT; HeightRequest = EmailList.ROW_HEIGHT; // Set background color BackgroundColor = DefaultColor = bgColor; // Self expand horizontal and vertical ExpandHorizontal = true; ExpandVertical = true; // No margin at all Margin = 0; // Set parent & active email ListParent = parent; ActiveEmail = s; EmailText = new TextEntry() { Text = s.UserEmail, MarginLeft = 5, HorizontalPlacement = WidgetPlacement.Fill, VerticalPlacement = WidgetPlacement.Center, MarginTop = 1, ExpandHorizontal = true, ExpandVertical = false }; EmailText.Changed += delegate { s.UserEmail = EmailText.Text; if (Email.IsValid(EmailText.Text)) { BackgroundColor = DefaultColor; } else { BackgroundColor = Colors.Red; EmailText.SetFocus(); } }; PackStart(EmailText, true, true); // Error Errors = new CheckBox() { State = (s.Errors) ? CheckBoxState.On : CheckBoxState.Off, WidthRequest = EmailList.ERROR_WIDTH, MinWidth = EmailList.ERROR_WIDTH, HorizontalPlacement = WidgetPlacement.Center, VerticalPlacement = WidgetPlacement.Center, MarginLeft = 25 }; Errors.Toggled += delegate { s.Errors = Errors.State == CheckBoxState.On; }; PackStart(Errors); // Notification Notification = new CheckBox() { State = (s.Notifications) ? CheckBoxState.On : CheckBoxState.Off, WidthRequest = EmailList.ERROR_WIDTH, MinWidth = EmailList.ERROR_WIDTH, HorizontalPlacement = WidgetPlacement.Center, VerticalPlacement = WidgetPlacement.Center }; Notification.Toggled += delegate { s.Notifications = Notification.State == CheckBoxState.On; }; PackStart(Notification); // Button RemoveEmail = new Button(Image.FromResource(DirectorImages.CROSS_ICON)) { HorizontalPlacement = WidgetPlacement.Center, VerticalPlacement = WidgetPlacement.Center, MarginRight = 20 }; RemoveEmail.Clicked += delegate { parent.RemoveEmail(ActiveEmail); }; PackStart(RemoveEmail); }
public void Focus () { var win = new Window (); var w = CreateWidget (); Run (delegate { HBox box = new HBox (); TextEntry e = new TextEntry (); box.PackStart (e); box.PackStart (w); win.Content = box; win.Show (); win.Present (); // for (int n=0; n < 500; n++) { Application.DispatchPendingEvents (); // System.Threading.Thread.Sleep (10); // } e.SetFocus (); Application.DispatchPendingEvents (); Assert.IsFalse (w.HasFocus); // Assert.IsTrue (w.CanGetFocus); int gotFocus = 0; w.GotFocus += delegate { gotFocus++; }; w.SetFocus (); Assert.IsTrue (w.HasFocus); Assert.AreEqual (1, gotFocus); int lostFocus = 0; w.LostFocus += delegate { lostFocus++; }; e.SetFocus (); Assert.IsFalse (w.HasFocus); // Assert.AreEqual (1, lostFocus); win.Dispose (); }); }