On occasions, I utilize the following approach:
@eval BORDER_SIZE_PLUS_2 2+2+"px"; /* GWT will compute this during compilation! */
Interestingly, it only seems to function properly if there are no spaces between the +
operator and the operands. Furthermore, when using @eval, you cannot incorporate constants that were previously defined with @def. Nevertheless, you can make use of constants declared as static fields in one of your Java classes:
@eval BORDER_SIZE_PLUS_2 com.example.MyCssConstants.BORDER_SIZE+2+"px";
Alternatively, you have the option of letting the computation be handled entirely by Java:
@eval WIDTH com.example.MyCssCalculations.width(); /* static method,
no arguments! */
@eval HEIGHT com.example.MyCssCalculations.height();
.style {
width: WIDTH;
height: HEIGHT;
}
However, my preference aligns closely with your idea:
@def BORDER_SIZE 2;
.style {
width: value(BORDER_SIZE + 2, 'px'); /* unfortunately not feasible */
height: value(BORDER_SIZE + 3, 'px');
}
I don't believe this is achievable in GWT 2.0. Perhaps you may discover a more optimal solution - refer to the Developer Guide page related to this subject.