From ab546d0e280831f23d559e5b5a7a4999fd3f9f8d Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 26 Nov 2017 09:28:06 -0800 Subject: [PATCH] Add SetAttribute to Element --- .../Renderers/ActivityIndicatorRenderer.cs | 10 ++++++++++ Ooui/Client.js | 16 +++++++++++++++- Ooui/Element.cs | 10 ++++++++++ Ooui/EventTarget.cs | 6 ++++++ Ooui/Message.cs | 2 ++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs diff --git a/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs new file mode 100644 index 0000000..8f7373c --- /dev/null +++ b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs @@ -0,0 +1,10 @@ +using System; +namespace Ooui.Forms.Renderers +{ + public class ActivityIndicatorRenderer + { + public ActivityIndicatorRenderer () + { + } + } +} diff --git a/Ooui/Client.js b/Ooui/Client.js index 108fc35..e796069 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -84,7 +84,7 @@ function ooui (rootElementPath) { if (!resizeTimeout) { resizeTimeout = setTimeout(function() { resizeTimeout = null; - actualResizeHandler(); + resizeHandler(); }, 100); } } @@ -145,6 +145,17 @@ function msgSet (m) { if (debug) console.log ("Set", node, parts, value); } +function msgSetAttr (m) { + const id = m.id; + const node = getNode (id); + if (!node) { + console.error ("Unknown node id", m); + return; + } + node.setAttribute(m.k, m.v); + if (debug) console.log ("SetAttr", node, m.k, m.v); +} + function msgCall (m) { const id = m.id; const node = getNode (id); @@ -203,6 +214,9 @@ function processMessage (m) { case "set": msgSet (m); break; + case "setAttr": + msgSetAttr (m); + break; case "call": msgCall (m); break; diff --git a/Ooui/Element.cs b/Ooui/Element.cs index 8ba85e9..a7287d1 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -102,6 +102,16 @@ namespace Ooui Style.PropertyChanged += HandleStylePropertyChanged; } + public void SetAttribute (string attributeName, string value) + { + Send (new Message { + MessageType = MessageType.SetAttribute, + TargetId = Id, + Key = attributeName, + Value = value, + }); + } + void HandleStylePropertyChanged (object sender, PropertyChangedEventArgs e) { SendSet ("style." + Style.GetJsName (e.PropertyName), Style[e.PropertyName]); diff --git a/Ooui/EventTarget.cs b/Ooui/EventTarget.cs index 2f66139..a7be894 100644 --- a/Ooui/EventTarget.cs +++ b/Ooui/EventTarget.cs @@ -163,6 +163,12 @@ namespace Ooui state.Add (message); }); break; + case MessageType.SetAttribute: + UpdateStateMessages (state => { + state.RemoveAll (x => x.MessageType == MessageType.SetAttribute && x.Key == message.Key); + state.Add (message); + }); + break; case MessageType.Listen: AddStateMessage (message); break; diff --git a/Ooui/Message.cs b/Ooui/Message.cs index ae9ffb1..0498437 100644 --- a/Ooui/Message.cs +++ b/Ooui/Message.cs @@ -46,6 +46,8 @@ namespace Ooui Create, [EnumMember(Value = "set")] Set, + [EnumMember (Value = "setAttr")] + SetAttribute, [EnumMember(Value = "call")] Call, [EnumMember(Value = "listen")]