From 35d1ba662bf80cc536042e381a76436402f7fcab Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 18 Jun 2017 22:28:14 -0700 Subject: [PATCH] Add more events to elements Fix #2 --- Ooui/Button.cs | 5 ---- Ooui/Client.js | 2 +- Ooui/Element.cs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ Ooui/Input.cs | 5 ++++ Ooui/TextArea.cs | 5 ++++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/Ooui/Button.cs b/Ooui/Button.cs index 4f52d4b..386fcd9 100644 --- a/Ooui/Button.cs +++ b/Ooui/Button.cs @@ -13,11 +13,6 @@ namespace Ooui set => SetProperty (ref typ, value, "type"); } - public event EventHandler Clicked { - add => AddEventListener ("click", value); - remove => RemoveEventListener ("click", value); - } - public Button () : base ("button") { diff --git a/Ooui/Client.js b/Ooui/Client.js index 3eb82db..8861f16 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -91,7 +91,7 @@ function msgListen (m) { id: m.id, k: m.k, }; - if (m.k === "change") { + if (m.k === "change" || m.k === "input") { em.v = node.value; } const ems = JSON.stringify (em); diff --git a/Ooui/Element.cs b/Ooui/Element.cs index 84252ce..130be71 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -25,6 +25,71 @@ namespace Ooui set => SetProperty (ref hidden, value, "hidden"); } + public event EventHandler Clicked { + add => AddEventListener ("click", value); + remove => RemoveEventListener ("click", value); + } + + public event EventHandler DoubleClicked { + add => AddEventListener ("dblclick", value); + remove => RemoveEventListener ("dblclick", value); + } + + public event EventHandler KeyDown { + add => AddEventListener ("keydown", value); + remove => RemoveEventListener ("keydown", value); + } + + public event EventHandler KeyPressed { + add => AddEventListener ("keypress", value); + remove => RemoveEventListener ("keypress", value); + } + + public event EventHandler KeyUp { + add => AddEventListener ("keyup", value); + remove => RemoveEventListener ("keyup", value); + } + + public event EventHandler MouseDown { + add => AddEventListener ("mousedown", value); + remove => RemoveEventListener ("mousedown", value); + } + + public event EventHandler MouseEntered { + add => AddEventListener ("mouseenter", value); + remove => RemoveEventListener ("mouseenter", value); + } + + public event EventHandler MouseLeft { + add => AddEventListener ("mouseleave", value); + remove => RemoveEventListener ("mouseleave", value); + } + + public event EventHandler MouseMove { + add => AddEventListener ("mousemove", value); + remove => RemoveEventListener ("mousemove", value); + } + + public event EventHandler MouseOut { + add => AddEventListener ("mouseout", value); + remove => RemoveEventListener ("mouseout", value); + } + + public event EventHandler MouseOver { + add => AddEventListener ("mouseover", value); + remove => RemoveEventListener ("mouseover", value); + } + + public event EventHandler MouseUp { + add => AddEventListener ("mouseup", value); + remove => RemoveEventListener ("mouseup", value); + } + + public event EventHandler Wheeled { + add => AddEventListener ("wheel", value); + remove => RemoveEventListener ("wheel", value); + } + protected Element (string tagName) : base (tagName) { diff --git a/Ooui/Input.cs b/Ooui/Input.cs index b6df605..ae4b6ee 100644 --- a/Ooui/Input.cs +++ b/Ooui/Input.cs @@ -32,6 +32,11 @@ namespace Ooui remove => RemoveEventListener ("change", value); } + public event EventHandler Inputted { + add => AddEventListener ("input", value); + remove => RemoveEventListener ("input", value); + } + bool isChecked = false; public bool IsChecked { get => isChecked; diff --git a/Ooui/TextArea.cs b/Ooui/TextArea.cs index 4b4c189..c289162 100644 --- a/Ooui/TextArea.cs +++ b/Ooui/TextArea.cs @@ -9,6 +9,11 @@ namespace Ooui remove => RemoveEventListener ("change", value); } + public event EventHandler Inputted { + add => AddEventListener ("input", value); + remove => RemoveEventListener ("input", value); + } + string val = ""; public string Value { get => val;