Themes
TextWidget has built-in themes ("light", "dark", "dark_green", "dark_blue") for fast changing the style of the widget. You can further customize a selected theme using theme_restyle or style (higher priority) attributes. Fully custom user themes are also supported.
- <TW_LOG text="Some text" theme="dark" width="300" />
Let's try the "light" theme with customized colors.
- <TW_LOG text="Some text" theme="light" width="300" style="border.color: #DD0000; resizer { color: #DD0000; active_color: #FF0000; } " />
Creating your own themes
You can add your own theme creating a VARIABLE with id "TW_THEMES" before including TextWidget library.
- <!-- create custom themes -->
- <VARIABLE id="TW_THEMES" value="{ your_theme_1 { }, your_theme_2 { } }" / >
- <!-- include textwidget -->
- <INCLUDE_ONCE file="/path/to/tw.inc" />
Here's an example of a "pinky" and "pinky_contrast" themes (the second one inherits another).
- <VARIABLE id="TW_THEMES" value="
- {
- pinky {
- text_color: #02040F;
- bg_color: #E5DADA;
- text_active_color: #FFFFFF;
- border: {
- color: #E59500;
- radius: 5;
- }
- scrollbars: {
- color: #84003277;
- active_color: #840032DD;
- bg_color: #00000011;
- disabled_bg_color: #00000010;
- }
- selection: {
- bg_color: #bad3fcAA;
- inactive_bg_color: #d9d9d9AA;
- }
- resizer: {
- color: #84003277;
- active_color: #840032DD;
- line_width_ratio: 1;
- }
- line_stripe: {
- color: #FFFFFFAA;
- active_color: #840032;
- }
- line_num: {
- color: #00000055;
- bg_color: #DDDDDD66;
- active_color: #FFFFFF;
- active_bg_color: #840032;
- border_color: #002642;
- border_width: 0.5;
- h_align: right;
- h_pad: 6;
- font_face: $DEFAULT_MONOSPACE_FONT$;
- font_size: 11;
- }
- /* optional changes when widget has focus */
- focus {
- text_color: #000000;
- border: {
- color: #840032;
- }
- }
- /* startup values for bbcode tags with same names */
- indent: 0;
- indent_right: 0;
- first_line_indent: 0;
- line_height_ratio: 1.1;
- margin_top: 0;
- margin_bottom: 0;
- group_margin_top: 0;
- group_margin_bottom: 0;
- },
- /* another theme that inherits previous */
- pinky_contrast{
- parent: pinky; /* inherit parent theme */
- text_color: #000000;
- bg_color: #FFFFFF;
- }
- }
- " />
Let's add a widget and take a look:
- <TW_LOG string_id="my_data" theme="pinky" line_numbers="true" line_stripes="true" width="400" resize="both" />
Notes on theming
1. You can use either curly brackets or dots, for example
- border: {
- color: #E59500;
- radius: 5;
- }
is the same:
- border.color: #E59500;
- border.radius: 5;
2. If theme has some parameters missing, it uses "parent" theme (if defined), and finally the built-in "default" theme. (Only single level "parenting" is supported for the moment).
- <!-- a user theme defined in $TW_THEMES$ (see above) -->
- pinky_contrast{
- parent: pinky;
- ...
- }
3. The "focus" prefix can make widget change some parameters when having focus (for editable and/or selectable widgets).
- <TW_LOG ... style="focus { text_color: #000000; border.color: #840032; }" />
4. If you a defining a new element based on TextWidget, you can use "theme_restyle" instead of "style". It will allow you to use "style" later for particular element customization. The "theme_restyle" works the same way as "style", just has lower priority.
5. Themes currently have only the settings that don't affect the layout and can easily change at runtime (for example border_width and corner_resizer_size are not in the theme because they affect how the KUIML-layout is computed, so they are attributes of the widget). Some attributes like font_size and font_face are also currently part of widget attributes due to legacy reasons.
6. The colors in the theme can have "opacity" values as last two chars in hex color: #00000033
7. Theme also has startup values for some bbcode parameters like "margin-top", "first-line-indent". So even if you have bbcode="false" you can still use some features to modify the text formatting.
List of available theme attributes (from the "default" theme)
- text_color: ;
- text_active_color: ;
- bg_color: ;
- text_hover_color: #DD0000;
- border: {
- color: #CCCCCCFF;
- radius: 5;
- stroke_width: ; /* can be in % of border_width */
- }
- scrollbars: {
- color: #00000033;
- active_color: #00000066;
- bg_color: #00000011;
- disabled_bg_color: #00000010;
- }
- selection: {
- bg_color: #bad3fcAA;
- inactive_bg_color: #d9d9d9AA;
- }
- resizer: {
- color: #00000055;
- active_color: #00000099;
- line_width_ratio: 1;
- }
- line_stripe: {
- color: #77889925;
- active_color: #FF993300;
- }
- line_num: {
- color: #00000055;
- bg_color: #DDDDDD66;
- active_color: #00000099;
- active_bg_color: #3399FF22;
- border_color: #AAAAAAFF;
- border_width: 0.5;
- h_align: right;
- h_pad: 6;
- font_face: $DEFAULT_MONOSPACE_FONT$;
- font_size: 11;
- }
- cursor.width_ratio: 1;
- indent: 0;
- indent_right: 0;
- first_line_indent: 0;
- line_height_ratio: 1.1;
- margin_top: 0;
- margin_bottom: 0;
- group_margin_top: 0;
- group_margin_bottom: 0;