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 
http://www.gwtproject.org/doc/latest/DevGuideClientBundle.html 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;
@def TOP_PANEL_BUTTON_AREA_MARGIN_TOP eval(
"net.vit.gwt.dev.ui.popuplogger.client.PopupLoggerImpl.evalTopPanelButtonAreaMarginTop()"
);

I get only

Java expression : net.vit.gwt.dev.ui.popuplogger.client.PopupLoggerImpl.
evalTopPanelButtonAreaMarginTop()

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:

*lib.MyWidgetImpl.java:*
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:

*lib.MyWidgetImpl.java:*
@Inject static MyWidgetResources resources;
@Inject static MyWidgetCss css;

*lib/myWidget.gss*:
@def MY_CONSTANT 5px;
@def MARGIN_TOP eval("lib.MyWidgetImpl.evalMarginTop()");

.inner {
  margin-top: MARGIN_TOP;
}

*lib.MyWidgetCss.java:*
@ImportedWithPrefix("myWidget")
public interface MyWidgetCss extends CssResource, SharedCss {
  String DEFAULT_PATH = "lib/my.gss";
  ...
  int myConstant();
}

*lib.MyWidgetResource.java:*
public interface MyWidgetResources extends ClientBundle {
  @Source("lib/imageA.png")
  ImageResource imageA();

  @Source("lib/imageB.png")
  ImageResource imageB();

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

*Application:*

*blah.AppResource.java:*
public interface AppResource extends ClientBundle, MyWidgetResource,...other 
bundles {
  ...
}

*blah.AppModule.java:*
@Override
protected void configure() {
  bind(MyWidgetResource.class).to(AppResource.class).in(Singleton.class);
  requestStaticInjection(MyWidgetImpl.class);
}

@Provides
@Singleton
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to