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

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