Update annotations: swipe, text, checkbox, checkbox_group, druid_instance

This commit is contained in:
Insality
2020-10-12 00:03:58 +03:00
parent 248b9c30f9
commit bea8e3b329
6 changed files with 203 additions and 223 deletions

View File

@@ -1,18 +1,19 @@
--- Component to handle swipe gestures on node.
-- Swipe will be triggered, if swipe was started and
-- ended on one node
-- @module druid.swipe
-- @module Swipe
-- @within BaseComponent
-- @alias druid.swipe
--- Components fields
-- @table Fields
-- @tparam node node Swipe node
-- @tparam[opt] node click_zone Restriction zone
--- Swipe node
-- @tparam node node
--- Restriction zone
-- @tparam[opt] node click_zone
--- Trigger on swipe event(self, swipe_side, dist, delta_time
-- @tfield druid_event on_swipe)
--- Component events
-- @table Events
-- @tfield druid_event on_swipe Trigger on swipe event
local Event = require("druid.event")
local const = require("druid.const")
@@ -67,11 +68,11 @@ end
--- Component style params.
-- You can override this component styles params in druid styles table
-- or create your own style
-- @table 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 Swipe:on_style_change(style)
function Swipe.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
@@ -80,10 +81,10 @@ end
--- Component init function
-- @function swipe:init
-- @tparam Swipe self
-- @tparam node node Gui node
-- @tparam function on_swipe_callback Swipe callback for on_swipe_end event
function Swipe:init(node, on_swipe_callback)
function Swipe.init(self, node, on_swipe_callback)
self._trigger_on_move = self.style.SWIPE_TRIGGER_ON_MOVE
self.node = self:get_node(node)
@@ -95,7 +96,7 @@ function Swipe:init(node, on_swipe_callback)
end
function Swipe:on_input(action_id, action)
function Swipe.on_input(self, action_id, action)
if action_id ~= const.ACTION_TOUCH then
return false
end
@@ -128,16 +129,16 @@ function Swipe:on_input(action_id, action)
end
function Swipe:on_input_interrupt()
function Swipe.on_input_interrupt(self)
reset_swipe(self)
end
--- Strict swipe click area. Useful for
-- restrict events outside stencil node
-- @function swipe:set_click_zone
-- @tparam Swipe self
-- @tparam node zone Gui node
function Swipe:set_click_zone(zone)
function Swipe.set_click_zone(self, zone)
self.click_zone = self:get_node(zone)
end

View File

