<drawable class="mycustomdrawable">
<param name="points">[[1,1],[5,5],[1,5]]</param>
</drawable>
<layout id="MainLayout">
<drawable id="customDrawable" class="CustomDrawable">
<param name="array">[ 1, 2, 3, 4 ]</param>
<param name="matrix">[ [ 1, 2 ], [ 3, 4 ] ]</param>
</drawable>
</layout>
using Toybox.WatchUi;
using Toybox.System;
class CustomDrawable extends WatchUi.Drawable
{
function initialize(params) {
System.println(params[:array]);
System.println(params[:matrix]);
}
}
[1, 2, 3, 4]
[[1, 2], [3, 4]]
you're sure it's passing those as arrays not just as strings?
using Toybox.WatchUi;
using Toybox.System;
class CustomDrawable extends WatchUi.Drawable
{
function initialize(params) {
System.println(params[:array]);
if (params[:array] instanceof Lang.Array) {
System.println("It's an array silly.");
}
else {
System.println("It is not an array! Argh!");
}
System.println(params[:matrix]);
}
}
[1, 2, 3, 4]
It's an array silly.
[[1, 2], [3, 4]]
var options = {
:identity => "customDrawable",
:array => [ 1, 2, 3, 4 ],
:matrix => [ [ 1, 2 ], [ 3, 4 ] ]
}
var drawable = new CustomDrawable(options);
// put drawable into the layout
I don't know how println formats arrays does it include the brackets and commas?
// this is what you want... the key is a symbol
var value = params[:array];
// that is very different from this, which will not work
value = params["array"];