Hi, I have careted a customer drawable to draw a graph. I am using relative layouts (works well for adapting the layout to many different devices). Here is my layouts file:
<layouts>
<layout id="myWidgetLayout">
<label id="title" x="center" y="15%" font="Graphics.FONT_SMAL" justification="Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER" color="Graphics.COLOR_WHITE" background="Graphics.COLOR_TRANSPARENT" />
<label id="message" x="center" y="30%" font="Graphics.FONT_SMALL" justification="Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER" color="Graphics.COLOR_WHITE" background="Graphics.COLOR_TRANSPARENT" />
<drawable id="graph" class="myGraphArea"></drawable>
</layout>
The custome drawable is defined as so:
class myGraphArea extends WatchUi.Drawable {
private var _locX as Number;
private var _locY as Number;
private var _width as Number;
private var _height as Number;
function initialize(options) {
Drawable.initialize(options);
}
function draw(dc as Dc) as Void {
// clear chart area
dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
dc.fillRectangle(_locX, _locY, _width, _height);
// logic to draw graph here...
}
function setLayout(x, y, width, height) {
_locX = x;
_locY = y;
_height = height;
_width = width;
}
}
Currently, the way I define the location of the graph area is to call the setLayout function from my widget app class. from there I can set relative coordinates using dc.getWidth() and dc.getHeight(), however, it would be cleaner and easier to set all coordinates for all layout elements in one place, from within the layout. I know I can pass options to the custom drawable from the layouts file, but not sure how to pass a "relative coordinate", such as 50% of screen width.
One idea I had was to pass 0.5 in the options array, as so:
<drawable id="graph" class="myGraphArea">
<param name="rel_xLoc">0.5</param>
</drawable>
And then calculate the coordinates in the initialize(options)function in the custom drawable:
function initialize(options) {
_locX = options.get(:rel_xLoc) * dc.getWidth();
}
But from there I don't have access to the dc object so I cannot use dc.getWidth()
I really want to use relative layouts (I know they are memory heavy) but it makes the code a lot easier to work with. I just thought maybe there is some easy and clevel solution that I didn't think of. As always, highly appreciate your help. //Fredrik