Add first implementation of druid styles (only button)

This commit is contained in:
Insality
2019-12-05 23:40:17 +03:00
parent 89933dfaf5
commit efef4d194d
9 changed files with 120 additions and 107 deletions

View File

@@ -0,0 +1,26 @@
local ui_animate = require("druid.helper.druid_animate")
local M = {}
function M.back_scale_animation(self, node, target_scale)
ui_animate.scale_to(self, node, target_scale)
end
function M.tap_scale_animation(self, node, target_scale)
ui_animate.scale_to(self, node, target_scale,
function()
M.back_scale_animation(self, node, self.scale_from)
end
)
end
function M.hover_scale(self, target, time)
ui_animate.scale(self, self.anim_node, target, time)
end
return M

View File

@@ -0,0 +1,14 @@
local M = {}
M.BUTTON = {
HOVER_SCALE = vmath.vector3(-0.025, -0.025, 1),
HOVER_TIME = 0.05,
SCALE_CHANGE = vmath.vector3(-0.05, - 0.05, 1),
BTN_SOUND = "click",
BTN_SOUND_DISABLED = "click",
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
ENABLED_COLOR = vmath.vector4(1),
}
return M

View File

@@ -0,0 +1,37 @@
local settings = require("druid.settings")
local anims = require("druid.styles.bounce.anims")
local const = require("druid.styles.bounce.const")
local M = {}
M.BUTTON = {
on_hover = function(self, node, state)
if self.hover_anim then
local scale_to = self.scale_from + const.BUTTON.HOVER_SCALE
local target_scale = state and scale_to or self.scale_from
anims.hover_scale(self, target_scale, const.BUTTON.HOVER_TIME)
end
end,
on_click = function(self, node)
local scale_to = self.scale_from + const.BUTTON.SCALE_CHANGE
anims.tap_scale_animation(self, node, scale_to)
settings.play_sound(const.BUTTON.BTN_SOUND)
end,
on_click_disabled = function(self, node)
settings.play_sound(const.BUTTON.BTN_SOUND_DISABLED)
end,
on_set_enabled = function(self, node, state)
if state then
gui.set_color(node, const.BUTTON.ENABLED_COLOR)
else
gui.set_color(node, const.BUTTON.DISABLED_COLOR)
end
end
}
return M