Colour Field Items

Tweaking of the object_editor to increase clarity seems to make sense, at least to some of our customers. These are the steps to color the fields dynamically based on their properties.

First override the method editor_field_item.styled_string_data to return style information for the field item. In this example I differentiate between mandatory and readonly, but there are many more properties to choose from.

_method editor_field_item.styled_string_data
    ## Return the text_styles to use for each field type.
    >> _if _self.mandatory?
           >> _self.mandatory_styled_string_data
       _elif _self.readonly?
           >> _self.readonly_styled_string_data
           >> _unset 

The returned style data is a hash_table; keys are the field type (symbol) and values are the textstyles (symbol). An example could be [:alpha_field] « :purple.
The textstyle can be a named color (:purple, :blue) or it can be a predefined textstyle like :disabled, :heading_1 or :error. To list all predefined textstyles use print(string_styles_holder.text_styles).

If you want to use a creative new textstyle you can create your own. You can simple define the textstyle on the string_styles_holder exemplar, because all string_styles_holders inherit the predefined styles from the exemplar. So it you define a new style on the exemplar, the stylesholder of the object_editor will know your new style automatically.
Define the new style like this:

string_styles_holder.add_text_style( :field_readonly, :grey,
                     _false, font.new_with_properties(:type, :logical,
                                      :name, :fancy,
                                      :point_size, 12))

I have attached an example (editor_field_item_extras.magik) that will color the mandatory field in bold purple and the readonly fields in italic grey. The result will look like this:

have fun.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License