我正在使用 UIBinder 和 MVP 编写 GWT 小部件。小部件的默认样式在TheWidgetView.ui.xml中定义:
<ui:style type="com.widgetlib.spinner.display.TheWidgetView.MyStyle">
.textbox {
border: 1px solid #red;
}
.important {
font-weight: bold;
}
</ui:style>
小部件的 CssResource 接口在TheWidgetView.java中定义:
public class TheWidgetView extends HorizontalPanel implements TheWidgetPresenter.Display {
// ... some code
@UiField MyStyle style;
public interface MyStyle extends CssResource {
String textbox();
String important();
}
// ... more code
}
我希望这个小部件的消费者能够自定义小部件的部分样式并将其包含在他们的MyExample.ui.xml中:
<ui:style type="com.consumer.MyExample.MyStyle">
.textbox {
border: 2px solid #black;
}
</ui:style>
这就是他们的MyExample.java:
public class MyExample extends Composite {
// ... some code
@UiField MyStyle style;
interface MyStyle extends TheWidgetView.MyStyle{
String textbox();
}
// ... more code
}
有没有办法让我的小部件具有默认样式,但小部件的使用者可以覆盖其中一个?当接口扩展 TheWidgetView.MyStyle 时,小部件使用者需要定义该父接口中列出的所有样式。我已经看到一些小部件库有小部件的构造函数以 ClientBundle 作为参数,我想这可以应用于 CssResource。虽然,我不确定如何在 UIBinder 调用的构造函数中传递此样式对象。
提前非常感谢!