From 8a27f336bd4ea27f24d8800a46c1aaa0fe5d5dd8 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 10 Dec 2017 15:07:33 -0800 Subject: [PATCH] Rename events to be DOM names (fix #41) --- Ooui.Forms/DisplayAlert.cs | 16 ++++++++-------- Ooui.Forms/Renderers/ButtonRenderer.cs | 4 ++-- Ooui.Forms/Renderers/DatePickerRenderer.cs | 8 ++++---- Ooui.Forms/Renderers/EditorRenderer.cs | 8 ++++---- Ooui.Forms/Renderers/EntryRenderer.cs | 12 ++++++------ Ooui.Forms/Renderers/SwitchRenderer.cs | 4 ++-- Ooui/Element.cs | 14 +++++++------- Ooui/Form.cs | 2 +- Ooui/Input.cs | 9 ++------- Ooui/Select.cs | 6 +++--- Ooui/TextArea.cs | 6 +++--- Ooui/TextInput.cs | 17 +++++++++++++++++ .../Controllers/SamplesController.cs | 2 +- README.md | 4 ++-- Samples/ButtonSample.cs | 2 +- Samples/DrawSample.cs | 4 ++-- Samples/TodoSample.cs | 8 ++++---- Tests/ButtonTests.cs | 2 +- Tests/NodeTests.cs | 2 +- 19 files changed, 71 insertions(+), 59 deletions(-) create mode 100644 Ooui/TextInput.cs diff --git a/Ooui.Forms/DisplayAlert.cs b/Ooui.Forms/DisplayAlert.cs index d5f22f5..fae811a 100644 --- a/Ooui.Forms/DisplayAlert.cs +++ b/Ooui.Forms/DisplayAlert.cs @@ -59,7 +59,7 @@ namespace Ooui.Forms { ClassName = "btn btn-default" }; - _cancelButton.Clicked += (s, e) => SetResult(false); + _cancelButton.Click += (s, e) => SetResult(false); footer.AppendChild(_cancelButton); @@ -70,7 +70,7 @@ namespace Ooui.Forms ClassName = "btn btn-default" }; - _acceptButton.Clicked += (s, e) => SetResult(true); + _acceptButton.Click += (s, e) => SetResult(true); footer.AppendChild(_acceptButton); } @@ -90,23 +90,23 @@ namespace Ooui.Forms { add { - _closeButton.Clicked += value; + _closeButton.Click += value; if(_cancelButton != null) - _cancelButton.Clicked += value; + _cancelButton.Click += value; if(_acceptButton != null) - _acceptButton.Clicked += value; + _acceptButton.Click += value; } remove { - _closeButton.Clicked -= value; + _closeButton.Click -= value; if (_cancelButton != null) - _cancelButton.Clicked -= value; + _cancelButton.Click -= value; if (_acceptButton != null) - _acceptButton.Clicked -= value; + _acceptButton.Click -= value; } } public Element Element { get; private set; } diff --git a/Ooui.Forms/Renderers/ButtonRenderer.cs b/Ooui.Forms/Renderers/ButtonRenderer.cs index 727d835..04f30b2 100644 --- a/Ooui.Forms/Renderers/ButtonRenderer.cs +++ b/Ooui.Forms/Renderers/ButtonRenderer.cs @@ -22,7 +22,7 @@ namespace Ooui.Forms.Renderers protected override void Dispose (bool disposing) { if (Control != null) { - Control.Clicked -= OnButtonTouchUpInside; + Control.Click -= OnButtonTouchUpInside; } base.Dispose (disposing); @@ -44,7 +44,7 @@ namespace Ooui.Forms.Renderers _buttonTextColorDefaultHighlighted = Ooui.Colors.Black; _buttonTextColorDefaultDisabled = Ooui.Colors.Black; - Control.Clicked += OnButtonTouchUpInside; + Control.Click += OnButtonTouchUpInside; } UpdateText (); diff --git a/Ooui.Forms/Renderers/DatePickerRenderer.cs b/Ooui.Forms/Renderers/DatePickerRenderer.cs index 79bb422..3df8d05 100644 --- a/Ooui.Forms/Renderers/DatePickerRenderer.cs +++ b/Ooui.Forms/Renderers/DatePickerRenderer.cs @@ -31,8 +31,8 @@ namespace Ooui.Forms.Renderers Type = InputType.Date, }; - entry.Inputted += OnStarted; - entry.Changed += OnEnded; + //entry.Input += OnStarted; + entry.Change += OnEnded; SetNativeControl (entry); } @@ -100,8 +100,8 @@ namespace Ooui.Forms.Renderers if (disposing) { if (Control != null) { - Control.Inputted -= OnStarted; - Control.Changed -= OnEnded; + //Control.Input -= OnStarted; + Control.Change -= OnEnded; } } diff --git a/Ooui.Forms/Renderers/EditorRenderer.cs b/Ooui.Forms/Renderers/EditorRenderer.cs index 828287c..84a8f60 100644 --- a/Ooui.Forms/Renderers/EditorRenderer.cs +++ b/Ooui.Forms/Renderers/EditorRenderer.cs @@ -25,9 +25,9 @@ namespace Ooui.Forms.Renderers if (disposing) { if (Control != null) { - Control.Inputted -= HandleChanged; + Control.Input -= HandleChanged; //Control.Started -= OnStarted; - Control.Changed -= OnEnded; + Control.Change -= OnEnded; } } @@ -46,9 +46,9 @@ namespace Ooui.Forms.Renderers ClassName = "form-control" }); - Control.Inputted += HandleChanged; + Control.Input += HandleChanged; //Control.Started += OnStarted; - Control.Changed += OnEnded; + Control.Change += OnEnded; } UpdateText (); diff --git a/Ooui.Forms/Renderers/EntryRenderer.cs b/Ooui.Forms/Renderers/EntryRenderer.cs index b4e5dfd..63a8750 100644 --- a/Ooui.Forms/Renderers/EntryRenderer.cs +++ b/Ooui.Forms/Renderers/EntryRenderer.cs @@ -6,7 +6,7 @@ using Xamarin.Forms; namespace Ooui.Forms.Renderers { - public class EntryRenderer : ViewRenderer + public class EntryRenderer : ViewRenderer { Ooui.Color _defaultTextColor; bool _disposed; @@ -32,8 +32,8 @@ namespace Ooui.Forms.Renderers if (disposing) { if (Control != null) { //Control.Inputted -= OnEditingBegan; - Control.Inputted -= OnEditingChanged; - Control.Changed -= OnEditingEnded; + Control.Input -= OnEditingChanged; + Control.Change -= OnEditingEnded; } } @@ -48,7 +48,7 @@ namespace Ooui.Forms.Renderers return; if (Control == null) { - var textField = new Ooui.Input (InputType.Text); + var textField = new Ooui.TextInput (); SetNativeControl (textField); Debug.Assert (Control != null, "Control != null"); @@ -57,10 +57,10 @@ namespace Ooui.Forms.Renderers _defaultTextColor = Colors.Black; - textField.Inputted += OnEditingChanged; + textField.Input += OnEditingChanged; //textField.EditingDidBegin += OnEditingBegan; - textField.Changed += OnEditingEnded; + textField.Change += OnEditingEnded; } UpdatePlaceholder (); diff --git a/Ooui.Forms/Renderers/SwitchRenderer.cs b/Ooui.Forms/Renderers/SwitchRenderer.cs index 75f1a7f..737eb50 100644 --- a/Ooui.Forms/Renderers/SwitchRenderer.cs +++ b/Ooui.Forms/Renderers/SwitchRenderer.cs @@ -14,7 +14,7 @@ namespace Ooui.Forms.Renderers protected override void Dispose (bool disposing) { if (disposing) - Control.Changed -= OnControlValueChanged; + Control.Change -= OnControlValueChanged; base.Dispose (disposing); } @@ -30,7 +30,7 @@ namespace Ooui.Forms.Renderers input.SetAttribute ("data-toggle", "toggle"); SetNativeControl (input); input.Call ("$.bootstrapToggle"); - Control.Changed += OnControlValueChanged; + Control.Change += OnControlValueChanged; } Control.IsChecked = Element.IsToggled; diff --git a/Ooui/Element.cs b/Ooui/Element.cs index ea87569..bc08de7 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -25,12 +25,12 @@ namespace Ooui set => SetProperty (ref hidden, value, "hidden"); } - public event TargetEventHandler Clicked { + public event TargetEventHandler Click { add => AddEventListener ("click", value); remove => RemoveEventListener ("click", value); } - public event TargetEventHandler DoubleClicked { + public event TargetEventHandler DoubleClick { add => AddEventListener ("dblclick", value); remove => RemoveEventListener ("dblclick", value); } @@ -40,7 +40,7 @@ namespace Ooui remove => RemoveEventListener ("keydown", value); } - public event TargetEventHandler KeyPressed { + public event TargetEventHandler KeyPress { add => AddEventListener ("keypress", value); remove => RemoveEventListener ("keypress", value); } @@ -55,17 +55,17 @@ namespace Ooui remove => RemoveEventListener ("mousedown", value); } - public event TargetEventHandler MouseEntered { + public event TargetEventHandler MouseEnter { add => AddEventListener ("mouseenter", value); remove => RemoveEventListener ("mouseenter", value); } - public event TargetEventHandler MouseLeft { + public event TargetEventHandler MouseLeave { add => AddEventListener ("mouseleave", value); remove => RemoveEventListener ("mouseleave", value); } - public event TargetEventHandler MouseMoved { + public event TargetEventHandler MouseMove { add => AddEventListener ("mousemove", value); remove => RemoveEventListener ("mousemove", value); } @@ -85,7 +85,7 @@ namespace Ooui remove => RemoveEventListener ("mouseup", value); } - public event TargetEventHandler Wheeled { + public event TargetEventHandler Wheel { add => AddEventListener ("wheel", value); remove => RemoveEventListener ("wheel", value); } diff --git a/Ooui/Form.cs b/Ooui/Form.cs index e23e22a..809397a 100644 --- a/Ooui/Form.cs +++ b/Ooui/Form.cs @@ -22,7 +22,7 @@ namespace Ooui set => SetProperty (ref enctype, value ?? "", "enctype"); } - public event TargetEventHandler Submitted { + public event TargetEventHandler Submit { add => AddEventListener ("submit", value); remove => RemoveEventListener ("submit", value); } diff --git a/Ooui/Input.cs b/Ooui/Input.cs index 1ceaa9d..90f73d8 100644 --- a/Ooui/Input.cs +++ b/Ooui/Input.cs @@ -30,16 +30,11 @@ namespace Ooui } } - public event TargetEventHandler Changed { + public event TargetEventHandler Change { add => AddEventListener ("change", value); remove => RemoveEventListener ("change", value); } - public event TargetEventHandler Inputted { - add => AddEventListener ("input", value); - remove => RemoveEventListener ("input", value); - } - string placeholder = ""; public string Placeholder { get => placeholder; @@ -77,7 +72,7 @@ namespace Ooui : base ("input") { // Subscribe to the change event so we always get up-to-date values - Changed += (s, e) => {}; + Change += (s, e) => {}; } public Input (InputType type) diff --git a/Ooui/Select.cs b/Ooui/Select.cs index 30a7b64..c88eed4 100644 --- a/Ooui/Select.cs +++ b/Ooui/Select.cs @@ -10,12 +10,12 @@ namespace Ooui set => SetProperty (ref val, value ?? "", "value"); } - public event TargetEventHandler Changed { + public event TargetEventHandler Change { add => AddEventListener ("change", value); remove => RemoveEventListener ("change", value); } - public event TargetEventHandler Inputted { + public event TargetEventHandler Input { add => AddEventListener ("input", value); remove => RemoveEventListener ("input", value); } @@ -24,7 +24,7 @@ namespace Ooui : base ("select") { // Subscribe to the change event so we always get up-to-date values - Changed += (s, e) => { }; + Change += (s, e) => { }; } public void AddOption (string label, string value) diff --git a/Ooui/TextArea.cs b/Ooui/TextArea.cs index 76b3a1d..a35b962 100644 --- a/Ooui/TextArea.cs +++ b/Ooui/TextArea.cs @@ -4,12 +4,12 @@ namespace Ooui { public class TextArea : FormControl { - public event TargetEventHandler Changed { + public event TargetEventHandler Change { add => AddEventListener ("change", value); remove => RemoveEventListener ("change", value); } - public event TargetEventHandler Inputted { + public event TargetEventHandler Input { add => AddEventListener ("input", value); remove => RemoveEventListener ("input", value); } @@ -36,7 +36,7 @@ namespace Ooui : base ("textarea") { // Subscribe to the change event so we always get up-to-date values - Changed += (s, e) => {}; + Change += (s, e) => {}; } public TextArea (string text) diff --git a/Ooui/TextInput.cs b/Ooui/TextInput.cs new file mode 100644 index 0000000..a8fd587 --- /dev/null +++ b/Ooui/TextInput.cs @@ -0,0 +1,17 @@ +using System; + +namespace Ooui +{ + public class TextInput : Input + { + public event TargetEventHandler Input { + add => AddEventListener ("input", value); + remove => RemoveEventListener ("input", value); + } + + public TextInput () + : base (InputType.Text) + { + } + } +} diff --git a/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs b/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs index cf4aa7a..fa0d1a3 100644 --- a/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs +++ b/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs @@ -21,7 +21,7 @@ namespace AspNetCoreMvc.Controllers var head = new Heading { Text = "Click away!" }; var label = new Label { Text = "0" }; var btn = new Button { Text = "Increase" }; - btn.Clicked += (sender, e) => { + btn.Click += (sender, e) => { count++; label.Text = count.ToString (); }; diff --git a/README.md b/README.md index 8c5d907..7dbe022 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ class Program // Add some logic to it var count = 0; - button.Clicked += (s, e) => { + button.Click += (s, e) => { count++; button.Text = $"Clicked {count} times"; }; @@ -81,7 +81,7 @@ Button MakeButton() { var button = new Button("Click me!"); var count = 0; - button.Clicked += (s, e) => { + button.Click += (s, e) => { count++; button.Text = $"Clicked {count} times"; }; diff --git a/Samples/ButtonSample.cs b/Samples/ButtonSample.cs index 7d8a08f..44d99d2 100644 --- a/Samples/ButtonSample.cs +++ b/Samples/ButtonSample.cs @@ -14,7 +14,7 @@ namespace Samples }; button.Style.MarginTop = "2em"; var count = 0; - button.Clicked += (s, e) => { + button.Click += (s, e) => { count++; button.Text = $"Clicked {count} times"; }; diff --git a/Samples/DrawSample.cs b/Samples/DrawSample.cs index 2fe12b9..3b333de 100644 --- a/Samples/DrawSample.cs +++ b/Samples/DrawSample.cs @@ -27,7 +27,7 @@ namespace Samples }; var context = canvas.GetContext2D (); - canvas.Clicked += (s, e) => { + canvas.Click += (s, e) => { var radius = 10; context.BeginPath (); if (toolSel.Value == "box") { @@ -47,7 +47,7 @@ namespace Samples Type = ButtonType.Submit, ClassName = "btn btn-danger", }; - clearbtn.Clicked += (s, e) => { + clearbtn.Click += (s, e) => { context.ClearRect (0, 0, canvas.Width, canvas.Height); }; clearbtn.Style.Display = "block"; diff --git a/Samples/TodoSample.cs b/Samples/TodoSample.cs index 839c8ab..6cf0e9c 100644 --- a/Samples/TodoSample.cs +++ b/Samples/TodoSample.cs @@ -66,19 +66,19 @@ namespace Samples if (string.IsNullOrWhiteSpace (input.Value)) return; var item = new Item (input.Value); - item.Clicked += (s, e) => { + item.Click += (s, e) => { item.IsDone = !item.IsDone; }; items.InsertBefore (item, items.FirstChild); input.Value = ""; } - addbtn.Clicked += (s, e) => { + addbtn.Click += (s, e) => { AddItem (); }; - inputForm.Submitted += (s, e) => { + inputForm.Submit += (s, e) => { AddItem (); }; - clearbtn.Clicked += (s, e) => { + clearbtn.Click += (s, e) => { var toremove = new List (); foreach (Item i in items.Children) { if (i.IsDone) toremove.Add (i); diff --git a/Tests/ButtonTests.cs b/Tests/ButtonTests.cs index e0e3eed..7d18e22 100644 --- a/Tests/ButtonTests.cs +++ b/Tests/ButtonTests.cs @@ -42,7 +42,7 @@ namespace Tests listened = listened || (m.MessageType == MessageType.Listen); }; Assert.IsFalse (listened); - b.Clicked += (s, e) => { + b.Click += (s, e) => { clicked = true; }; Assert.IsTrue (listened); diff --git a/Tests/NodeTests.cs b/Tests/NodeTests.cs index 24eb223..20a480a 100644 --- a/Tests/NodeTests.cs +++ b/Tests/NodeTests.cs @@ -52,7 +52,7 @@ namespace Tests var b = new Button (); p.AppendChild (b); var clicked = false; - b.Clicked += (s, e) => { + b.Click += (s, e) => { clicked = true; }; p.Receive (Message.Event (b.Id, "click"));