mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update docs
This commit is contained in:
81
wiki/styles.md
Normal file
81
wiki/styles.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Styles
|
||||
|
||||
## Overview
|
||||
|
||||
Styles - set of functions and parameters for components to customize their behavior.
|
||||
|
||||
Styles is a table, where key is name of component, and value is style table for this component.
|
||||
|
||||
In component API documentation, you can find the style API for this component. Or just lookup for existing styles and modify them.
|
||||
|
||||
## Usage
|
||||
|
||||
Setup default druid style for all druid instances via `druid.set_default_style`
|
||||
You can pass _nil_ or _empty_table_ to use default values for all components (no styles)
|
||||
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
local my_style = require("my.amazing.style")
|
||||
|
||||
function init(self)
|
||||
druid.set_default_style(my_style)
|
||||
end
|
||||
```
|
||||
|
||||
Setup custom style to specific druid instance:
|
||||
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
local my_style = require("my.amazing.style")
|
||||
|
||||
function init(self)
|
||||
-- This druid instance will be use my_style as default
|
||||
self.druid = druid.new(self, my_style)
|
||||
end
|
||||
```
|
||||
|
||||
Change component style with _set_style_ function
|
||||
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
local my_style = require("my.amazing.style")
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
self.button = self.druid:new_button("node", function() end)
|
||||
-- Setup custom style for specific component
|
||||
self.button:set_style(my_style)
|
||||
end
|
||||
```
|
||||
|
||||
## Adjust styles in place
|
||||
|
||||
You can adjust styles params right after the component creation.
|
||||
|
||||
```lua
|
||||
local druid = require("druid.druid")
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
self.grid = self.druid:new_grid("node", "prefab", 1)
|
||||
self.grid.style.IS_ALIGN_LAST_ROW = true
|
||||
|
||||
self.drag = self.druid:new_drag("node")
|
||||
self.drag.style.DRAG_DEADZONE = 0
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
## Create your own styles
|
||||
|
||||
The most components have their styles. You can explore it on [Druid API](https://insality.github.io/druid/) in table style section ([button example](https://insality.github.io/druid/modules/Button.html#style)). Or you can see, what fields component uses in code in function `on_style_change`
|
||||
|
||||
To create you style, create lua module, what return <_component_name_, _component_style_> table
|
||||
|
||||
Example: [default druid style](https://github.com/Insality/druid/blob/master/druid/styles/default/style.lua)
|
||||
|
||||
Override all fields you want and set your style with one of next ways:
|
||||
|
||||
- Set your style as global via `druid.set_default_style`
|
||||
- Set style for concrete druid instance via `druid = druid.new(self, style)`
|
||||
- Set style for concrete instance via `component:set_style(style)`
|
Reference in New Issue
Block a user