I have been thinking about that and I have some ideas. But I would like to 
understand how often that use case actually comes up. I know CSS supports it, 
but in practice (in Pivot specifically) I wonder how important it is?


On Jul 2, 2010, at 7:30 PM, Michael Allman wrote:

> Hi Greg,
> 
> How would one specify multiple named styles for a component element?  Like
> 
> <PushButton styles="redButton bigFont"/>
> 
> Cheers,
> 
> Michael
> 
> On Fri, 2 Jul 2010, Greg Brown wrote:
> 
>> Hi all,
>> 
>> I have been thinking about this and I think I have a fairly elegant solution 
>> that will also significantly extend the capabilities of BXMLSerializer. I am 
>> thinking of extending the <bxml:include> tag to support loading of arbitrary 
>> content. Currently, it only supports includes of other BXML files, but there 
>> is no reason that it couldn't be modified to include other types, such as 
>> JSON, XML, or even images. All we'd have to do is determine an appropriate 
>> serializer to use for the include - this could be inferred based on file 
>> extension or could be specified explicitly via a "mimeType" attribute to the 
>> include tag. The MIME type-to-serializer mappings could be configurable such 
>> that an include could literally be used to load any type of object.
>> 
>> One application of such an extension would be styling. <bxml:include> could 
>> be used to load a "stylesheet" - a JSON file containing a "map of maps". The 
>> format of this file would be identical to the format I had been considering 
>> for the "named styles" approach - each key/value pair in the file would 
>> essentially represent a "style class". For example, the following JSON file 
>> would define a "redButton" class:
>> 
>> {   redButton: {
>>       backgroundColor: "#aa0000",
>>       color: "#ffffff"
>>   }
>> }
>> 
>> In a BXML document, this file could be included as follows:
>> 
>> <bxml:include bxml:id="styles" src="styles.json"/>
>> 
>> The "redButton" style could then be applied to a button as follows:
>> 
>> <PushButton styles="$styles.redButton"/>
>> 
>> Unlike the previous solution I proposed, this approach would require no 
>> changes to the Component or Container classes whatsoever. With the exception 
>> of extending the <bxml:include> tag, it relies entirely on existing 
>> functionality (and existing BXML syntax, so developers will already be 
>> familiar with it).
>> 
>> There are obviously other applications as well. Some simple examples:
>> 
>> <TableView>
>>   <tableData>
>>       <bxml:include src="table_data.json"/>
>>   </tableData>
>> </TableView>
>> 
>> <TreeView>
>>   <treeData>
>>       <bxml:include src="tree_data.xml"/>
>>   </treeData>
>> </TreeView>
>> 
>> One challenge might be how to specify the MIME/serializer mapping for an 
>> include (we won't want BXMLSerializer to include all possible mappings by 
>> default). This could be inherited from the parent serializer, but I think 
>> that a BXML syntax for specifying it in markup is probably a good idea.
>> 
>> Anyway, I think this would be an extremely flexible and useful addition to 
>> the serializer, and I think it also handles the styling case pretty well. 
>> Let me know what you think.
>> 
>> G
>> 
>> 
>> On Jul 2, 2010, at 1:34 PM, Greg Brown wrote:
>> 
>>> FYI, named styles are turning out to be a lot more challenging than I 
>>> expected. The solution I proposed the other day doesn't work - elements in 
>>> BXML aren't added to the parent element until the end tag is processed. So, 
>>> given the following structure:
>>> 
>>> <Window styleClasses="{foo:{...}}">
>>> <BoxPane>
>>>   <PushButton styleClass="foo"/>
>>> </BoxPane>
>>> </Window>
>>> 
>>> when the styleClass attribute of the PushButton is processed, the BoxPane 
>>> hasn't yet been added to the Window, so the "foo" style class name resolves 
>>> to null.  :-(
>>> 
>>> I'll keep thinking about it, though. Suggestions are welcome.
>>> 
>>> Thanks,
>>> G
>>> 
>> 

Reply via email to