mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Renamed class functions
This commit is contained in:
@@ -13,14 +13,14 @@ local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("back_handler", { const.ON_INPUT })
|
||||
local BackHandler = component.create("back_handler", { const.ON_INPUT })
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function back_handler:init
|
||||
-- @tparam callback callback On back button
|
||||
-- @tparam[opt] params Callback argument
|
||||
function M.init(self, callback, params)
|
||||
function BackHandler:init(callback, params)
|
||||
self.params = params
|
||||
|
||||
self.on_back = Event(callback)
|
||||
@@ -31,7 +31,7 @@ end
|
||||
-- @function back_handler:on_input
|
||||
-- @tparam string action_id on_input action id
|
||||
-- @tparam table action on_input action
|
||||
function M.on_input(self, action_id, action)
|
||||
function BackHandler:on_input(action_id, action)
|
||||
if not action[const.RELEASED] then
|
||||
return false
|
||||
end
|
||||
@@ -45,4 +45,4 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return BackHandler
|
||||
|
@@ -14,13 +14,13 @@ local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("blocker", { const.ON_INPUT })
|
||||
local Blocker = component.create("blocker", { const.ON_INPUT })
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function blocker:init
|
||||
-- @tparam node node Gui node
|
||||
function M.init(self, node)
|
||||
function Blocker:init(node)
|
||||
self.node = self:get_node(node)
|
||||
|
||||
self.on_click = Event()
|
||||
@@ -28,7 +28,7 @@ function M.init(self, node)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
function Blocker:on_input(action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH and
|
||||
action_id ~= const.ACTION_MULTITOUCH and
|
||||
action_id ~= nil then
|
||||
@@ -50,7 +50,7 @@ end
|
||||
--- Set enabled blocker component state
|
||||
-- @function blocker:set_enabled
|
||||
-- @tparam bool state Enabled state
|
||||
function M.set_enabled(self, state)
|
||||
function Blocker:set_enabled(state)
|
||||
gui.set_enabled(self.node, state)
|
||||
end
|
||||
|
||||
@@ -58,9 +58,9 @@ end
|
||||
--- Return blocked enabled state
|
||||
-- @function blocker:is_enabled
|
||||
-- @treturn bool True, if blocker is enabled
|
||||
function M.is_enabled(self, state)
|
||||
function Blocker:is_enabled(state)
|
||||
return gui.is_enabled(self.node)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Blocker
|
||||
|
@@ -26,7 +26,7 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("button", { const.ON_INPUT })
|
||||
local Button = component.create("button", { const.ON_INPUT })
|
||||
|
||||
|
||||
local function is_input_match(self, action_id)
|
||||
@@ -141,7 +141,7 @@ end
|
||||
-- @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)
|
||||
function Button:on_style_change(style)
|
||||
self.style = {}
|
||||
self.style.LONGTAP_TIME = style.LONGTAP_TIME or 0.4
|
||||
self.style.AUTOHOLD_TRIGGER = style.AUTOHOLD_TRIGGER or 0.8
|
||||
@@ -161,7 +161,7 @@ end
|
||||
-- @tparam function callback Button callback
|
||||
-- @tparam[opt] table params Button callback params
|
||||
-- @tparam[opt] node anim_node Button anim node (node, if not provided)
|
||||
function M.init(self, node, callback, params, anim_node)
|
||||
function Button:init(node, callback, params, anim_node)
|
||||
self.druid = self:get_druid()
|
||||
self.node = self:get_node(node)
|
||||
|
||||
@@ -188,7 +188,7 @@ function M.init(self, node, callback, params, anim_node)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
function Button:on_input(action_id, action)
|
||||
if not is_input_match(self, action_id) then
|
||||
return false
|
||||
end
|
||||
@@ -257,7 +257,7 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input_interrupt(self)
|
||||
function Button:on_input_interrupt()
|
||||
self.can_action = false
|
||||
end
|
||||
|
||||
@@ -266,7 +266,7 @@ end
|
||||
-- @function button:set_enabled
|
||||
-- @tparam bool state Enabled state
|
||||
-- @treturn druid.button Current button instance
|
||||
function M.set_enabled(self, state)
|
||||
function Button:set_enabled(state)
|
||||
self.disabled = not state
|
||||
self.hover:set_enabled(state)
|
||||
self.style.on_set_enabled(self, self.node, state)
|
||||
@@ -278,7 +278,7 @@ end
|
||||
--- Return button enabled state
|
||||
-- @function button:is_enabled
|
||||
-- @treturn bool True, if button is enabled
|
||||
function M.is_enabled(self)
|
||||
function Button:is_enabled()
|
||||
return not self.disabled
|
||||
end
|
||||
|
||||
@@ -288,7 +288,7 @@ end
|
||||
-- @function button:set_click_zone
|
||||
-- @tparam node zone Gui node
|
||||
-- @treturn druid.button Current button instance
|
||||
function M.set_click_zone(self, zone)
|
||||
function Button:set_click_zone(zone)
|
||||
self.click_zone = self:get_node(zone)
|
||||
self.hover:set_click_zone(zone)
|
||||
|
||||
@@ -300,7 +300,7 @@ end
|
||||
-- @function button:set_key_trigger
|
||||
-- @tparam hash key The action_id of the key
|
||||
-- @treturn druid.button Current button instance
|
||||
function M.set_key_trigger(self, key)
|
||||
function Button:set_key_trigger(key)
|
||||
self.key_trigger = hash(key)
|
||||
|
||||
return self
|
||||
@@ -310,9 +310,9 @@ end
|
||||
--- Get key-code to trigger this button
|
||||
-- @function button:get_key_trigger
|
||||
-- @treturn hash The action_id of the key
|
||||
function M.get_key_trigger(self)
|
||||
function Button:get_key_trigger()
|
||||
return self.key_trigger
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Button
|
||||
|
@@ -27,7 +27,7 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("drag", { const.ON_INPUT_HIGH })
|
||||
local Drag = component.create("drag", { const.ON_INPUT_HIGH })
|
||||
|
||||
|
||||
local function start_touch(self, touch)
|
||||
@@ -129,7 +129,7 @@ end
|
||||
-- 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)
|
||||
function Drag:on_style_change(style)
|
||||
self.style = {}
|
||||
self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10
|
||||
end
|
||||
@@ -139,7 +139,7 @@ end
|
||||
-- @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)
|
||||
function Drag:init(node, on_drag_callback)
|
||||
self.node = self:get_node(node)
|
||||
|
||||
self.dx = 0
|
||||
@@ -163,14 +163,14 @@ function M.init(self, node, on_drag_callback)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input_interrupt(self)
|
||||
function Drag:on_input_interrupt()
|
||||
if self.is_drag or self.is_touch then
|
||||
end_touch(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
function Drag:on_input(action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then
|
||||
return false
|
||||
end
|
||||
@@ -243,9 +243,9 @@ end
|
||||
-- restrict events outside stencil node
|
||||
-- @function drag:set_click_zone
|
||||
-- @tparam node zone Gui node
|
||||
function M.set_click_zone(self, zone)
|
||||
function Drag:set_click_zone(zone)
|
||||
self.click_zone = self:get_node(zone)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Drag
|
||||
|
@@ -11,14 +11,14 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("hover", { const.ON_INPUT })
|
||||
local Hover = component.create("hover", { const.ON_INPUT })
|
||||
|
||||
|
||||
--- Component init function
|
||||
-- @function hover:init
|
||||
-- @tparam node node Gui node
|
||||
-- @tparam function on_hover_callback Hover callback
|
||||
function M.init(self, node, on_hover_callback)
|
||||
function Hover:init(node, on_hover_callback)
|
||||
self.node = self:get_node(node)
|
||||
|
||||
self._is_hovered = false
|
||||
@@ -31,7 +31,7 @@ function M.init(self, node, on_hover_callback)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
function Hover:on_input(action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH and action_id ~= nil then
|
||||
return false
|
||||
end
|
||||
@@ -49,7 +49,7 @@ function M.on_input(self, action_id, action)
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
|
||||
local hover_function = action_id and M.set_hover or M.set_mouse_hover
|
||||
local hover_function = action_id and self.set_hover or self.set_mouse_hover
|
||||
|
||||
if not is_pick then
|
||||
hover_function(self, false)
|
||||
@@ -64,7 +64,7 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input_interrupt(self)
|
||||
function Hover:on_input_interrupt()
|
||||
self:set_hover(false)
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ end
|
||||
--- Set hover state
|
||||
-- @function hover:set_hover
|
||||
-- @tparam bool state The hover state
|
||||
function M.set_hover(self, state)
|
||||
function Hover:set_hover(state)
|
||||
if self._is_hovered ~= state then
|
||||
self._is_hovered = state
|
||||
self.on_hover:trigger(self:get_context(), state)
|
||||
@@ -82,7 +82,7 @@ end
|
||||
--- Set mouse hover state
|
||||
-- @function hover:set_mouse_hover
|
||||
-- @tparam bool state The mouse hover state
|
||||
function M.set_mouse_hover(self, state)
|
||||
function Hover:set_mouse_hover(state)
|
||||
if self._is_mouse_hovered ~= state then
|
||||
self._is_mouse_hovered = state
|
||||
self.on_mouse_hover:trigger(self:get_context(), state)
|
||||
@@ -94,7 +94,7 @@ end
|
||||
-- no click events outside stencil node
|
||||
-- @function hover:set_click_zone
|
||||
-- @tparam node zone Gui node
|
||||
function M.set_click_zone(self, zone)
|
||||
function Hover:set_click_zone(zone)
|
||||
self.click_zone = self:get_node(zone)
|
||||
end
|
||||
|
||||
@@ -104,7 +104,7 @@ end
|
||||
-- any hover events
|
||||
-- @function hover:set_enabled
|
||||
-- @tparam bool state The hover enabled state
|
||||
function M.set_enabled(self, state)
|
||||
function Hover:set_enabled(state)
|
||||
self._is_enabled = state
|
||||
|
||||
if not state then
|
||||
@@ -121,9 +121,9 @@ end
|
||||
--- Return current hover enabled state
|
||||
-- @function hover:is_enabled
|
||||
-- @treturn bool The hover enabled state
|
||||
function M.is_enabled(self)
|
||||
function Hover:is_enabled()
|
||||
return self._is_enabled
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Hover
|
||||
|
@@ -17,7 +17,7 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("swipe", { const.ON_INPUT })
|
||||
local Swipe = component.create("swipe", { const.ON_INPUT })
|
||||
|
||||
|
||||
local function start_swipe(self, action)
|
||||
@@ -69,7 +69,7 @@ end
|
||||
-- @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)
|
||||
function Swipe:on_style_change(style)
|
||||
self.style = {}
|
||||
self.style.SWIPE_TIME = style.SWIPE_TIME or 0.4
|
||||
self.style.SWIPE_THRESHOLD = style.SWIPE_THRESHOLD or 50
|
||||
@@ -81,7 +81,7 @@ end
|
||||
-- @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)
|
||||
function Swipe:init(node, on_swipe_callback)
|
||||
self._trigger_on_move = self.style.SWIPE_TRIGGER_ON_MOVE
|
||||
self.node = self:get_node(node)
|
||||
|
||||
@@ -93,7 +93,7 @@ function M.init(self, node, on_swipe_callback)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
function Swipe:on_input(action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH then
|
||||
return false
|
||||
end
|
||||
@@ -126,7 +126,7 @@ function M.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
|
||||
function M.on_input_interrupt(self)
|
||||
function Swipe:on_input_interrupt()
|
||||
reset_swipe(self)
|
||||
end
|
||||
|
||||
@@ -135,9 +135,9 @@ end
|
||||
-- restrict events outside stencil node
|
||||
-- @function swipe:set_click_zone
|
||||
-- @tparam node zone Gui node
|
||||
function M.set_click_zone(self, zone)
|
||||
function Swipe:set_click_zone(zone)
|
||||
self.click_zone = self:get_node(zone)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Swipe
|
||||
|
@@ -24,7 +24,7 @@ local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("text", { const.ON_LAYOUT_CHANGE })
|
||||
local Text = component.create("text", { const.ON_LAYOUT_CHANGE })
|
||||
|
||||
|
||||
local function update_text_size(self)
|
||||
@@ -81,7 +81,7 @@ end
|
||||
-- @tparam node node Gui text node
|
||||
-- @tparam[opt] string value Initial text. Default value is node text from GUI scene.
|
||||
-- @tparam[opt] bool no_adjust If true, text will be not auto-adjust size
|
||||
function M.init(self, node, value, no_adjust)
|
||||
function Text:init(node, value, no_adjust)
|
||||
self.node = self:get_node(node)
|
||||
self.pos = gui.get_position(self.node)
|
||||
|
||||
@@ -107,7 +107,7 @@ function M.init(self, node, value, no_adjust)
|
||||
end
|
||||
|
||||
|
||||
function M.on_layout_change(self)
|
||||
function Text:on_layout_change()
|
||||
self:set_to(self.last_value)
|
||||
end
|
||||
|
||||
@@ -115,7 +115,7 @@ end
|
||||
--- Calculate text width with font with respect to trailing space
|
||||
-- @function text:get_text_width
|
||||
-- @tparam[opt] string text
|
||||
function M.get_text_width(self, text)
|
||||
function Text:get_text_width(text)
|
||||
text = text or self.last_value
|
||||
local font = gui.get_font(self.node)
|
||||
local scale = gui.get_scale(self.node)
|
||||
@@ -136,7 +136,7 @@ end
|
||||
--- Set text to text field
|
||||
-- @function text:set_to
|
||||
-- @tparam string set_to Text for node
|
||||
function M.set_to(self, set_to)
|
||||
function Text:set_to(set_to)
|
||||
self.last_value = set_to
|
||||
gui.set_text(self.node, set_to)
|
||||
|
||||
@@ -151,7 +151,7 @@ end
|
||||
--- Set color
|
||||
-- @function text:set_color
|
||||
-- @tparam vector4 color Color for node
|
||||
function M.set_color(self, color)
|
||||
function Text:set_color(color)
|
||||
self.color = color
|
||||
gui.set_color(self.node, color)
|
||||
end
|
||||
@@ -160,7 +160,7 @@ end
|
||||
--- Set alpha
|
||||
-- @function text:set_alpha
|
||||
-- @tparam number alpha Alpha for node
|
||||
function M.set_alpha(self, alpha)
|
||||
function Text:set_alpha(alpha)
|
||||
self.color.w = alpha
|
||||
gui.set_color(self.node, self.color)
|
||||
end
|
||||
@@ -169,7 +169,7 @@ end
|
||||
--- Set scale
|
||||
-- @function text:set_scale
|
||||
-- @tparam vector3 scale Scale for node
|
||||
function M.set_scale(self, scale)
|
||||
function Text:set_scale(scale)
|
||||
self.last_scale = scale
|
||||
gui.set_scale(self.node, scale)
|
||||
end
|
||||
@@ -179,7 +179,7 @@ end
|
||||
-- his text area
|
||||
-- @function text:set_pivot
|
||||
-- @tparam gui.pivot pivot Gui pivot constant
|
||||
function M.set_pivot(self, pivot)
|
||||
function Text:set_pivot(pivot)
|
||||
local prev_pivot = gui.get_pivot(self.node)
|
||||
local prev_offset = const.PIVOTS[prev_pivot]
|
||||
|
||||
@@ -202,9 +202,9 @@ end
|
||||
--- Return true, if text with line break
|
||||
-- @function text:is_multiline
|
||||
-- @treturn bool Is text node with line break
|
||||
function M.is_multiline(self)
|
||||
function Text:is_multiline()
|
||||
return gui.get_line_break(self.node)
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Text
|
||||
|
Reference in New Issue
Block a user