PDA

View Full Version : @eval and ensureInjected with Themebuilder



smarttle
5 Mar 2014, 2:07 PM
I'd like to set dynamic values in my theme, for example a backgroundcolor depending on a logged-in user preference. Is it possible to use at runtime:

@eval userBackground com.module.UserPreferences.getUserBackground();
and then

CssResource.ensureInjected()
with the new themebuilder?

jhickman
7 Mar 2014, 10:15 AM
Currently, the theme builder doesn't support custom background images other than gradients set in the configuration file. Recent work has been done on being able to provide a mechanism for custom icons.


If the background image is a "one off," where it's only used for a panel or two, then you may want to consider just using a CSS style when constructing the widget


widget.getElement().getStyle().setBackground(someBackground);


If all instances of a single widget need a background image, then I can think of a couple of methods that could be considered.

Subclass the generated Appearance, add the background image, create a <replace-with> to override the Appearance to use new sub class.
When generating the theme, use the -gen flag to generate the code to a specified directory and update the code directly before jarring up.
I just tried another option, which is fairly straight forward. By creating a CustomStyle CssResource, you can import the appearance style interface and modify. For example:




public interface CustomResources extends ClientBundle {
@Import(Css3FramedPanelStyle.class)
@Source("custom.css")
CustomStyles style();
}


public interface CustomStyles extends CssResource {


}


Then, in your "custom.css" file, you can change the background (I used a color in this case):


.Css3FramedPanelStyle-body {
background-color: green !important;
}



You can then add any custom backgrounds you want.