在 GWT 中需要应用程序范围的 CSS 常量
我想在 GWT CssResource 中将一些颜色定义为常量,并在整个应用程序中使用这些常量;但我不知道该怎么做。
我会告诉你我已经尝试过什么。我创建了一个 ClientBundle 和一个 CssResource,如下所示:
public interface Resources extends ClientBundle {
public interface MyStyle extends CssResource {
String JUNGLEGREEN();
String example();
...
}
@Source("Resources.css")
MyStyle css();
}
我定义了一些 Resources.css 中的常量:
@def JUNGLEGREEN #1F3D0A;
在 Resources.css 中,我像这样使用这些常量:
.example { color:JUNGLEGREEN; }
我不知道如何在其他 CSS 文件和 UiBinder 模板中重用这些常量。我想在其他一些 UiBinder 文件中执行此操作,例如 LoginView.ui.xml:
<ui:with field='resources' type='com.example.Resources' />
<ui:style>
.mainPanel {
background:{resources.css.JUNGLEGREEN};
...
}
</ui:style>
...但它似乎无法编译。你知道我怎样才能实现我的目标吗?
I'd like to define some colours as constants in a GWT CssResource, and use those constants throughout my application; but I don't know how to do that.
I'll tell you what what I've tried. I've created a ClientBundle and a CssResource as follows:
public interface Resources extends ClientBundle {
public interface MyStyle extends CssResource {
String JUNGLEGREEN();
String example();
...
}
@Source("Resources.css")
MyStyle css();
}
I've defined some constants in Resources.css:
@def JUNGLEGREEN #1F3D0A;
Within Resources.css, I use those constants like so:
.example { color:JUNGLEGREEN; }
I'm not aware of a way to re-use those constants in other CSS files and UiBinder templates. I'd like to do this in some other UiBinder file, say LoginView.ui.xml:
<ui:with field='resources' type='com.example.Resources' />
<ui:style>
.mainPanel {
background:{resources.css.JUNGLEGREEN};
...
}
</ui:style>
...but it doesn't seem to compile. Do you know how I can achieve my objective?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们是这样做的:
constant.css
文件中,您可以通过以下方式引用这些常量:希望有所帮助。
编辑:
为了避免
元素中的相对路径,您可以执行以下操作:constants.css
)- 使用 @eval 注释来访问常量
我知道如何处理的唯一方法使用常量而不引用 css 文件本身。
This is how we do it:
constant.css
fileHope that helps.
EDIT:
To avoid the relative path in the
<ui:style>
element you could do the following:constants.css
)ClientBundle
andCssResource
to retrieve the defined constants-use the
@eval
annotation to access the constantThe only way I know of how to deal with constants without referencing the css file itself.
我知道这个答案可能有点晚了,但可能会对某人有所帮助。我遇到了同样的问题,并且能够通过添加以下内容来解决它:
Resources.css().ensureInjected()
我在我的工厂中添加了它,但在几个地方尝试了它,无论我把它放在哪里,它都有效。
I know this answer might be kind of late but may help someone. I was having the same problem and was able to solve it by adding the following:
Resources.css().ensureInjected()
I added it in my factory but tried it in a couple of places and no matter where I put it, it worked.
你应该能够使用
You should be able to use