Skip to content

Commit

Permalink
Add button correct annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Oct 11, 2020
1 parent 3933d53 commit fbef0cb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
3 changes: 1 addition & 2 deletions config.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package='druid'
sort=false
dir='./docs'
style='!fixed'
format='discount'
topics={"./docs_md", "README.md"}
topics={}
use_markdown_titles=true
no_space_before_args=true
99 changes: 62 additions & 37 deletions druid/base/button.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
--- Component to handle basic GUI button
-- @module druid.button

--- Component events
-- @table Events
-- @tfield druid_event on_click (self, params, button_instance) On release button callback
-- @tfield druid_event on_repeated_click (self, params, button_instance, click_amount) On repeated action button callback
-- @tfield druid_event on_long_click (self, params, button_instance, time) On long tap button callback
-- @tfield druid_event on_double_click (self, params, button_instance, click_amount) On double tap button callback
-- @tfield druid_event on_hold_callback (self, params, button_instance, time) On button hold before long_click callback
-- @tfield druid_event on_click_outside (self, params, button_instance) On click outside of button

--- Component fields
-- @table Fields
-- @tfield node node Trigger node
-- @tfield[opt=node] node anim_node Animation node
-- @tfield vector3 start_scale Initial scale of anim_node
-- @tfield vector3 start_pos Initial pos of anim_node
-- @tfield vector3 pos Initial pos of anim_node
-- @tfield any params Params to click callbacks
-- @tfield druid.hover hover Druid hover logic component
-- @tfield[opt] node click_zone Restriction zone
-- @module Button
-- @alias druid.button
-- @within component

--- On release button callback(self, params, button_instance)
-- @tfield druid_event on_click

--- On repeated action button callback(self, params, button_instance, click_amount)
-- @tfield druid_event on_repeated_click

---On long tap button callback(self, params, button_instance, time)
-- @tfield druid_event on_long_click

---On double tap button callback(self, params, button_instance, click_amount)
-- @tfield druid_event on_double_click

---On button hold before long_click callback(self, params, button_instance, time)
-- @tfield druid_event on_hold_callback

---On click outside of button(self, params, button_instance)
-- @tfield druid_event on_click_outside

---Trigger node
-- @tfield node node

---Animation node
-- @tfield[opt=node] node anim_node

---Initial scale of anim_node
-- @tfield vector3 start_scale

---Initial pos of anim_node
-- @tfield vector3 start_pos

---Initial pos of anim_node
-- @tfield vector3 pos

---Params to click callbacks
-- @tfield any params

---Druid hover logic component
-- @tfield druid.hover hover

---Restriction zone
-- @tfield[opt] node click_zone


local Event = require("druid.event")
local const = require("druid.const")
Expand Down Expand Up @@ -132,7 +157,7 @@ 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 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
Expand All @@ -141,7 +166,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 Button:on_style_change(style)
function Button.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
Expand All @@ -156,12 +181,12 @@ end


--- Component init function
-- @function button:init
-- @tparam druid.button self
-- @tparam node node Gui node
-- @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 Button:init(node, callback, params, anim_node)
function Button.init(self, node, callback, params, anim_node)
self.druid = self:get_druid()
self.node = self:get_node(node)

Expand All @@ -188,7 +213,7 @@ function Button:init(node, callback, params, anim_node)
end


function Button:on_input(action_id, action)
function Button.on_input(self, action_id, action)
if not is_input_match(self, action_id) then
return false
end
Expand Down Expand Up @@ -257,16 +282,16 @@ function Button:on_input(action_id, action)
end


function Button:on_input_interrupt()
function Button.on_input_interrupt(self)
self.can_action = false
end


--- Set enabled button component state
-- @function button:set_enabled
-- @tparam druid.button self
-- @tparam bool state Enabled state
-- @treturn druid.button Current button instance
function Button:set_enabled(state)
function Button.set_enabled(self, state)
self.disabled = not state
self.hover:set_enabled(state)
self.style.on_set_enabled(self, self.node, state)
Expand All @@ -276,19 +301,19 @@ end


--- Return button enabled state
-- @function button:is_enabled
-- @tparam druid.button self
-- @treturn bool True, if button is enabled
function Button:is_enabled()
function Button.is_enabled(self)
return not self.disabled
end


--- Strict button click area. Useful for
-- no click events outside stencil node
-- @function button:set_click_zone
-- @tparam druid.button self
-- @tparam node zone Gui node
-- @treturn druid.button Current button instance
function Button:set_click_zone(zone)
function Button.set_click_zone(self, zone)
self.click_zone = self:get_node(zone)
self.hover:set_click_zone(zone)

Expand All @@ -297,20 +322,20 @@ end


--- Set key-code to trigger this button
-- @function button:set_key_trigger
-- @tparam druid.button self
-- @tparam hash key The action_id of the key
-- @treturn druid.button Current button instance
function Button:set_key_trigger(key)
function Button.set_key_trigger(self, key)
self.key_trigger = hash(key)

return self
end


--- Get key-code to trigger this button
-- @function button:get_key_trigger
-- @tparam druid.button self
-- @treturn hash The action_id of the key
function Button:get_key_trigger()
function Button.get_key_trigger(self)
return self.key_trigger
end

Expand Down
2 changes: 2 additions & 0 deletions settings_deployer
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/bash
use_latest_bob=false
enable_incremental_version=true
bob_sha="173:fe2b689302e79b7cf8c0bc7d934f23587b268c8a"

0 comments on commit fbef0cb

Please sign in to comment.