@@ -1,26 +1,43 @@
--- Component to handle all GUI texts.
-- Druid text can adjust itself for text node size
-- Text will never will be outside of his text size (even multiline)
-- @module druid.text
-- @module Text
-- @within BaseComponent
-- @alias druid.text
--- Component events
-- @table Events
-- @tfield druid_event on_set_text On set text callback
-- @tfield druid_event on_update_text_scale On adjust text size callback
-- @tfield druid_event on_set_pivot On change pivot callback
--- On set text callback(self, text)
-- @tfield druid_event on_set_text
--- On adjust text size callback(self, new_scale)
-- @tfield druid_event on_update_text_scale
--- On change pivot callback(self, pivot)
-- @tfield druid_event on_set_pivot
--- Text node
-- @tfield node node
--- Current text position
-- @tfield vector3 pos
--- Initial text node scale
-- @tfield vector3 start_scale
--- Current text node scale
-- @tfield vector3 scale
--- Initial text node size
-- @tfield vector3 start_size
--- Current text node available are
-- @tfield vector3 text_area
--- Current text size adjust settings
-- @tfield bool is_no_adjust
--- Current text color
-- @tfield vector3 color
--- Component fields
-- @table Fields
-- @tfield node node Text node
-- @tfield vector3 pos Current text position
-- @tfield vector3 start_scale Initial text node scale
-- @tfield vector3 scale Current text node scale
-- @tfield vector3 start_size Initial text node size
-- @tfield vector3 text_area Current text node available are
-- @tfield bool is_no_adjust Current text size adjust settings
-- @tfield vector3 color Current text color
local Event = require("druid.event")
local const = require("druid.const")
@@ -79,11 +96,11 @@ end
--- Component init function
-- @function text:init
-- @tparam Text self
-- @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 Text:init(node, value, no_adjust)
function Text.init(self, node, value, no_adjust)
self.node = self:get_node(node)
self.pos = gui.get_position(self.node)
@@ -109,15 +126,15 @@ function Text:init(node, value, no_adjust)
end
function Text:on_layout_change()
function Text.on_layout_change(self)
self:set_to(self.last_value)
end
--- Calculate text width with font with respect to trailing space
-- @function text:get_text_width
-- @tparam Text self
-- @tparam[opt] string text
function Text:get_text_width(text)
function Text.get_text_width(self, text)
text = text or self.last_value
local font = gui.get_font(self.node)
local scale = gui.get_scale(self.node)
@@ -136,9 +153,9 @@ end
--- Set text to text field
-- @function text:set_to
-- @tparam Text self
-- @tparam string set_to Text for node
function Text:set_to(set_to)
function Text.set_to(self, set_to)
self.last_value = set_to
gui.set_text(self.node, set_to)
@@ -151,27 +168,27 @@ end
--- Set color
-- @function text:set_color
-- @tparam Text self
-- @tparam vector4 color Color for node
function Text:set_color(color)
function Text.set_color(self, color)
self.color = color
gui.set_color(self.node, color)
end
--- Set alpha
-- @function text:set_alpha
-- @tparam Text self
-- @tparam number alpha Alpha for node
function Text:set_alpha(alpha)
function Text.set_alpha(self, alpha)
self.color.w = alpha
gui.set_color(self.node, self.color)
end
--- Set scale
-- @function text:set_scale
-- @tparam Text self
-- @tparam vector3 scale Scale for node
function Text:set_scale(scale)
function Text.set_scale(self, scale)
self.last_scale = scale
gui.set_scale(self.node, scale)
end
@@ -179,9 +196,9 @@ end
--- Set text pivot. Text will re-anchor inside
-- his text area
-- @function text:set_pivot
-- @tparam Text self
-- @tparam gui.pivot pivot Gui pivot constant
function Text:set_pivot(pivot)
function Text.set_pivot(self, pivot)
local prev_pivot = gui.get_pivot(self.node)
local prev_offset = const.PIVOTS[prev_pivot]
@@ -202,9 +219,9 @@ end
--- Return true, if text with line break
-- @function text:is_multiline
-- @tparam Text self
-- @treturn bool Is text node with line break
function Text:is_multiline()
function Text.is_multiline(self)
return gui.get_line_break(self.node)
end

View File

@@ -1,17 +1,20 @@
--- Druid checkbox component
-- @module druid.checkbox
-- @module Checkbox
-- @within BaseComponent
-- @alias druid.checkbox
--- Component events
-- @table Events
-- @tfield druid_event on_change_state On change state callback
--- On change state callback(self, state)
-- @tfield druid_event on_change_state
--- Visual node
-- @tfield node node
--- Button trigger node
-- @tfield[opt=node] node click_node
--- Button component from click_node
-- @tfield Button button
--- Component fields
-- @table Fields
-- @tfield node node Visual node
-- @tfield[opt=node] node click_node Button trigger node
-- @tfield druid.button button Button component from click_node
local const = require("druid.const")
local Event = require("druid.event")
@@ -28,9 +31,9 @@ end
--- Component style params.
-- You can override this component styles params in druid styles table
-- or create your own style
-- @table Style
-- @table style
-- @tfield function on_change_state (self, node, state)
function Checkbox:on_style_change(style)
function Checkbox.on_style_change(self, style)
self.style = {}
self.style.on_change_state = style.on_change_state or function(_, node, state)
@@ -40,11 +43,11 @@ end
--- Component init function
-- @function checkbox:init
-- @tparam Checkbox self
-- @tparam node node Gui node
-- @tparam function callback Checkbox callback
-- @tparam[opt=node] node click node Trigger node, by default equals to node
function Checkbox:init(node, callback, click_node)
-- @tparam[opt=node] node click_node Trigger node, by default equals to node
function Checkbox.init(self, node, callback, click_node)
self.druid = self:get_druid()
self.node = self:get_node(node)
self.click_node = self:get_node(click_node)
@@ -56,16 +59,16 @@ function Checkbox:init(node, callback, click_node)
end
function Checkbox:on_layout_change()
function Checkbox.on_layout_change(self)
self:set_state(self.state, true)
end
--- Set checkbox state
-- @function checkbox:set_state
-- @tparam Checkbox self
-- @tparam bool state Checkbox state
-- @tparam bool is_silent Don't trigger on_change_state if true
function Checkbox:set_state(state, is_silent)
function Checkbox.set_state(self, state, is_silent)
self.state = state
self.style.on_change_state(self, self.node, state)
@@ -76,9 +79,9 @@ end
--- Return checkbox state
-- @function checkbox:get_state
-- @tparam Checkbox self
-- @treturn bool Checkbox state
function Checkbox:get_state()
function Checkbox.get_state(self)
return self.state
end

View File

@@ -1,15 +1,14 @@
--- Checkbox group module
-- @module druid.checkbox_group
-- @module CheckboxGroup
-- @within BaseComponent
-- @alias druid.checkbox_group
--- Component events
-- @table Events
-- @tfield druid_event on_checkbox_click On any checkbox click
--- On any checkbox click callback(self, index)
-- @tfield druid_event on_checkbox_click
--- Array of checkbox components
-- @tfield table checkboxes
--- Component fields
-- @table Fields
-- @tfield table checkboxes Array of checkbox components
local Event = require("druid.event")
local component = require("druid.component")
@@ -18,11 +17,11 @@ local CheckboxGroup = component.create("checkbox_group")
--- Component init function
-- @function checkbox_group:init
-- @tparam node[] node Array of gui node
-- @tparam CheckboxGroup self
-- @tparam node[] nodes Array of gui node
-- @tparam function callback Checkbox callback
-- @tparam[opt=node] node[] click node Array of trigger nodes, by default equals to nodes
function CheckboxGroup:init(nodes, callback, click_nodes)
-- @tparam[opt=node] node[] click_nodes Array of trigger nodes, by default equals to nodes
function CheckboxGroup.init(self, nodes, callback, click_nodes)
self.druid = self:get_druid()
self.checkboxes = {}
@@ -40,9 +39,9 @@ end
--- Set checkbox group state
-- @function checkbox_group:set_state
-- @tparam CheckboxGroup self
-- @tparam bool[] indexes Array of checkbox state
function CheckboxGroup:set_state(indexes)
function CheckboxGroup.set_state(self, indexes)
for i = 1, #indexes do
if self.checkboxes[i] then
self.checkboxes[i]:set_state(indexes[i], true)
@@ -52,9 +51,9 @@ end
--- Return checkbox group state
-- @function checkbox_group:get_state
-- @tparam CheckboxGroup self
-- @treturn bool[] Array if checkboxes state
function CheckboxGroup:get_state()
function CheckboxGroup.get_state(self)
local result = {}
for i = 1, #self.checkboxes do

View File

@@ -13,7 +13,7 @@
-- @see Blocker
-- @see BackHandler
-- @see druid.input
-- @see druid.text
-- @see Text
-- @see druid.lang_text
-- @see druid.timer
-- @see druid.progress
@@ -21,10 +21,10 @@
-- @see druid.dynamic_grid
-- @see Scroll
-- @see druid.slider
-- @see druid.checkbox
-- @see druid.checkbox_group
-- @see Checkbox
-- @see CheckboxGroup
-- @see druid.radio_group
-- @see druid.swipe
-- @see Swipe
-- @see Drag
-- @see Hover
@@ -529,4 +529,4 @@ function DruidInstance.new_progress(self, ...)
end
return DruidInstanceInstance
return DruidInstance