Update docs, little optimizations, inline style anims

This commit is contained in:
Insality 2023-07-15 12:35:05 +03:00
parent 38c117b9d8
commit 337090e74c
9 changed files with 53 additions and 92 deletions

View File

@ -138,7 +138,7 @@ Here is full **Druid** components list.
### 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.
```
local data_list = require("druid.extended.data_list")

View File

@ -126,8 +126,7 @@ function BaseComponent.get_template(self)
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.
-- @function component:set_nodes
-- @tparam BaseComponent self @{BaseComponent}
@ -501,10 +500,7 @@ function BaseComponent.get_childrens(self)
local children = self._meta.children[i]
table.insert(childrens, children)
local recursive_childrens = children:get_childrens()
for j = 1, #recursive_childrens do
table.insert(childrens, recursive_childrens[j])
end
helper.add_array(childrens, children:get_childrens())
end
return childrens

View File

@ -190,9 +190,7 @@ function M.create(text, settings)
local words = {}
for index = 1, #lines do
for jindex = 1, #lines[index] do
table.insert(words, lines[index][jindex])
end
helper.add_array(words, lines[index])
end
return words, settings, lines_metrics

View File

@ -172,15 +172,11 @@ function M.on_window_callback(event)
for i = 1, #instances do
msg.post(instances[i].url, base_component.ON_FOCUS_LOST)
end
end
if event == window.WINDOW_EVENT_FOCUS_GAINED then
elseif event == window.WINDOW_EVENT_FOCUS_GAINED then
for i = 1, #instances do
msg.post(instances[i].url, base_component.ON_FOCUS_GAINED)
end
end
if event == window.WINDOW_EVENT_RESIZED then
elseif event == window.WINDOW_EVENT_RESIZED then
for i = 1, #instances do
msg.post(instances[i].url, base_component.ON_WINDOW_RESIZED)
end

View File

@ -32,7 +32,7 @@ local component = require("druid.component")
local LangText = component.create("lang_text")
--- @{LangText} constructor
--- The @{LangText} constructor
-- @tparam LangText self @{LangText}
-- @tparam string|node node Node name or GUI Text Node itself
-- @tparam string locale_id Default locale id or text from node as default

View File

@ -251,6 +251,26 @@ function M.deepcopy(orig_table)
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
-- @function helper.get_scaled_size
-- @tparam node node GUI node

View File

@ -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

View File

@ -2,11 +2,20 @@
local const = require("druid.const")
local settings = require("druid.system.settings")
local anims = require("druid.styles.default.anims")
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"] = {
HOVER_SCALE = vmath.vector3(0.02, 0.02, 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 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,
on_mouse_hover = function(self, node, state)
local scale_to = self.start_scale + M.button.HOVER_MOUSE_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,
on_click = function(self, node)
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)
end,
@ -167,23 +176,7 @@ M["hotkey"] = {
M["rich_text"] = {
COLORS = {
white = "#FFFFFF",
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",
black = "#000000"
}
}

View File

@ -115,7 +115,7 @@ local function set_input_state(self, is_input_inited)
end
-- a and b - two Druid components
-- The a and b - two Druid components
-- @local
local function sort_input_comparator(a, b)
local a_priority = a:get_input_priority()
@ -478,20 +478,19 @@ end
-- component will be not processed on input step
-- @tparam DruidInstance self
-- @tparam[opt=nil] table|Component whitelist_components The array of component to whitelist
-- @treturn self @{DruidInstance}
function DruidInstance.set_whitelist(self, whitelist_components)
if whitelist_components and whitelist_components.isInstanceOf then
whitelist_components = { whitelist_components }
end
for i = 1, #whitelist_components do
local component = whitelist_components[i]
local childrens = component:get_childrens()
for j = 1, #childrens do
table.insert(whitelist_components, childrens[j])
end
helper.add_array(whitelist_components, whitelist_components[i]:get_childrens())
end
self._input_whitelist = whitelist_components
return self
end
@ -501,20 +500,19 @@ end
-- component will be not processed on input step
-- @tparam DruidInstance self @{DruidInstance}
-- @tparam[opt=nil] table|Component blacklist_components The array of component to blacklist
-- @treturn self @{DruidInstance}
function DruidInstance.set_blacklist(self, blacklist_components)
if blacklist_components and blacklist_components.isInstanceOf then
blacklist_components = { blacklist_components }
end
for i = 1, #blacklist_components do
local component = blacklist_components[i]
local childrens = component:get_childrens()
for j = 1, #childrens do
table.insert(blacklist_components, childrens[j])
end
helper.add_array(blacklist_components, blacklist_components[i]:get_childrens())
end
self._input_blacklist = blacklist_components
return self
end
@ -800,9 +798,9 @@ end
-- As a template please check rich_text.gui layout.
-- @tparam DruidInstance self
-- @tparam[opt] string template Template name if used
-- @tparam[opt] table<hash, node> nodes Nodes table from gui.clone_tree
-- @treturn Hotkey @{RichText} component
function DruidInstance.new_hotkey(self, template, nodes)
-- @tparam[opt] table nodes Nodes table from gui.clone_tree
-- @treturn RichText @{RichText} component
function DruidInstance.new_rich_text(self, template, nodes)
return helper.require_component_message("rich_text", "custom")
end