BoxViewClock Forms sample working in wasm

This commit is contained in:
Frank A. Krueger 2018-03-09 23:12:07 -08:00
parent 0f085717ad
commit 78528a0c87
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
5 changed files with 49 additions and 30 deletions

View File

@ -13,7 +13,7 @@ Expand that into this directory.
## Build
```bash
csc /nostdlib /target:library /r:managed/mscorlib.dll /r:managed/System.Runtime.dll /r:managed/Ooui.dll /out:managed/Ooui.Sample.dll ooui-sample.cs
csc /nostdlib /target:library /r:managed/mscorlib.dll /r:managed/System.Runtime.dll /r:managed/Xamarin.Forms.Core.dll /r:managed/Ooui.dll /r:managed/Ooui.Forms.dll /out:managed/Ooui.Sample.dll ../Samples/ISample.cs ../Samples/BoxViewClockSample.cs ooui-sample.cs
```

View File

@ -3,18 +3,30 @@ using Ooui;
public class Program
{
static Element GetButtonElement ()
{
var l = new Label { Text = "Hello" };
var b = new Button ("Click Me");
var e = new Div (new Div (l), b);
int count = 0;
b.Click += (s, ee) => {
count++;
b.Text = $"Clicked {count} times";
};
return e;
}
static Element GetBoxViewClockElement ()
{
var s = new Samples.BoxViewClockSample ();
return s.CreateElement ();
}
public static string Main (string a0, string a1)
{
Xamarin.Forms.Forms.Init ();
try {
var l = new Label { Text = "Hello" };
var b = new Button ("Click Me");
var e = new Div (new Div (l), b);
int count = 0;
b.Click += (s, ee) => {
count++;
b.Text = $"Clicked {count} times";
};
var e = GetBoxViewClockElement ();
UI.SetGlobalElement ("main", e);
return e.ToString ();
}

View File

@ -37,6 +37,7 @@
"System.Threading.Tasks.dll",
"System.Reflection.dll",
"System.Reflection.Extensions.dll",
"System.Resources.ResourceManager.dll",
"System.Runtime.dll",
"System.Runtime.Extensions.dll",
"System.Runtime.Serialization.dll",
@ -48,6 +49,7 @@
"Xamarin.Forms.Platform.dll",
"Xamarin.Forms.Xaml.dll",
"Ooui.dll",
"Ooui.Forms.dll",
mainAsmName + ".dll"
];
oouiWasm (mainAsmName, "", "Program", "Main", assemblies);

View File

@ -44,7 +44,7 @@ namespace Ooui
}
}
void QueueMessageLocked (Message message)
protected void QueueMessageLocked (Message message)
{
//
// Make sure all the referenced objects have been created

View File

@ -18,38 +18,43 @@ namespace Ooui
protected override void QueueMessage (Message message)
{
base.QueueMessage (message);
TransmitQueuedMessages ();
}
void TransmitQueuedMessages ()
{
//
// Dequeue as many messages as we can
//
var messagesToSend = new List<Message> ();
lock (queuedMessages) {
messagesToSend.AddRange (queuedMessages);
QueueMessageLocked (message);
var max = 1;
var i = 0;
while (i < queuedMessages.Count) {
TransmitQueuedMessagesLocked (queuedMessages, i, max);
i += max;
}
// WebAssembly.Runtime.InvokeJS("console.log('TRANSMITTED'," + queuedMessages.Count + ")");
queuedMessages.Clear ();
}
}
void TransmitQueuedMessagesLocked (List<Message> messagesToSend, int startIndex, int max)
{
if (messagesToSend.Count == 0)
return;
//
// Now actually send the messages
//
var sb = new StringBuilder ();
var sb = new System.IO.StringWriter ();
sb.Write ("__oouiReceiveMessages(\"");
sb.Write (id);
sb.Write ("\",");
sb.Write ("[");
var head = "";
sb.Append ("[");
foreach (var m in messagesToSend) {
sb.Append (head);
sb.Append (m.ToJson ());
int n = 0;
for (var i = startIndex; i < messagesToSend.Count && n < max; i++, n++) {
sb.Write (head);
messagesToSend[i].WriteJson (sb);
head = ",";
}
sb.Append ("]");
var json = sb.ToString ();
WebAssembly.Runtime.InvokeJS ("__oouiReceiveMessages(\"" + id + "\", " + json + ")");
sb.Write ("])");
var jsonp = sb.ToString ();
// WebAssembly.Runtime.InvokeJS("console.log('TRANSMIT',"+n+")");
WebAssembly.Runtime.InvokeJS (jsonp);
}
public void ReceiveMessageJson (string json)