Skip to content

Cascading Stylesheet Support for Codename One

Notifications You must be signed in to change notification settings

chadelofson/cn1-css

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codename One CSS Support

A library to add support for designing Codename One themes using CSS (Cascading Style Sheets).

#Requirements

  • Your development machine must have Java 8 installed.

Features

  • .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)
  • Automatic image imports as Multi-images.
  • Automatic TTF font imports via the @font-face directive.

Installation

See the Installation Wiki Page

Usage / How it Works

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.

Flowchart

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.

Supported CSS Directives

See the Supported CSS Properties Wiki Page

Supported CSS Selectors

See the Supported Selectors Wiki Page

Image Support

See the Images Wiki Page :

Font Support

See the Fonts Wiki Page

Examples

Building From Source

$ 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.

About

Cascading Stylesheet Support for Codename One

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 91.3%
  • CSS 8.7%