A library to add support for designing Codename One themes using CSS (Cascading Style Sheets).
#Requirements
- Your development machine must have Java 8 installed.
- .css files compiled to native Codename One .res theme files at compile time.
- Support for all style settings that are supported by the CN1 resource editor:
- Padding
- Margin
- Background
- Colors (foreground, background, transparency)
- Fonts (system and TTF)
- Borders (Standard and 9-piece Image borders)
- Automatic 9-piece border generation where borders and backgrounds cannot be achieved efficiently using standard CN1 styles.
- Rounded borders (via
border-radius
) - Linear Gradients (via
linear-gradient
) - Radial Gradients (via
radial-gradient
) - Opacity
- Box Shadow (via
box-shadow
)
- Rounded borders (via
- Automatic image imports as Multi-images.
- Automatic TTF font imports via the
@font-face
directive.
See the Installation Wiki Page
Once you install the above snippet into your build.xml file, it will activate the CSS compiler to run each time you compile your project. The CSS compiler will look for .css files inside your project's "css" directory (which you'll need to create). It will compiles these CSS files into corresponding .res
files which will be placed into your project's src
directory. You can then load this theme in your app just as you would load any other theme file.
E.g.
Suppose you add a CSS file into your project css/theme.css
. When you compile your project, it will generate the file src/theme.css.res
. Then you can load this file in your app as follows:
Resources css = Resources.openLayered("/theme.css");
UIManager.getInstance().addThemeProps(css.getTheme(css.getThemeResourceNames()[0]));
Alternatively, you can use the "OverlayThemes" theme constant in your project's main theme to have your css theme loaded automatically at runtime. Using this approach has the benefit that the designer previews will reflect the styles in your CSS file.
E.g. You could set the OverlayThemes
constant in your main project theme to "theme.css" to have your theme automatically included in your app.
See the Supported CSS Properties Wiki Page
See the Supported Selectors Wiki Page
- Importing Multiple Images in a Single Selector
- Loading Images Remotely
- Generating 9-Piece Image Borders
- Image Backgrounds
- Image Compression
- Test CSS File is compiled to this Codename One theme file
$ git clone https://github.com/shannah/cn1-css.git
$ cd cn1-css/CN1CSSCompiler
$ ant jar
If all went well, you'll find the generated cn1css-ant-task.jar
inside the cn1-css/CN1CSSCompiler/dist
directory.