mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update docs, little optimizations, inline style anims
This commit is contained in:
parent
38c117b9d8
commit
337090e74c
@ -138,7 +138,7 @@ Here is full **Druid** components list.
|
|||||||
|
|
||||||
### Extended components
|
### Extended components
|
||||||
|
|
||||||
> Extended components before usage should be registered in **Druid** with `druid.register()` function.
|
> Extended components before usage should be registered in **Druid** with [`druid.register()`](https://insality.github.io/druid/modules/Druid.html#druid.register) function.
|
||||||
> On usage of unregistered **Druid** component the next log will be shown in the console.
|
> On usage of unregistered **Druid** component the next log will be shown in the console.
|
||||||
```
|
```
|
||||||
local data_list = require("druid.extended.data_list")
|
local data_list = require("druid.extended.data_list")
|
||||||
|
@ -126,8 +126,7 @@ function BaseComponent.get_template(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set current component nodes
|
--- Set current component nodes.
|
||||||
--
|
|
||||||
-- Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree.
|
-- Use if your component nodes was cloned with `gui.clone_tree` and you got the node tree.
|
||||||
-- @function component:set_nodes
|
-- @function component:set_nodes
|
||||||
-- @tparam BaseComponent self @{BaseComponent}
|
-- @tparam BaseComponent self @{BaseComponent}
|
||||||
@ -501,10 +500,7 @@ function BaseComponent.get_childrens(self)
|
|||||||
local children = self._meta.children[i]
|
local children = self._meta.children[i]
|
||||||
|
|
||||||
table.insert(childrens, children)
|
table.insert(childrens, children)
|
||||||
local recursive_childrens = children:get_childrens()
|
helper.add_array(childrens, children:get_childrens())
|
||||||
for j = 1, #recursive_childrens do
|
|
||||||
table.insert(childrens, recursive_childrens[j])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return childrens
|
return childrens
|
||||||
|
@ -190,9 +190,7 @@ function M.create(text, settings)
|
|||||||
|
|
||||||
local words = {}
|
local words = {}
|
||||||
for index = 1, #lines do
|
for index = 1, #lines do
|
||||||
for jindex = 1, #lines[index] do
|
helper.add_array(words, lines[index])
|
||||||
table.insert(words, lines[index][jindex])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return words, settings, lines_metrics
|
return words, settings, lines_metrics
|
||||||
|
@ -172,15 +172,11 @@ function M.on_window_callback(event)
|
|||||||
for i = 1, #instances do
|
for i = 1, #instances do
|
||||||
msg.post(instances[i].url, base_component.ON_FOCUS_LOST)
|
msg.post(instances[i].url, base_component.ON_FOCUS_LOST)
|
||||||
end
|
end
|
||||||
end
|
elseif event == window.WINDOW_EVENT_FOCUS_GAINED then
|
||||||
|
|
||||||
if event == window.WINDOW_EVENT_FOCUS_GAINED then
|
|
||||||
for i = 1, #instances do
|
for i = 1, #instances do
|
||||||
msg.post(instances[i].url, base_component.ON_FOCUS_GAINED)
|
msg.post(instances[i].url, base_component.ON_FOCUS_GAINED)
|
||||||
end
|
end
|
||||||
end
|
elseif event == window.WINDOW_EVENT_RESIZED then
|
||||||
|
|
||||||
if event == window.WINDOW_EVENT_RESIZED then
|
|
||||||
for i = 1, #instances do
|
for i = 1, #instances do
|
||||||
msg.post(instances[i].url, base_component.ON_WINDOW_RESIZED)
|
msg.post(instances[i].url, base_component.ON_WINDOW_RESIZED)
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ local component = require("druid.component")
|
|||||||
local LangText = component.create("lang_text")
|
local LangText = component.create("lang_text")
|
||||||
|
|
||||||
|
|
||||||
--- @{LangText} constructor
|
--- The @{LangText} constructor
|
||||||
-- @tparam LangText self @{LangText}
|
-- @tparam LangText self @{LangText}
|
||||||
-- @tparam string|node node Node name or GUI Text Node itself
|
-- @tparam string|node node Node name or GUI Text Node itself
|
||||||
-- @tparam string locale_id Default locale id or text from node as default
|
-- @tparam string locale_id Default locale id or text from node as default
|
||||||
|
@ -251,6 +251,26 @@ function M.deepcopy(orig_table)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Add all elements from source array to the target array
|
||||||
|
-- @function helper.add_array
|
||||||
|
-- @tparam table target Array to put elements from source
|
||||||
|
-- @tparam[opt] table source The source array to get elements from
|
||||||
|
-- @treturn array The target array
|
||||||
|
function M.add_array(target, source)
|
||||||
|
assert(target)
|
||||||
|
|
||||||
|
if not source then
|
||||||
|
return target
|
||||||
|
end
|
||||||
|
|
||||||
|
for index = 1, #source do
|
||||||
|
table.insert(target, source[index])
|
||||||
|
end
|
||||||
|
|
||||||
|
return target
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get node size adjusted by scale
|
--- Get node size adjusted by scale
|
||||||
-- @function helper.get_scaled_size
|
-- @function helper.get_scaled_size
|
||||||
-- @tparam node node GUI node
|
-- @tparam node node GUI node
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
|
||||||
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
|
|
||||||
local function scale_to(self, node, to, callback, time, delay, easing)
|
|
||||||
easing = easing or gui.EASING_INSINE
|
|
||||||
time = time or M.SCALE_ANIMATION_TIME
|
|
||||||
delay = delay or 0
|
|
||||||
time = time or 0.10
|
|
||||||
gui.animate(node, gui.PROP_SCALE, to, easing, time, delay,
|
|
||||||
function()
|
|
||||||
if callback then
|
|
||||||
callback(self, node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function M.back_scale_animation(self, node, target_scale)
|
|
||||||
scale_to(self, node, target_scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function M.tap_scale_animation(self, node, target_scale)
|
|
||||||
scale_to(self, node, target_scale,
|
|
||||||
function()
|
|
||||||
M.back_scale_animation(self, node, self.start_scale)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function M.hover_scale(self, target, time)
|
|
||||||
gui.animate(self.anim_node, "scale", target, gui.EASING_OUTSINE, time)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return M
|
|
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local settings = require("druid.system.settings")
|
local settings = require("druid.system.settings")
|
||||||
local anims = require("druid.styles.default.anims")
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
|
local function button_hover_scale(node, target, time)
|
||||||
|
gui.animate(node, "scale", target, gui.EASING_OUTSINE, time)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function button_tap_anim(node, tap_scale, start_scale)
|
||||||
|
gui.animate(node, gui.PROP_SCALE, tap_scale, gui.EASING_INSINE, 0.1, 0, function()
|
||||||
|
gui.animate(node, gui.PROP_SCALE, start_scale, gui.EASING_INSINE, 0.1)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
M["button"] = {
|
M["button"] = {
|
||||||
HOVER_SCALE = vmath.vector3(0.02, 0.02, 1),
|
HOVER_SCALE = vmath.vector3(0.02, 0.02, 1),
|
||||||
HOVER_MOUSE_SCALE = vmath.vector3(0.01, 0.01, 1),
|
HOVER_MOUSE_SCALE = vmath.vector3(0.01, 0.01, 1),
|
||||||
@ -24,19 +33,19 @@ M["button"] = {
|
|||||||
local scale_to = self.start_scale + M.button.HOVER_SCALE
|
local scale_to = self.start_scale + M.button.HOVER_SCALE
|
||||||
|
|
||||||
local target_scale = state and scale_to or self.start_scale
|
local target_scale = state and scale_to or self.start_scale
|
||||||
anims.hover_scale(self, target_scale, M.button.HOVER_TIME)
|
button_hover_scale(node, target_scale, M.button.HOVER_TIME)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_mouse_hover = function(self, node, state)
|
on_mouse_hover = function(self, node, state)
|
||||||
local scale_to = self.start_scale + M.button.HOVER_MOUSE_SCALE
|
local scale_to = self.start_scale + M.button.HOVER_MOUSE_SCALE
|
||||||
|
|
||||||
local target_scale = state and scale_to or self.start_scale
|
local target_scale = state and scale_to or self.start_scale
|
||||||
anims.hover_scale(self, target_scale, M.button.HOVER_TIME)
|
button_hover_scale(node, target_scale, M.button.HOVER_TIME)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_click = function(self, node)
|
on_click = function(self, node)
|
||||||
local scale_to = self.start_scale + M.button.SCALE_CHANGE
|
local scale_to = self.start_scale + M.button.SCALE_CHANGE
|
||||||
anims.tap_scale_animation(self, node, scale_to)
|
button_tap_anim(node, scale_to, self.start_scale)
|
||||||
settings.play_sound(M.button.BTN_SOUND)
|
settings.play_sound(M.button.BTN_SOUND)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -167,23 +176,7 @@ M["hotkey"] = {
|
|||||||
M["rich_text"] = {
|
M["rich_text"] = {
|
||||||
COLORS = {
|
COLORS = {
|
||||||
white = "#FFFFFF",
|
white = "#FFFFFF",
|
||||||
black = "#000000",
|
black = "#000000"
|
||||||
red = "#FF0000",
|
|
||||||
green = "#00FF00",
|
|
||||||
blue = "#0000FF",
|
|
||||||
yellow = "#FFFF00",
|
|
||||||
magenta = "#FF00FF",
|
|
||||||
cyan = "#00FFFF",
|
|
||||||
gray = "#808080",
|
|
||||||
dark_gray = "#404040",
|
|
||||||
light_gray = "#C0C0C0",
|
|
||||||
orange = "#FFA500",
|
|
||||||
pink = "#FFC0CB",
|
|
||||||
purple = "#800080",
|
|
||||||
brown = "#A52A2A",
|
|
||||||
olive = "#808000",
|
|
||||||
teal = "#008080",
|
|
||||||
navy = "#000080",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ local function set_input_state(self, is_input_inited)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- a and b - two Druid components
|
-- The a and b - two Druid components
|
||||||
-- @local
|
-- @local
|
||||||
local function sort_input_comparator(a, b)
|
local function sort_input_comparator(a, b)
|
||||||
local a_priority = a:get_input_priority()
|
local a_priority = a:get_input_priority()
|
||||||
@ -478,20 +478,19 @@ end
|
|||||||
-- component will be not processed on input step
|
-- component will be not processed on input step
|
||||||
-- @tparam DruidInstance self
|
-- @tparam DruidInstance self
|
||||||
-- @tparam[opt=nil] table|Component whitelist_components The array of component to whitelist
|
-- @tparam[opt=nil] table|Component whitelist_components The array of component to whitelist
|
||||||
|
-- @treturn self @{DruidInstance}
|
||||||
function DruidInstance.set_whitelist(self, whitelist_components)
|
function DruidInstance.set_whitelist(self, whitelist_components)
|
||||||
if whitelist_components and whitelist_components.isInstanceOf then
|
if whitelist_components and whitelist_components.isInstanceOf then
|
||||||
whitelist_components = { whitelist_components }
|
whitelist_components = { whitelist_components }
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #whitelist_components do
|
for i = 1, #whitelist_components do
|
||||||
local component = whitelist_components[i]
|
helper.add_array(whitelist_components, whitelist_components[i]:get_childrens())
|
||||||
local childrens = component:get_childrens()
|
|
||||||
for j = 1, #childrens do
|
|
||||||
table.insert(whitelist_components, childrens[j])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self._input_whitelist = whitelist_components
|
self._input_whitelist = whitelist_components
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -501,20 +500,19 @@ end
|
|||||||
-- component will be not processed on input step
|
-- component will be not processed on input step
|
||||||
-- @tparam DruidInstance self @{DruidInstance}
|
-- @tparam DruidInstance self @{DruidInstance}
|
||||||
-- @tparam[opt=nil] table|Component blacklist_components The array of component to blacklist
|
-- @tparam[opt=nil] table|Component blacklist_components The array of component to blacklist
|
||||||
|
-- @treturn self @{DruidInstance}
|
||||||
function DruidInstance.set_blacklist(self, blacklist_components)
|
function DruidInstance.set_blacklist(self, blacklist_components)
|
||||||
if blacklist_components and blacklist_components.isInstanceOf then
|
if blacklist_components and blacklist_components.isInstanceOf then
|
||||||
blacklist_components = { blacklist_components }
|
blacklist_components = { blacklist_components }
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #blacklist_components do
|
for i = 1, #blacklist_components do
|
||||||
local component = blacklist_components[i]
|
helper.add_array(blacklist_components, blacklist_components[i]:get_childrens())
|
||||||
local childrens = component:get_childrens()
|
|
||||||
for j = 1, #childrens do
|
|
||||||
table.insert(blacklist_components, childrens[j])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self._input_blacklist = blacklist_components
|
self._input_blacklist = blacklist_components
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -800,9 +798,9 @@ end
|
|||||||
-- As a template please check rich_text.gui layout.
|
-- As a template please check rich_text.gui layout.
|
||||||
-- @tparam DruidInstance self
|
-- @tparam DruidInstance self
|
||||||
-- @tparam[opt] string template Template name if used
|
-- @tparam[opt] string template Template name if used
|
||||||
-- @tparam[opt] table<hash, node> nodes Nodes table from gui.clone_tree
|
-- @tparam[opt] table nodes Nodes table from gui.clone_tree
|
||||||
-- @treturn Hotkey @{RichText} component
|
-- @treturn RichText @{RichText} component
|
||||||
function DruidInstance.new_hotkey(self, template, nodes)
|
function DruidInstance.new_rich_text(self, template, nodes)
|
||||||
return helper.require_component_message("rich_text", "custom")
|
return helper.require_component_message("rich_text", "custom")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user