mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
Merge pull request #60 from Insality/feature/54-styles-refactoring
Feature/54 styles refactoring
This commit is contained in:
commit
3fae050b9d
@ -21,13 +21,6 @@
|
||||
-- @tfield druid.hover hover Druid hover logic component
|
||||
-- @tfield[opt] node click_zone Restriction zone
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield function on_click (self, node)
|
||||
-- @tfield function on_click_disabled (self, node)
|
||||
-- @tfield function on_hover (self, node, hover_state)
|
||||
-- @tfield function on_set_enabled (self, node, enabled_state)
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
@ -50,27 +43,18 @@ end
|
||||
|
||||
|
||||
local function on_button_hover(self, hover_state)
|
||||
if not self._style.on_hover then
|
||||
return
|
||||
end
|
||||
|
||||
self._style.on_hover(self, self.anim_node, hover_state)
|
||||
self.style.on_hover(self, self.anim_node, hover_state)
|
||||
end
|
||||
|
||||
|
||||
local function on_button_mouse_hover(self, hover_state)
|
||||
if not self._style.on_mouse_hover then
|
||||
return
|
||||
end
|
||||
|
||||
self._style.on_mouse_hover(self, self.anim_node, hover_state)
|
||||
self.style.on_mouse_hover(self, self.anim_node, hover_state)
|
||||
end
|
||||
|
||||
|
||||
local function on_button_click(self)
|
||||
if self._style.on_click then
|
||||
self._style.on_click(self, self.anim_node)
|
||||
end
|
||||
self.style.on_click(self, self.anim_node)
|
||||
|
||||
self.click_in_row = 1
|
||||
self.on_click:trigger(self:get_context(), self.params, self)
|
||||
end
|
||||
@ -82,18 +66,16 @@ local function on_button_repeated_click(self)
|
||||
self.is_repeated_started = true
|
||||
end
|
||||
|
||||
if self._style.on_click then
|
||||
self._style.on_click(self, self.anim_node)
|
||||
end
|
||||
self.style.on_click(self, self.anim_node)
|
||||
|
||||
self.click_in_row = self.click_in_row + 1
|
||||
self.on_repeated_click:trigger(self:get_context(), self.params, self, self.click_in_row)
|
||||
end
|
||||
|
||||
|
||||
local function on_button_long_click(self)
|
||||
if self._style.on_click then
|
||||
self._style.on_click(self, self.anim_node)
|
||||
end
|
||||
self.style.on_click(self, self.anim_node)
|
||||
|
||||
self.click_in_row = 1
|
||||
local time = socket.gettime() - self.last_pressed_time
|
||||
self.on_long_click:trigger(self:get_context(), self.params, self, time)
|
||||
@ -101,9 +83,8 @@ end
|
||||
|
||||
|
||||
local function on_button_double_click(self)
|
||||
if self._style.on_click then
|
||||
self._style.on_click(self, self.anim_node)
|
||||
end
|
||||
self.style.on_click(self, self.anim_node)
|
||||
|
||||
self.click_in_row = self.click_in_row + 1
|
||||
self.on_double_click:trigger(self:get_context(), self.params, self, self.click_in_row)
|
||||
end
|
||||
@ -124,10 +105,10 @@ local function on_button_release(self)
|
||||
self.can_action = false
|
||||
|
||||
local time = socket.gettime()
|
||||
local is_long_click = (time - self.last_pressed_time) > self._style.LONGTAP_TIME
|
||||
local is_long_click = (time - self.last_pressed_time) > self.style.LONGTAP_TIME
|
||||
is_long_click = is_long_click and self.on_long_click:is_exist()
|
||||
|
||||
local is_double_click = (time - self.last_released_time) < self._style.DOUBLETAP_TIME
|
||||
local is_double_click = (time - self.last_released_time) < self.style.DOUBLETAP_TIME
|
||||
is_double_click = is_double_click and self.on_double_click:is_exist()
|
||||
|
||||
if is_long_click then
|
||||
@ -142,14 +123,38 @@ local function on_button_release(self)
|
||||
end
|
||||
return true
|
||||
else
|
||||
if self._style.on_click_disabled then
|
||||
self._style.on_click_disabled(self, self.anim_node)
|
||||
end
|
||||
self.style.on_click_disabled(self, self.anim_node)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=0.4] number LONGTAP_TIME Minimum time to trigger on_hold_callback
|
||||
-- @tfield[opt=0.8] number AUTOHOLD_TRIGGER Maximum hold time to trigger button release while holding
|
||||
-- @tfield[opt=0.4] number DOUBLETAP_TIME Time between double taps
|
||||
-- @tfield function on_click (self, node)
|
||||
-- @tfield function on_click_disabled (self, node)
|
||||
-- @tfield function on_hover (self, node, hover_state)
|
||||
-- @tfield function on_mouse_hover (self, node, hover_state)
|
||||
-- @tfield function on_set_enabled (self, node, enabled_state)
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.LONGTAP_TIME = style.LONGTAP_TIME or 0.4
|
||||
self.style.AUTOHOLD_TRIGGER = style.AUTOHOLD_TRIGGER or 0.8
|
||||
self.style.DOUBLETAP_TIME = style.DOUBLETAP_TIME or 0.4
|
||||
|
||||
self.style.on_click = style.on_click or function(_, node) end
|
||||
self.style.on_click_disabled = style.on_click_disabled or function(_, node) end
|
||||
self.style.on_mouse_hover = style.on_mouse_hover or function(_, node, state) end
|
||||
self.style.on_hover = style.on_hover or function(_, node, state) end
|
||||
self.style.on_set_enabled = style.on_set_enabled or function(_, node, state) end
|
||||
end
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function button:init
|
||||
-- @tparam node node Gui node
|
||||
@ -237,12 +242,12 @@ function M.on_input(self, action_id, action)
|
||||
if not self.disabled and self.can_action and self.on_long_click:is_exist() then
|
||||
local press_time = socket.gettime() - self.last_pressed_time
|
||||
|
||||
if self._style.AUTOHOLD_TRIGGER and self._style.AUTOHOLD_TRIGGER <= press_time then
|
||||
if self.style.AUTOHOLD_TRIGGER <= press_time then
|
||||
on_button_release(self)
|
||||
return true
|
||||
end
|
||||
|
||||
if press_time >= self._style.LONGTAP_TIME then
|
||||
if press_time >= self.style.LONGTAP_TIME then
|
||||
on_button_hold(self, press_time)
|
||||
return true
|
||||
end
|
||||
@ -262,9 +267,7 @@ end
|
||||
-- @tparam bool state Enabled state
|
||||
function M.set_enabled(self, state)
|
||||
self.disabled = not state
|
||||
if self._style.on_set_enabled then
|
||||
self._style.on_set_enabled(self, self.node, state)
|
||||
end
|
||||
self.style.on_set_enabled(self, self.node, state)
|
||||
end
|
||||
|
||||
|
||||
|
@ -11,10 +11,6 @@
|
||||
-- @tfield[opt=node] node click_node Button trigger node
|
||||
-- @tfield druid.button button Button component from click_node
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield function on_change_state (self, node, state)
|
||||
|
||||
local Event = require("druid.event")
|
||||
local component = require("druid.component")
|
||||
|
||||
@ -26,13 +22,26 @@ local function on_click(self)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield function on_change_state (self, node, state)
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
|
||||
self.style.on_change_state = style.on_change_state or function(_, node, state)
|
||||
gui.set_enabled(node, state)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function checkbox:init
|
||||
-- @tparam node node Gui node
|
||||
-- @tparam function callback Checkbox callback
|
||||
-- @tparam[opt=node] node click node Trigger node, by default equals to node
|
||||
function M.init(self, node, callback, click_node)
|
||||
self.style = self:get_style()
|
||||
self.druid = self:get_druid()
|
||||
self.node = self:get_node(node)
|
||||
self.click_node = self:get_node(click_node)
|
||||
@ -54,9 +63,7 @@ function M.set_state(self, state, is_silent)
|
||||
end
|
||||
|
||||
self.state = state
|
||||
if self.style.on_change_state then
|
||||
self.style.on_change_state(self, self.node, state)
|
||||
end
|
||||
|
||||
if not is_silent then
|
||||
self.on_change_state:trigger(self:get_context(), state)
|
||||
|
@ -22,10 +22,6 @@
|
||||
-- @tfield number y Current touch y position
|
||||
-- @tfield vector3 touch_start_pos Touch start position
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield number DRAG_DEADZONE Distance in pixels to start dragging
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
@ -128,12 +124,22 @@ local function on_touch_release(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=10] number DRAG_DEADZONE Distance in pixels to start dragging
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10
|
||||
end
|
||||
|
||||
|
||||
--- Drag component constructor
|
||||
-- @tparam node node GUI node to detect dragging
|
||||
-- @tparam function on_drag_callback Callback for on_drag_event(self, dx, dy)
|
||||
-- @function drag:init
|
||||
function M.init(self, node, on_drag_callback)
|
||||
self.style = self:get_style()
|
||||
self.node = self:get_node(node)
|
||||
|
||||
self.dx = 0
|
||||
|
@ -22,16 +22,6 @@
|
||||
-- @tfield[opt] string allowerd_characters Pattern matching for user input
|
||||
-- @tfield number keyboard_type Gui keyboard type for input field
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield bool IS_LONGTAP_ERASE Is long tap will erase current input data
|
||||
-- @tfield number BUTTON_SELECT_INCREASE Button scale multiplier on selecting input field
|
||||
-- @tfield string MASK_DEFAULT_CHAR Default character mask for password input
|
||||
-- @tfield function on_select (self, button_node) Callback on input field selecting
|
||||
-- @tfield function on_unselect (self, button_node) Callback on input field unselecting
|
||||
-- @tfield function on_input_wrong (self, button_node) Callback on wrong user input
|
||||
-- @tfield table button Custom button style for input node
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local component = require("druid.component")
|
||||
@ -67,10 +57,8 @@ local function select(self)
|
||||
gui.show_keyboard(self.keyboard_type, false)
|
||||
self.on_input_select:trigger(self:get_context())
|
||||
|
||||
if self.style.on_select then
|
||||
self.style.on_select(self, self.button.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -85,10 +73,8 @@ local function unselect(self)
|
||||
gui.hide_keyboard()
|
||||
self.on_input_unselect:trigger(self:get_context())
|
||||
|
||||
if self.style.on_unselect then
|
||||
self.style.on_unselect(self, self.button.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -101,9 +87,36 @@ local function clear_and_select(self)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=false] bool IS_LONGTAP_ERASE Is long tap will erase current input data
|
||||
-- @tfield[opt=*] string MASK_DEFAULT_CHAR Default character mask for password input
|
||||
-- @tfield function on_select (self, button_node) Callback on input field selecting
|
||||
-- @tfield function on_unselect (self, button_node) Callback on input field unselecting
|
||||
-- @tfield function on_input_wrong (self, button_node) Callback on wrong user input
|
||||
-- @tfield table button_style Custom button style for input node
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
|
||||
self.style.IS_LONGTAP_ERASE = style.IS_LONGTAP_ERASE or false
|
||||
self.style.MASK_DEFAULT_CHAR = style.MASK_DEFAULT_CHAR or "*"
|
||||
|
||||
self.style.on_select = style.on_select or function(self, button_node) end
|
||||
self.style.on_unselect = style.on_unselect or function(self, button_node) end
|
||||
self.style.on_input_wrong = style.on_input_wrong or function(self, button_node) end
|
||||
|
||||
self.style.button_style = style.button_style or {
|
||||
LONGTAP_TIME = 0.4,
|
||||
AUTOHOLD_TRIGGER = 0.8,
|
||||
DOUBLETAP_TIME = 0.4
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
function M.init(self, click_node, text_node, keyboard_type)
|
||||
self.druid = self:get_druid(self)
|
||||
self.style = self:get_style(self)
|
||||
self.text = self.druid:new_text(text_node)
|
||||
|
||||
self.selected = false
|
||||
@ -123,7 +136,7 @@ function M.init(self, click_node, text_node, keyboard_type)
|
||||
self.keyboard_type = keyboard_type or gui.KEYBOARD_TYPE_DEFAULT
|
||||
|
||||
self.button = self.druid:new_button(click_node, select)
|
||||
self.button:set_style(self.style)
|
||||
self.button:set_style(self.button_style)
|
||||
self.button.on_click_outside:subscribe(unselect)
|
||||
self.button.on_long_click:subscribe(clear_and_select)
|
||||
|
||||
@ -158,10 +171,8 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
else
|
||||
self.on_input_wrong:trigger(self:get_context(), action.text)
|
||||
if self.style.on_input_wrong then
|
||||
self.style.on_input_wrong(self, self.button.node)
|
||||
end
|
||||
end
|
||||
self.marked_value = ""
|
||||
end
|
||||
end
|
||||
|
@ -15,11 +15,6 @@
|
||||
-- @tfield number max_size Maximum size of progress bar
|
||||
-- @tfield vector4 slice Progress bar slice9 settings
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield number SPEED Progress bas fill rate. More -> faster
|
||||
-- @tfield number MIN_DELTA Minimum step to fill progress bar
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
@ -70,6 +65,19 @@ local function set_bar_to(self, set_to, is_silent)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=5] number SPEED Progress bas fill rate. More -> faster
|
||||
-- @tfield[opt=0.005] number MIN_DELTA Minimum step to fill progress bar
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.SPEED = style.SPEED or 5
|
||||
self.style.MIN_DELTA = style.MIN_DELTA or 0.005
|
||||
end
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function progress:init
|
||||
-- @tparam string|node node Progress bar fill node or node name
|
||||
@ -81,7 +89,6 @@ function M.init(self, node, key, init_value)
|
||||
self.prop = hash("scale."..key)
|
||||
self.key = key
|
||||
|
||||
self.style = self:get_style()
|
||||
self.node = self:get_node(node)
|
||||
self.scale = gui.get_scale(self.node)
|
||||
self.size = gui.get_size(self.node)
|
||||
|
@ -27,18 +27,6 @@
|
||||
-- @tfield[opt] selected Current index of points of interests
|
||||
-- @tfield bool is_animate Flag, if scroll now animating by gui.animate
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield number FRICT_HOLD Multiplier for inertion, while touching
|
||||
-- @tfield number FRICT Multiplier for free inertion
|
||||
-- @tfield number INERT_THRESHOLD Scroll speed to stop inertion
|
||||
-- @tfield number INERT_SPEED Multiplier for inertion speed
|
||||
-- @tfield number POINTS_DEADZONE Speed to check points of interests in no_inertion mode
|
||||
-- @tfield number BACK_SPEED Scroll back returning lerp speed
|
||||
-- @tfield number ANIM_SPEED Scroll gui.animation speed for scroll_to function
|
||||
-- @tfield number EXTRA_STRECH_SIZE extra size in pixels outside of scroll (stretch effect)
|
||||
-- @tfield bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
@ -302,17 +290,18 @@ local function update_size(self)
|
||||
-- We add extra size only if scroll is available
|
||||
-- Even the content zone size less than view zone size
|
||||
local content_border_extra = helper.get_border(self.content_node)
|
||||
local stretch_size = self.style.EXTRA_STRECH_SIZE
|
||||
|
||||
if self.drag.can_x then
|
||||
local sign = content_size.x > view_size.x and 1 or -1
|
||||
content_border_extra.x = content_border_extra.x - self.extra_stretch_size * sign
|
||||
content_border_extra.z = content_border_extra.z + self.extra_stretch_size * sign
|
||||
content_border_extra.x = content_border_extra.x - stretch_size * sign
|
||||
content_border_extra.z = content_border_extra.z + stretch_size * sign
|
||||
end
|
||||
|
||||
if self.drag.can_y then
|
||||
local sign = content_size.y > view_size.y and 1 or -1
|
||||
content_border_extra.y = content_border_extra.y + self.extra_stretch_size * sign
|
||||
content_border_extra.w = content_border_extra.w - self.extra_stretch_size * sign
|
||||
content_border_extra.y = content_border_extra.y + stretch_size * sign
|
||||
content_border_extra.w = content_border_extra.w - stretch_size * sign
|
||||
end
|
||||
|
||||
if not self.style.SMALL_CONTENT_SCROLL then
|
||||
@ -325,13 +314,45 @@ local function update_size(self)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=0] number FRICT Multiplier for free inertion
|
||||
-- @tfield[opt=0] number FRICT_HOLD Multiplier for inertion, while touching
|
||||
-- @tfield[opt=3] number INERT_THRESHOLD Scroll speed to stop inertion
|
||||
-- @tfield[opt=30] number INERT_SPEED Multiplier for inertion speed
|
||||
-- @tfield[opt=20] number POINTS_DEADZONE Speed to check points of interests in no_inertion mode
|
||||
-- @tfield[opt=0.35] number BACK_SPEED Scroll back returning lerp speed
|
||||
-- @tfield[opt=0.2] number ANIM_SPEED Scroll gui.animation speed for scroll_to function
|
||||
-- @tfield[opt=0] number EXTRA_STRECH_SIZE extra size in pixels outside of scroll (stretch effect)
|
||||
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.EXTRA_STRECH_SIZE = style.EXTRA_STRECH_SIZE or 0
|
||||
self.style.ANIM_SPEED = style.ANIM_SPEED or 0.2
|
||||
self.style.BACK_SPEED = style.BACK_SPEED or 0.35
|
||||
|
||||
self.style.FRICT = style.FRICT or 0
|
||||
self.style.FRICT_HOLD = style.FRICT_HOLD or 0
|
||||
|
||||
self.style.INERT_THRESHOLD = style.INERT_THRESHOLD or 3
|
||||
self.style.INERT_SPEED = style.INERT_SPEED or 30
|
||||
self.style.POINTS_DEADZONE = style.POINTS_DEADZONE or 20
|
||||
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
|
||||
|
||||
self._is_inert = not (self.style.FRICT == 0 or
|
||||
self.style.FRICT_HOLD == 0 or
|
||||
self.style.INERT_SPEED == 0)
|
||||
end
|
||||
|
||||
|
||||
--- Scroll constructor.
|
||||
-- @function scroll:init
|
||||
-- @tparam node view_node GUI view scroll node
|
||||
-- @tparam node content_node GUI content scroll node
|
||||
function M.init(self, view_node, content_node)
|
||||
self.druid = self:get_druid()
|
||||
self.style = self:get_style()
|
||||
|
||||
self.view_node = self:get_node(view_node)
|
||||
self.content_node = self:get_node(content_node)
|
||||
@ -349,9 +370,7 @@ function M.init(self, view_node, content_node)
|
||||
self.on_point_scroll = Event()
|
||||
|
||||
self.selected = nil
|
||||
self._is_inert = true
|
||||
self.is_animate = false
|
||||
self.extra_stretch_size = self.style.EXTRA_STRECH_SIZE
|
||||
|
||||
update_size(self)
|
||||
end
|
||||
@ -486,10 +505,10 @@ end
|
||||
--- Set extra size for scroll stretching.
|
||||
-- Set 0 to disable stretching effect
|
||||
-- @function scroll:set_extra_strech_size
|
||||
-- @tparam number stretch_size Size in pixels of additional scroll area
|
||||
-- @tparam[opt=0] number stretch_size Size in pixels of additional scroll area
|
||||
-- @treturn druid.scroll Self instance
|
||||
function M.set_extra_strech_size(self, stretch_size)
|
||||
self.extra_stretch_size = stretch_size or self.style.EXTRA_STRECH_SIZE
|
||||
self.style.EXTRA_STRECH_SIZE = stretch_size or 0
|
||||
update_size(self)
|
||||
|
||||
return self
|
||||
|
@ -12,12 +12,6 @@
|
||||
-- @table Events
|
||||
-- @tfield druid_event on_swipe Trigger on swipe event
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield number SWIPE_TIME Maximum time for swipe trigger
|
||||
-- @tfield number SWIPE_THRESHOLD Minimum distance for swipe trigger
|
||||
-- @tfield bool SWIPE_TRIGGER_ON_MOVE If true, trigger on swipe moving, not only release action
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
@ -48,6 +42,7 @@ local function check_swipe(self, action)
|
||||
if is_swipe then
|
||||
local is_x_swipe = math.abs(dx) >= math.abs(dy)
|
||||
local swipe_side = false
|
||||
|
||||
if is_x_swipe and dx > 0 then
|
||||
swipe_side = const.SWIPE.RIGHT
|
||||
end
|
||||
@ -67,12 +62,26 @@ local function check_swipe(self, action)
|
||||
end
|
||||
|
||||
|
||||
--- Component style params.
|
||||
-- You can override this component styles params in druid styles table
|
||||
-- or create your own style
|
||||
-- @table Style
|
||||
-- @tfield[opt=0.4] number SWIPE_TIME Maximum time for swipe trigger
|
||||
-- @tfield[opt=50] number SWIPE_THRESHOLD Minimum distance for swipe trigger
|
||||
-- @tfield[opt=false] bool SWIPE_TRIGGER_ON_MOVE If true, trigger on swipe moving, not only release action
|
||||
function M.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.SWIPE_TIME = style.SWIPE_TIME or 0.4
|
||||
self.style.SWIPE_THRESHOLD = style.SWIPE_THRESHOLD or 50
|
||||
self.style.SWIPE_TRIGGER_ON_MOVE = style.SWIPE_TRIGGER_ON_MOVE or false
|
||||
end
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function swipe:init
|
||||
-- @tparam node node Gui node
|
||||
-- @tparam function on_swipe_callback Swipe callback for on_swipe_end event
|
||||
function M.init(self, node, on_swipe_callback)
|
||||
self.style = self:get_style()
|
||||
self._trigger_on_move = self.style.SWIPE_TRIGGER_ON_MOVE
|
||||
self.node = self:get_node(node)
|
||||
|
||||
|
@ -9,24 +9,18 @@ local class = require("druid.system.middleclass")
|
||||
local Component = class("druid.component")
|
||||
|
||||
|
||||
--- Get current component style table
|
||||
-- @function component:get_style
|
||||
-- @treturn table Component style table
|
||||
function Component.get_style(self)
|
||||
if not self._meta.style then
|
||||
return const.EMPTY_TABLE
|
||||
end
|
||||
|
||||
return self._meta.style[self._component.name] or const.EMPTY_TABLE
|
||||
end
|
||||
|
||||
|
||||
--- Set current component style table
|
||||
--- Set current component style table.
|
||||
-- Invoke `on_style_change` on component, if exist. Component should handle
|
||||
-- their style changing and store all style params
|
||||
-- @function component:set_style
|
||||
-- @tparam table style Druid style module
|
||||
function Component.set_style(self, druid_style)
|
||||
self._meta.style = druid_style
|
||||
self._style = self:get_style()
|
||||
self._meta.style = druid_style or const.EMPTY_TABLE
|
||||
local component_style = self._meta.style[self._component.name] or const.EMPTY_TABLE
|
||||
|
||||
if self.on_style_change then
|
||||
self:on_style_change(component_style)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ end
|
||||
-- @function druid.set_default_style
|
||||
-- @tparam table style Druid style module
|
||||
function M.set_default_style(style)
|
||||
settings.default_style = style
|
||||
settings.default_style = style or {}
|
||||
end
|
||||
|
||||
|
||||
|
@ -118,10 +118,6 @@ M["input"] = {
|
||||
end,
|
||||
|
||||
button = {
|
||||
BTN_SOUND = "click",
|
||||
BTN_SOUND_DISABLED = "click",
|
||||
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
|
||||
ENABLED_COLOR = vmath.vector4(1),
|
||||
LONGTAP_TIME = 0.4,
|
||||
AUTOHOLD_TRIGGER = 0.8,
|
||||
DOUBLETAP_TIME = 0.4,
|
||||
|
@ -1,51 +1 @@
|
||||
local M = {}
|
||||
|
||||
|
||||
M["button"] = {
|
||||
BTN_SOUND = "click",
|
||||
BTN_SOUND_DISABLED = "click",
|
||||
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
|
||||
ENABLED_COLOR = vmath.vector4(1),
|
||||
LONGTAP_TIME = 0.4,
|
||||
DOUBLETAP_TIME = 0.4,
|
||||
}
|
||||
|
||||
|
||||
M["scroll"] = {
|
||||
FRICT_HOLD = 0, -- mult. for inert, while touching
|
||||
FRICT = 0, -- mult for free inert
|
||||
INERT_THRESHOLD = 2, -- speed to stop inertion
|
||||
INERT_SPEED = 0, -- koef. of inert speed
|
||||
DEADZONE = 6, -- in px
|
||||
SOFT_ZONE_SIZE = 20, -- size of outside zone (back move)
|
||||
BACK_SPEED = 0, -- lerp speed
|
||||
ANIM_SPEED = 0, -- gui.animation speed to point
|
||||
}
|
||||
|
||||
|
||||
M["progress"] = {
|
||||
SPEED = 5, -- progress bar fill rate, more faster
|
||||
MIN_DELTA = 1
|
||||
}
|
||||
|
||||
|
||||
M["progress_rich"] = {
|
||||
DELAY = 0, -- delay in seconds before main fill
|
||||
}
|
||||
|
||||
|
||||
M["checkbox"] = {
|
||||
on_change_state = function(self, node, state)
|
||||
gui.set_enabled(node, state)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
M["swipe"] = {
|
||||
SWIPE_THRESHOLD = 50,
|
||||
SWIPE_TIME = 0.4,
|
||||
SWIPE_TRIGGER_ON_MOVE = false
|
||||
}
|
||||
|
||||
|
||||
return M
|
||||
return {}
|
||||
|
@ -2,12 +2,9 @@ local M = {}
|
||||
|
||||
|
||||
M["button"] = {
|
||||
BTN_SOUND = "click",
|
||||
BTN_SOUND_DISABLED = "click",
|
||||
DISABLED_COLOR = vmath.vector4(0, 0, 0, 1),
|
||||
ENABLED_COLOR = vmath.vector4(1),
|
||||
LONGTAP_TIME = 0.4,
|
||||
DOUBLETAP_TIME = 0.4,
|
||||
|
||||
HOVER_MOUSE_IMAGE = "button_yellow",
|
||||
DEFAULT_IMAGE = "button_blue",
|
||||
HOVER_IMAGE = "button_red",
|
||||
@ -24,41 +21,4 @@ M["button"] = {
|
||||
}
|
||||
|
||||
|
||||
M["scroll"] = {
|
||||
FRICT_HOLD = 0, -- mult. for inert, while touching
|
||||
FRICT = 0, -- mult for free inert
|
||||
INERT_THRESHOLD = 2, -- speed to stop inertion
|
||||
INERT_SPEED = 0, -- koef. of inert speed
|
||||
DEADZONE = 6, -- in px
|
||||
SOFT_ZONE_SIZE = 20, -- size of outside zone (back move)
|
||||
BACK_SPEED = 0, -- lerp speed
|
||||
ANIM_SPEED = 0, -- gui.animation speed to point
|
||||
}
|
||||
|
||||
|
||||
M["progress"] = {
|
||||
SPEED = 5, -- progress bar fill rate, more faster
|
||||
MIN_DELTA = 1
|
||||
}
|
||||
|
||||
|
||||
M["progress_rich"] = {
|
||||
DELAY = 0, -- delay in seconds before main fill
|
||||
}
|
||||
|
||||
|
||||
M["checkbox"] = {
|
||||
on_change_state = function(self, node, state)
|
||||
gui.set_enabled(node, state)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
M["swipe"] = {
|
||||
SWIPE_THRESHOLD = 50,
|
||||
SWIPE_TIME = 0.4,
|
||||
SWIPE_TRIGGER_ON_MOVE = false
|
||||
}
|
||||
|
||||
|
||||
return M
|
||||
|
Loading…
x
Reference in New Issue
Block a user