Sunday, May 6, 2018

Re: value function in GSS and math formulas

I can't get my mind around the fact that value function and eval are always runtime substitutions for ImageResource, when it's clearly said in for @eval
  • If the user-defined function can be statically evaluated by the compiler, then the implementation of the specific CssResource should collapse to just a string literal.

One of the major optimizations provided by ClientBundle is an image bundle generation, and it's done at compile time. Also any ClientBundle is a subject of GWT.create(...) call. My point is that there's no runtime information required here. And yet for

@def MY_CONSTANT 5px;

I get only

Java expression :

I'm not sure at which point the call to evalTopPanelButtonAreaMarginTop() is done and why so late. But it precludes from mixing value or eval in GSS formulas. Therefore I have to either rely on CSS3 calc() funcion, or do everything in static methods like evalTopPanelButtonAreaMarginTop().


So the task is still the same: derive an offset, based on the information about image(s) size and other ready-to-use constants when CssResource.ensureInjected() is called. 

Let's say I need to declare a class .inner in my.gss, for which margin-top: property would be equal to (<height of image A> - <height of image B>)/2 + constant. I declare a static method:
public static String evalMarginTop() {
int val = (resource.imageA().getHeight() - resource.imageB().getHeight()) / 2 + css.myConstant();
return val + "px";

Now where do I get resource and css from? Well, I believe I'm forced to statically inject them. I didn't manage to find a better solution for my GIN controlled client lib. These are the miniumum requirements:
@Inject static MyWidgetResources resources;
@Inject static MyWidgetCss css;

@def MY_CONSTANT 5px;
@def MARGIN_TOP eval("lib.MyWidgetImpl.evalMarginTop()");

.inner {
public interface MyWidgetCss extends CssResource, SharedCss {
String DEFAULT_PATH = "lib/my.gss";
int myConstant();
public interface MyWidgetResources extends ClientBundle {
ImageResource imageA();

ImageResource imageB();

@Source({MyWidgetCss.DEFAULT_PATH, SharedCss.DEFAULT_PATH});
MyWidgetCss myWidgetCss();

public interface AppResource extends ClientBundle, MyWidgetResource,...other bundles {
protected void configure() {

public MyWidgetCss getMyWidgetCss(MyWidgetResource resources) {
  return resources.MyWidgetCss();

I don't want to statically inject resources and request static injection for each and every ui class in my application, for which I have a GSS file with runtime evaluation. I want to inject resources in constructor. Why does it have to be so ugly in order to make my GIN controlled client lib work?

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment