Kite 797e00
# Developing Stylesheets
Kite 797e00
Stylesheets are written with [LESS](http://lesscss.org/), which is a dynamic preprocessor stylesheet language that can be compiled into Qt stylesheets.
Kite 797e00

Kite 797e00
ℹ️ [LESS Functions](http://lesscss.org/functions/)
Kite 797e00

Kite 797e00
## Recommended Setup
360dd0

360dd0
### Windows
Kite 797e00
Although any LESS compiler will work fine, here is a recommended setup.
Kite 797e00

Kite 797e00
- Install [Visual Studio Code](https://code.visualstudio.com/) by Microsoft.
Kite 797e00
- Add the [Easy LESS](https://marketplace.visualstudio.com/items?itemName=mrcrowl.easy-less) extension from the marketplace which will be used as the compiler.
Kite 797e00
- In VSCode, navigate to your OpenToonz stuff folder and open `config/qss/Default/less`.
Kite 797e00

Kite 797e00
A `settings.json` file is already included to ensure developers work to the same standards located in `.vscode`. If the file must be created manually then the following should apply.
Kite 797e00

Kite 797e00
``` json
Kite 797e00
  "editor.tabSize": 2,
Kite 797e00
  "less.compile": {
Kite 797e00
  "compress":  true,
Kite 797e00
  "sourceMap": false,
Kite 797e00
  "out":       false
Kite 797e00
}
Kite 797e00
```
360dd0

Kite 797e00
ℹ️ [How to Change Settings in Visual Studio Code](https://code.visualstudio.com/docs/getstarted/settings).
Kite 797e00

360dd0
### Linux
360dd0

360dd0
On Linux you will need a command-line compiler `lessc`.
360dd0

360dd0
Ubuntu:
360dd0

360dd0
    $ apt install node-less
360dd0

360dd0
Fedora:
360dd0

360dd0
    $ dnf install nodejs-less
360dd0

360dd0

360dd0

Kite 797e00
## How To Compile
360dd0

360dd0
### Windows
360dd0

Kite 797e00
Easy LESS uses a compile on save feature, so the theme files must be saved to generate an output.
Kite 797e00

Kite 797e00
```
Kite 797e00
Default.less
Kite 797e00
themes/Blue.less
Kite 797e00
themes/Dark.less
Kite 797e00
themes/Light.less
Kite 797e00
```
Kite 797e00

360dd0
### Linux
360dd0
From opentoonz source directory root execute the following commands:
360dd0
```
360dd0
$ lessc -x stuff/config/qss/Default/less/Default.less stuff/config/qss/Default/Default.qss
360dd0
$ lessc -x stuff/config/qss/Default/less/themes/Blue.less stuff/config/qss/Blue/Blue.qss
360dd0
$ lessc -x stuff/config/qss/Default/less/themes/Dark.less stuff/config/qss/Dark/Dark.qss
360dd0
$ lessc -x stuff/config/qss/Default/less/themes/Light.less stuff/config/qss/Light/Light.qss
360dd0
```
360dd0

Kite 797e00
## How They Work
Kite 797e00
The stylesheets are designed into a component, wire-frame and palette structure similar to web design that exploits the cascade of the LESS language to generate multiple theme colors from a single layout. This method was used to prevent duplication.
Kite 797e00

Kite 797e00
### Cascade Hierarchy 
Kite 797e00
The include pathway is important as `components` need to be included before `layouts`. The cascade order is defined in the `main.less` file.
Kite 797e00

Kite 797e00
``` LESS
Kite 797e00
// Base
Kite 797e00
@import 'base/colors';
Kite 797e00
@import 'base/mixins';
Kite 797e00

Kite 797e00
// Components
Kite 797e00
@import 'components/all';
Kite 797e00

Kite 797e00
// Layouts
Kite 797e00
@import 'layouts/all';
Kite 797e00
```
Kite 797e00

Kite 797e00
Then import the `main.less` file into the theme file which will add values to every variable in `Default.less`.
Kite 797e00

Kite 797e00
## Variable List
Kite 797e00
There are many variables, for a full list look at `Default.less`, below is a list of the core variables.
Kite 797e00

Kite 797e00
`@bg` is the main background color for the interface, almost all other color variables use it as their base color and instead use color functions to either lighten or darken the value.
Kite 797e00

Kite 797e00
`@text-color` is the main text color for the interface.
Kite 797e00

Kite 797e00
`@accent` is used for accenting, such as borders, separators, boxes, wrappers, think of it as secondary.
Kite 797e00

Kite 797e00
`@hl-bg-color` changes the color for highlighted items and focused text fields, think of it as tertiary.
Kite 797e00

Kite 797e00
# Adding New Features
Kite 797e00
This is an example of how to add new features into the layout files.
Kite 797e00

Kite 797e00
``` LESS
Kite 797e00
#NewWindow {
Kite 797e00
  background-color: @bg;
Kite 797e00
  border: 1 solid @accent;
Kite 797e00
  
Kite 797e00
  & QPushButton#OK {
Kite 797e00
    background-color: @button-bg-color;
Kite 797e00
    border-color: @button-border-color;
Kite 797e00
    color: @button-text-color;
Kite 797e00
    padding: 3;
Kite 797e00
    &:hover {
Kite 797e00
      border-color: @hl-bg-color;
Kite 797e00
    }
Kite 797e00
  }
Kite 797e00
}
Kite 797e00
```
Kite 797e00

Kite 797e00
To call components, use the LESS extend function.
Kite 797e00

Kite 797e00
``` LESS
Kite 797e00
#NewWindow {
Kite 797e00
  &:extend(#ComponentName all);
Kite 797e00
}
Kite 797e00
```
Kite 797e00

Kite 797e00
ℹ️ [LESS Extend Docs](http://lesscss.org/features/#extend-feature)
Kite 797e00

Kite 797e00
# Creating New Themes
Kite 797e00
It's possible to create custom themes.
Kite 797e00

Kite 797e00
## How To
Kite 797e00
- Navigate to your OpenToonz stuff directory, and create a new folder in `config/qss`.
Kite 797e00
- Create a new text file in the new folder, give it the same name as the folder and save it with the `.less` extension.
Kite 797e00
- Open the LESS file and add the following line at the top.
Kite 797e00
- `// out: filename.qss`
Kite 797e00
- Which will control where Easy LESS outputs the compiled file on save.
Kite 797e00
- Next, choose which theme you want to base from, in this example the base will be Default.
Kite 797e00
- Add this line under the Easy LESS line but above everything else.
Kite 797e00
- `@import '../Default/less/Default.less'`
Kite 797e00
- Now the theme file is a clone of Default, so variables can be overridden.
Kite 797e00

Kite 797e00
``` LESS
Kite 797e00
//out: filename.qss
Kite 797e00

Kite 797e00
@import '../Default/less/Default.less';
Kite 797e00

Kite 797e00
@bg: red;
Kite 797e00
@text-color: white;
Kite 797e00
@hl-bg-color: yellow;
Kite 797e00

Kite 797e00
// etc
Kite 797e00
```
Kite 797e00

Kite 797e00
# Notes
Kite 797e00
⚠️ When developing, always develop with the Default theme, then decide later if any changes need porting to alternate themes, in most cases it won't be necessary.
Kite 797e00

Kite 797e00
⚠️ Layout files must never have hard-coded color values, color values **must always** be variable. Each function area of OpenToonz is split into a separate file.
Kite 797e00

Kite 797e00
### Directory Information
Kite 797e00
**Base:** Contains generic color palettes, legacy code, mixins and functions. It's fine to place junk code here.
Kite 797e00

Kite 797e00
**Components:** Anything re-usable is here, such as multiple tab structures, button styles, icon layouts, frames, wrappers and folder trees.
Kite 797e00

Kite 797e00
**Layouts:** The core wire-frame, every window, widget and control is designed here.
Kite 797e00

360dd0
**Themes:** Alternate theme colors that inherit the Default theme, it is only necessary to override variable values unique to the theme.