You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

themes-overview.asciidoc 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ---
  2. title: Overview
  3. order: 1
  4. layout: page
  5. ---
  6. [[themes.overview]]
  7. = Overview
  8. Vaadin separates the appearance of the user interface from its logic using
  9. __themes__. Themes can include Sass or CSS style sheets, custom HTML layouts,
  10. and any necessary graphics. Theme resources can also be accessed from
  11. application code as [classname]#ThemeResource# objects.
  12. Custom themes are placed under the [filename]#VAADIN/themes/# folder of the web
  13. application (under [filename]#WebContent# in Eclipse or
  14. [filename]#src/main/webapp# in Maven projects). This location is fixed -- the
  15. [filename]#VAADIN# folder contains static resources that are served by the
  16. Vaadin servlet. The servlet augments the files stored in the folder by resources
  17. found from corresponding [filename]#VAADIN# folders contained in JARs in the
  18. class path. For example, the built-in themes are stored in the
  19. [filename]#vaadin-themes.jar#.
  20. <<figure.themes.theme-contents>> illustrates the contents of a theme.
  21. [[figure.themes.theme-contents]]
  22. .Contents of a Theme
  23. image::img/theme-contents-hi.png[]
  24. The name of a theme folder defines the name of the theme. The name is used in
  25. the [literal]#++@Theme++# annotation that sets the theme. A theme must contain
  26. either a [filename]#styles.scss# for Sass themes, or [filename]#styles.css#
  27. stylesheet for plain CSS themes, but other contents have free naming. We
  28. recommend that you have the actual theme content in a SCSS file named after the
  29. theme, such as [filename]#mytheme.scss#, to make the names more unique.
  30. We also suggest a convention for naming the folders as [filename]#img# for
  31. images, [filename]#layouts# for custom layouts, and [filename]#css# for
  32. additional stylesheets.
  33. Custom themes need to extend a base theme, as described in
  34. <<dummy/../../../framework/themes/themes-creating#themes.creating,"Creating and
  35. Using Themes">>. Copying and modifying an existing theme is also possible, but
  36. it is not recommended, as it may need more work to maintain if the modifications
  37. are small.
  38. You use a theme by specifying it with the [literal]#++@Theme++# annotation for
  39. the UI class of the application as follows:
  40. [source, java]
  41. ----
  42. @Theme("mytheme")
  43. public class MyUI extends UI {
  44. @Override
  45. protected void init(VaadinRequest request) {
  46. ...
  47. }
  48. }
  49. ----
  50. A theme can contain alternate styles for user interface components, which can be
  51. changed as needed.
  52. In addition to style sheets, a theme can contain HTML templates for custom
  53. layouts used with [classname]#CustomLayout#. See
  54. <<dummy/../../../framework/layout/layout-customlayout#layout.customlayout,"Custom
  55. Layouts">> for details.
  56. Resources provided in a theme can also be accessed using the
  57. [classname]#ThemeResource# class, as described in
  58. <<dummy/../../../framework/application/application-resources#application.resources.theme,"Theme
  59. Resources">>. This allows displaying theme resources in component icons, in the
  60. [classname]#Image# component, and other such uses.