On Feb 21, 2006, at 1:58 PM, James Howe wrote:
Ok, I understand that, but it gets a bit confusing when some places you can use color names or strings of the form "#hhhhhh" and other places you can't.  Obviously there is some translation that goes on in the compiler when you specify a value in an attribute (since attributes are always some sort of 'string').  It would be handy to have some sort of globally available function like 'color' where you could send in things like color("red") or color("#FFFFFF") and get a color value back.  Better yet, a set of utility functions which you can use in _javascript_ to convert string values to the correct attribute value.

Anyway, thanks for the help, I figured there some something silly that I was missing.

I ran into this recently.  I was writing a library (to render serialized GraphViz graphs) that was supposed to work in both OpenLaszlo and DHTML.  But the OpenLaszlo <drawview> element only accepts numbers (such as 0xff0000), and the WHATWG 2d context only accepts strings (such as "#ff0000", "#f00", or "red").

I ended up (1) writing a quick-and-dirty CSS parser, and (2) patching <drawview>.  You can get them both from http://osteele.com/sources/_javascript_/drawview-patches.js.  The CSS parser is cssColorToLong.

The rest of the file shows how to patch LzDrawView to accept CSS color strings.  You could use a different (simpler) technique to patch LzView: add the line "c = cssColorToLong(c)" to the beginning of the definition of setColor in WEB-INF/lps/lfc/views/LaszloView.as, and similarly for setBGColor.

Best,
Oliver
_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to