diff --git a/annotations.lua b/annotations.lua index cd3b198..e41d6a1 100644 --- a/annotations.lua +++ b/annotations.lua @@ -1,15 +1,12 @@ ---@class druid ---@field checkbox druid.checkbox Submodule ---@field checkbox_group druid.checkbox_group Submodule ----@field drag druid.drag Submodule ---@field dynamic_grid druid.dynamic_grid Submodule ---@field helper druid.helper Submodule ----@field hover druid.hover Submodule ---@field input druid.input Submodule ---@field lang_text druid.lang_text Submodule ---@field progress druid.progress Submodule ---@field radio_group druid.radio_group Submodule ----@field scroll druid.scroll Submodule ---@field slider druid.slider Submodule ---@field static_grid druid.static_grid Submodule ---@field swipe druid.swipe Submodule @@ -114,29 +111,22 @@ ---@field checkboxes field Array of checkbox components ---@class druid.drag : druid.base_component ----@field Events druid.drag.Events Component events ----@field Fields druid.drag.Fields Components fields ----@field Style druid.drag.Style Component style params. ----@field init fun(node:node, on_drag_callback:function) Drag component constructor ----@field set_click_zone fun(zone:node) Strict drag click area. +---@field can_x bool Is drag component process vertical dragging. +---@field can_y bool Is drag component process horizontal. +---@field is_drag bool Is component now dragging +---@field is_touch bool Is component now touching +---@field on_drag druid_event on drag progress callback(self, dx, dy) +---@field on_drag_end druid_event Event on drag end callback(self) +---@field on_drag_start druid_event Event on drag start callback(self) +---@field on_touch_end druid_event Event on touch end callback(self) +---@field on_touch_start druid_event Event on touch start callback(self) +---@field style druid.drag.style Component style params. +---@field x number Current touch x position +---@field y number Current touch y position +---@field init fun(self:druid.drag, node:node, on_drag_callback:function) Drag component constructor +---@field set_click_zone fun(self:druid.drag, zone:node) Strict drag click area. ----@class druid.drag.Events ----@field on_drag field (self, dx, dy) Event on drag progress ----@field on_drag_end field (self) Event on drag end ----@field on_drag_start field (self) Event on drag start ----@field on_touch_end field (self) Event on touch end ----@field on_touch_start field (self) Event on touch start - ----@class druid.drag.Fields ----@field can_x field Is drag component process vertical dragging. Default - true ----@field can_y field Is drag component process horizontal. Default - true ----@field is_drag field Is component now dragging ----@field is_touch field Is component now touching ----@field touch_start_pos field Touch start position ----@field x field Current touch x position ----@field y field Current touch y position - ----@class druid.drag.Style +---@class druid.drag.style ---@field DRAG_DEADZONE field Distance in pixels to start dragging ---@class druid.dynamic_grid : druid.base_component @@ -178,17 +168,13 @@ ---@field is_web fun() Check if device is HTML5 ---@class druid.hover : druid.base_component ----@field Events druid.hover.Events Component events ----@field init fun(node:node, on_hover_callback:function) Component init function ----@field is_enabled fun():bool Return current hover enabled state ----@field set_click_zone fun(zone:node) Strict hover click area. ----@field set_enabled fun(state:bool) Set enable state of hover component. ----@field set_hover fun(state:bool) Set hover state ----@field set_mouse_hover fun(state:bool) Set mouse hover state - ----@class druid.hover.Events ----@field on_hover field On hover callback (Touch pressed) ----@field on_mouse_hover field On mouse hover callback (Touch over without action_id) +---@field on_hover druid_event On hover callback(self, state) +---@field init fun(self:druid.hover, node:node, on_hover_callback:function) Component init function +---@field is_enabled fun(self:druid.hover):bool Return current hover enabled state +---@field set_click_zone fun(self:druid.hover, zone:node) Strict hover click area. +---@field set_enabled fun(self:druid.hover, state:bool) Set enable state of hover component. +---@field set_hover fun(self:druid.hover, state:bool) Set hover state +---@field set_mouse_hover fun(self:druid.hover, state:bool) Set mouse hover state ---@class druid.input : druid.base_component ---@field Events druid.input.Events Component events @@ -279,44 +265,37 @@ ---@field checkboxes field Array of checkbox components ---@class druid.scroll : druid.base_component ----@field Events druid.scroll.Events Component events ----@field Fields druid.scroll.Fields Component fields ----@field Style druid.scroll.Style Component style params. ----@field Scroll:_cancel_animate fun() Cancel animation on other animation or input touch ----@field bind_grid fun(Druid:druid.static_grid|druid.dynamic_grid):druid.scroll Bind the grid component (Static or Dynamic) to recalculate scroll size on grid changes ----@field get_percent fun():vector3 Return current scroll progress status. ----@field get_scroll_size fun():vector3 Return vector of scroll size with width and height. ----@field init fun(view_node:node, content_node:node) Scroll constructor. ----@field is_inert fun():bool Return if scroll have inertion. ----@field scroll_to fun(vector3:point, is_instant:bool) Start scroll to target point. ----@field scroll_to_index fun(index:number, skip_cb:bool) Scroll to item in scroll by point index. ----@field scroll_to_percent fun(vector3:point, is_instant:bool) Start scroll to target scroll percent ----@field set_extra_stretch_size fun(stretch_size:number):druid.scroll Set extra size for scroll stretching. ----@field set_horizontal_scroll fun(state:bool):druid.scroll Lock or unlock horizontal scroll ----@field set_inert fun(state:bool):druid.scroll Enable or disable scroll inert. ----@field set_points fun(points:table):druid.scroll Set points of interest. ----@field set_size fun(size:vector3):druid.scroll Set scroll content size. ----@field set_vertical_scroll fun(state:bool):druid.scroll Lock or unlock vertical scroll +---@field available_pos vector4 Available position for content node: (min_x, max_y, max_x, min_y) +---@field available_size vector3 Size of available positions: (width, height, 0) +---@field content_node node Scroll content node +---@field drag Drag Drag Druid component +---@field inertion vector3 Current inert speed +---@field is_inert bool Flag, if scroll now moving by inertion +---@field on_point_scroll druid_event On scroll_to_index function callback +---@field on_scroll druid_event On scroll move callback +---@field on_scroll_to druid_event On scroll_to function callback(self, target, is_instant) +---@field position vector3 Current scroll posisition +---@field selected number Current index of points of interests +---@field style druid.scroll.style Component style params. +---@field target_position vector3 Current scroll target position +---@field view_node node Scroll view node +---@field _cancel_animate fun(self:unknown) Cancel animation on other animation or input touch +---@field bind_grid fun(self:druid.scroll, grid:StaticGrid|DynamicGrid):druid.scroll Bind the grid component (Static or Dynamic) to recalculate scroll size on grid changes +---@field get_percent fun(self:druid.scroll):vector3 Return current scroll progress status. +---@field get_scroll_size fun(self:druid.scroll):vector3 Return vector of scroll size with width and height. +---@field init fun(self:druid.scroll, view_node:node, content_node:node) Scroll constructor +---@field is_inert fun(self:druid.scroll):bool Return if scroll have inertion. +---@field scroll_to fun(self:druid.scroll, point:vector3, is_instant:bool) Start scroll to target point. +---@field scroll_to_index fun(self:druid.scroll, index:number, skip_cb:bool) Scroll to item in scroll by point index. +---@field scroll_to_percent fun(self:druid.scroll, percent:vector3, is_instant:bool) Start scroll to target scroll percent +---@field set_extra_stretch_size fun(self:druid.scroll, stretch_size:number):druid.scroll Set extra size for scroll stretching. +---@field set_horizontal_scroll fun(self:druid.scroll, state:bool):druid.scroll Lock or unlock horizontal scroll +---@field set_inert fun(self:druid.scroll, state:bool):druid.scroll Enable or disable scroll inert. +---@field set_points fun(self:druid.scroll, points:table):druid.scroll Set points of interest. +---@field set_size fun(self:druid.scroll, size:vector3):druid.scroll Set scroll content size. +---@field set_vertical_scroll fun(self:druid.scroll, state:bool):druid.scroll Lock or unlock vertical scroll ----@class druid.scroll.Events ----@field on_point_scroll field On scroll_to_index function callback ----@field on_scroll field On scroll move callback ----@field on_scroll_to field On scroll_to function callback - ----@class druid.scroll.Fields ----@field Current field index of points of interests ----@field available_pos field Available position for content node: (min_x, max_y, max_x, min_y) ----@field available_size field Size of available positions: (width, height, 0) ----@field content_node field Scroll content node ----@field drag field Drag component ----@field inertion field Current inert speed ----@field is_animate field Flag, if scroll now animating by gui.animate ----@field is_inert field Flag, if scroll now moving by inertion ----@field position field Current scroll posisition ----@field target_position field Current scroll target position ----@field view_node field Scroll view node - ----@class druid.scroll.Style +---@class druid.scroll.style ---@field ANIM_SPEED field Scroll gui.animation speed for scroll_to function ---@field BACK_SPEED field Scroll back returning lerp speed ---@field EXTRA_STRETCH_SIZE field extra size in pixels outside of scroll (stretch effect) diff --git a/druid/base/drag.lua b/druid/base/drag.lua index 6e3e17e..2eef901 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -2,27 +2,46 @@ -- Drag have correct handling for multitouch and swap -- touched while dragging. Drag will be processed even -- the cursor is outside of node, if drag is already started --- @module druid.drag +-- @module Drag -- @within BaseComponent -- @alias druid.drag ---- Component events --- @table Events --- @tfield druid_event on_touch_start (self) Event on touch start --- @tfield druid_event on_touch_end (self) Event on touch end --- @tfield druid_event on_drag_start (self) Event on drag start --- @tfield druid_event on_drag (self, dx, dy) Event on drag progress --- @tfield druid_event on_drag_end (self) Event on drag end +--- Event on touch start callback(self) +-- @tfield druid_event on_touch_start + +--- Event on touch end callback(self) +-- @tfield druid_event on_touch_end + +--- Event on drag start callback(self) +-- @tfield druid_event on_drag_start + +--- on drag progress callback(self, dx, dy) +-- @tfield druid_event on_drag Event + +--- Event on drag end callback(self) +-- @tfield druid_event on_drag_end + +--- Is component now touching +-- @tfield bool is_touch + +--- Is component now dragging +-- @tfield bool is_drag + +--- Is drag component process vertical dragging. Default - true +-- @tfield bool can_x + +--- Is drag component process horizontal. Default - true +-- @tfield bool can_y + +--- Current touch x position +-- @tfield number x + +--- Current touch y position +-- @tfield number y + +--- Touch start position +-- @tfield vector3 touch_start_pos ---- Components fields --- @table Fields --- @tfield bool is_touch Is component now touching --- @tfield bool is_drag Is component now dragging --- @tfield bool can_x Is drag component process vertical dragging. Default - true --- @tfield bool can_y Is drag component process horizontal. Default - true --- @tfield number x Current touch x position --- @tfield number y Current touch y position --- @tfield vector3 touch_start_pos Touch start position local Event = require("druid.event") local const = require("druid.const") @@ -129,19 +148,19 @@ 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=10] number DRAG_DEADZONE Distance in pixels to start dragging -function Drag:on_style_change(style) +function Drag.on_style_change(self, style) self.style = {} self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10 end --- Drag component constructor +-- @tparam Drag self -- @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 Drag:init(node, on_drag_callback) +function Drag.init(self, node, on_drag_callback) self.node = self:get_node(node) self.dx = 0 @@ -165,14 +184,14 @@ function Drag:init(node, on_drag_callback) end -function Drag:on_input_interrupt() +function Drag.on_input_interrupt(self) if self.is_drag or self.is_touch then end_touch(self) end end -function Drag:on_input(action_id, action) +function Drag.on_input(self, action_id, action) if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then return false end @@ -243,9 +262,9 @@ end --- Strict drag click area. Useful for -- restrict events outside stencil node --- @function drag:set_click_zone +-- @tparam Drag self -- @tparam node zone Gui node -function Drag:set_click_zone(zone) +function Drag.set_click_zone(self, zone) self.click_zone = self:get_node(zone) end diff --git a/druid/base/hover.lua b/druid/base/hover.lua index bb13273..4d61461 100644 --- a/druid/base/hover.lua +++ b/druid/base/hover.lua @@ -1,12 +1,14 @@ --- Component to handle hover node interaction --- @module druid.hover +-- @module Hover -- @within BaseComponent -- @alias druid.hover ---- Component events --- @table Events --- @tfield druid_event on_hover On hover callback (Touch pressed) --- @tfield druid_event on_mouse_hover On mouse hover callback (Touch over without action_id) +--- On hover callback(self, state) +-- @tfield druid_event on_hover + +--- On mouse hover callback(self, state) +-- @tfield druid_event on_mouse_hover + local Event = require("druid.event") local const = require("druid.const") @@ -17,10 +19,10 @@ local Hover = component.create("hover", { const.ON_INPUT }) --- Component init function --- @function hover:init +-- @tparam Hover self -- @tparam node node Gui node -- @tparam function on_hover_callback Hover callback -function Hover:init(node, on_hover_callback) +function Hover.init(self, node, on_hover_callback) self.node = self:get_node(node) self._is_hovered = false @@ -33,7 +35,7 @@ function Hover:init(node, on_hover_callback) end -function Hover:on_input(action_id, action) +function Hover.on_input(self, action_id, action) if action_id ~= const.ACTION_TOUCH and action_id ~= nil then return false end @@ -66,15 +68,15 @@ function Hover:on_input(action_id, action) end -function Hover:on_input_interrupt() +function Hover.on_input_interrupt(self) self:set_hover(false) end --- Set hover state --- @function hover:set_hover +-- @tparam Hover self -- @tparam bool state The hover state -function Hover:set_hover(state) +function Hover.set_hover(self, state) if self._is_hovered ~= state then self._is_hovered = state self.on_hover:trigger(self:get_context(), state) @@ -82,9 +84,9 @@ function Hover:set_hover(state) end --- Set mouse hover state --- @function hover:set_mouse_hover +-- @tparam Hover self -- @tparam bool state The mouse hover state -function Hover:set_mouse_hover(state) +function Hover.set_mouse_hover(self, state) if self._is_mouse_hovered ~= state then self._is_mouse_hovered = state self.on_mouse_hover:trigger(self:get_context(), state) @@ -94,9 +96,9 @@ end --- Strict hover click area. Useful for -- no click events outside stencil node --- @function hover:set_click_zone +-- @tparam Hover self -- @tparam node zone Gui node -function Hover:set_click_zone(zone) +function Hover.set_click_zone(self, zone) self.click_zone = self:get_node(zone) end @@ -104,9 +106,9 @@ end --- Set enable state of hover component. -- If hover is not enabled, it will not generate -- any hover events --- @function hover:set_enabled +-- @tparam Hover self -- @tparam bool state The hover enabled state -function Hover:set_enabled(state) +function Hover.set_enabled(self, state) self._is_enabled = state if not state then @@ -121,9 +123,9 @@ end --- Return current hover enabled state --- @function hover:is_enabled +-- @tparam Hover self -- @treturn bool The hover enabled state -function Hover:is_enabled() +function Hover.is_enabled(self) return self._is_enabled end diff --git a/druid/base/scroll.lua b/druid/base/scroll.lua index c466c48..3646984 100644 --- a/druid/base/scroll.lua +++ b/druid/base/scroll.lua @@ -5,29 +5,53 @@ -- Setup initial scroll size by changing scroll parent size. If scroll parent -- size will be less than scroll_input size, no scroll is available. For scroll -- parent size should be more than input size --- @module druid.scroll +-- @module Scroll -- @within BaseComponent -- @alias druid.scroll ---- Component events --- @table Events --- @tfield druid_event on_scroll On scroll move callback --- @tfield druid_event on_scroll_to On scroll_to function callback --- @tfield druid_event on_point_scroll On scroll_to_index function callback ---- Component fields --- @table Fields --- @tfield node view_node Scroll view node --- @tfield node content_node Scroll content node --- @tfield bool is_inert Flag, if scroll now moving by inertion --- @tfield vector3 inertion Current inert speed --- @tfield vector3 position Current scroll posisition --- @tfield vector3 target_position Current scroll target position --- @tfield vector4 available_pos Available position for content node: (min_x, max_y, max_x, min_y) --- @tfield vector3 available_size Size of available positions: (width, height, 0) --- @tfield druid.drag drag Drag component --- @tfield[opt] selected Current index of points of interests --- @tfield bool is_animate Flag, if scroll now animating by gui.animate +--- On scroll move callback +-- @tfield druid_event on_scroll(self, position) + +--- On scroll_to function callback(self, target, is_instant) +-- @tfield druid_event on_scroll_to + +--- On scroll_to_index function callback +-- @tfield druid_event on_point_scroll(self, index, point) + +--- Scroll view node +-- @tfield node view_node + +--- Scroll content node +-- @tfield node content_node + +--- Flag, if scroll now moving by inertion +-- @tfield bool is_inert + +--- Current inert speed +-- @tfield vector3 inertion + +--- Current scroll posisition +-- @tfield vector3 position + +--- Current scroll target position +-- @tfield vector3 target_position + +--- Available position for content node: (min_x, max_y, max_x, min_y) +-- @tfield vector4 available_pos + +--- Size of available positions: (width, height, 0) +-- @tfield vector3 available_size + +--- Drag Druid component +-- @tfield Drag drag + +--- Current index of points of interests +-- @tfield[opt] number selected + +--- Flag, if scroll now animating by gui.animate +-- @tfield bool is_animate + local Event = require("druid.event") local const = require("druid.const") @@ -66,7 +90,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] 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 @@ -76,7 +100,7 @@ end -- @tfield[opt=0.2] number ANIM_SPEED Scroll gui.animation speed for scroll_to function -- @tfield[opt=0] number EXTRA_STRETCH_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 Scroll:on_style_change(style) +function Scroll.on_style_change(self, style) self.style = {} self.style.EXTRA_STRETCH_SIZE = style.EXTRA_STRETCH_SIZE or 0 self.style.ANIM_SPEED = style.ANIM_SPEED or 0.2 @@ -96,11 +120,11 @@ function Scroll:on_style_change(style) end ---- Scroll constructor. --- @function scroll:init +--- Scroll constructor +-- @tparam Scroll self -- @tparam node view_node GUI view scroll node -- @tparam node content_node GUI content scroll node -function Scroll:init(view_node, content_node) +function Scroll.init(self, view_node, content_node) self.druid = self:get_druid() self.view_node = self:get_node(view_node) @@ -130,12 +154,12 @@ function Scroll:init(view_node, content_node) end -function Scroll:on_layout_change() +function Scroll.on_layout_change(self) gui.set_position(self.content_node, self.position) end -function Scroll:update(dt) +function Scroll.update(self, dt) if self.drag.is_drag then self:_update_hand_scroll(dt) else @@ -144,18 +168,18 @@ function Scroll:update(dt) end -function Scroll:on_remove() +function Scroll.on_remove(self) self:bind_grid(nil) end --- Start scroll to target point. --- @function scroll:scroll_to --- @tparam point vector3 Target point +-- @tparam Scroll self +-- @tparam vector3 point Target point -- @tparam[opt] bool is_instant Instant scroll flag -- @usage scroll:scroll_to(vmath.vector3(0, 50, 0)) -- @usage scroll:scroll_to(vmath.vector3(0), true) -function Scroll:scroll_to(point, is_instant) +function Scroll.scroll_to(self, point, is_instant) local b = self.available_pos local target = vmath.vector3(-point.x, -point.y, 0) target.x = helper.clamp(target.x, b.x, b.z) @@ -181,10 +205,10 @@ end --- Scroll to item in scroll by point index. --- @function scroll:scroll_to_index +-- @tparam Scroll self -- @tparam number index Point index -- @tparam[opt] bool skip_cb If true, skip the point callback -function Scroll:scroll_to_index(index, skip_cb) +function Scroll.scroll_to_index(self, index, skip_cb) if not self.points then return end @@ -204,11 +228,11 @@ end --- Start scroll to target scroll percent --- @function scroll:scroll_to_percent --- @tparam point vector3 target percent +-- @tparam Scroll self +-- @tparam vector3 percent target percent -- @tparam[opt] bool is_instant instant scroll flag -- @usage scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0)) -function Scroll:scroll_to_percent(percent, is_instant) +function Scroll.scroll_to_percent(self, percent, is_instant) local border = self.available_pos local pos = vmath.vector3( @@ -223,9 +247,9 @@ end --- Return current scroll progress status. -- Values will be in [0..1] interval --- @function scroll:get_percent +-- @tparam Scroll self -- @treturn vector3 New vector with scroll progress values -function Scroll:get_percent() +function Scroll.get_percent(self) local x_perc = 1 - inverse_lerp(self.available_pos.x, self.available_pos.z, self.position.x) local y_perc = inverse_lerp(self.available_pos.w, self.available_pos.y, self.position.y) @@ -235,10 +259,10 @@ end --- Set scroll content size. -- It will change content gui node size --- @function scroll:set_size +-- @tparam Scroll self -- @tparam vector3 size The new size for content node -- @treturn druid.scroll Current scroll instance -function Scroll:set_size(size) +function Scroll.set_size(self, size) gui.set_size(self.content_node, size) self:_update_size() @@ -249,10 +273,10 @@ end --- Enable or disable scroll inert. -- If disabled, scroll through points (if exist) -- If no points, just simple drag without inertion --- @function scroll:set_inert +-- @tparam Scroll self -- @tparam bool state Inert scroll state -- @treturn druid.scroll Current scroll instance -function Scroll:set_inert(state) +function Scroll.set_inert(self, state) self._is_inert = state return self @@ -260,19 +284,19 @@ end --- Return if scroll have inertion. --- @function scroll:is_inert +-- @tparam Scroll self -- @treturn bool If scroll have inertion -function Scroll:is_inert() +function Scroll.is_inert(self) return self._is_inert end --- Set extra size for scroll stretching. -- Set 0 to disable stretching effect --- @function scroll:set_extra_stretch_size +-- @tparam Scroll self -- @tparam[opt=0] number stretch_size Size in pixels of additional scroll area -- @treturn druid.scroll Current scroll instance -function Scroll:set_extra_stretch_size(stretch_size) +function Scroll.set_extra_stretch_size(self, stretch_size) self.style.EXTRA_STRETCH_SIZE = stretch_size or 0 self:_update_size() @@ -281,19 +305,19 @@ end --- Return vector of scroll size with width and height. --- @function scroll:get_scroll_size +-- @tparam Scroll self -- @treturn vector3 Available scroll size -function Scroll:get_scroll_size() +function Scroll.get_scroll_size(self) return self.available_size end --- Set points of interest. -- Scroll will always centered on closer points --- @function scroll:set_points +-- @tparam Scroll self -- @tparam table points Array of vector3 points -- @treturn druid.scroll Current scroll instance -function Scroll:set_points(points) +function Scroll.set_points(self, points) self.points = points table.sort(self.points, function(a, b) @@ -307,10 +331,10 @@ end --- Lock or unlock horizontal scroll --- @function scroll:set_horizontal_scroll +-- @tparam Scroll self -- @tparam bool state True, if horizontal scroll is enabled -- @treturn druid.scroll Current scroll instance -function Scroll:set_horizontal_scroll(state) +function Scroll.set_horizontal_scroll(self, state) self._is_horizontal_scroll = state self.drag.can_x = self.available_size.x > 0 and state return self @@ -318,10 +342,10 @@ end --- Lock or unlock vertical scroll --- @function scroll:set_vertical_scroll +-- @tparam Scroll self -- @tparam bool state True, if vertical scroll is enabled -- @treturn druid.scroll Current scroll instance -function Scroll:set_vertical_scroll(state) +function Scroll.set_vertical_scroll(self, state) self._is_vertical_scroll = state self.drag.can_y = self.available_size.y > 0 and state return self @@ -331,10 +355,10 @@ end --- Bind the grid component (Static or Dynamic) to recalculate -- scroll size on grid changes --- @function scroll:bind_grid --- @tparam druid.static_grid|druid.dynamic_grid Druid grid component +-- @tparam Scroll self +-- @tparam StaticGrid|DynamicGrid grid Druid grid component -- @treturn druid.scroll Current scroll instance -function Scroll:bind_grid(grid) +function Scroll.bind_grid(self, grid) if self._grid_on_change then self._grid_on_change:unsubscribe(self._grid_on_change_callback) @@ -356,7 +380,7 @@ function Scroll:bind_grid(grid) end -function Scroll:_on_scroll_drag(dx, dy) +function Scroll._on_scroll_drag(self, dx, dy) local t = self.target_position local b = self.available_pos local eb = self.available_pos_extra @@ -397,7 +421,7 @@ function Scroll:_on_scroll_drag(dx, dy) end -function Scroll:_check_soft_zone() +function Scroll._check_soft_zone(self) local target = self.target_position local border = self.available_pos local speed = self.style.BACK_SPEED @@ -422,7 +446,7 @@ end --- Cancel animation on other animation or input touch -function Scroll:_cancel_animate() +function Scroll._cancel_animate(self) if self.is_animate then self.target_position = gui.get_position(self.content_node) self.position.x = self.target_position.x @@ -433,7 +457,7 @@ function Scroll:_cancel_animate() end -function Scroll:_set_scroll_position(position) +function Scroll._set_scroll_position(self, position) local available_extra = self.available_pos_extra position.x = helper.clamp(position.x, available_extra.x, available_extra.z) position.y = helper.clamp(position.y, available_extra.w, available_extra.y) @@ -452,7 +476,7 @@ end -- if no inert, scroll to next point by scroll direction -- if inert, find next point by scroll director -- @local -function Scroll:_check_points() +function Scroll._check_points(self) if not self.points then return end @@ -504,7 +528,7 @@ function Scroll:_check_points() end -function Scroll:_check_threshold() +function Scroll._check_threshold(self) local is_stopped = false if self.inertion.x ~= 0 and math.abs(self.inertion.x) < self.style.INERT_THRESHOLD then @@ -522,7 +546,7 @@ function Scroll:_check_threshold() end -function Scroll:_update_free_scroll(dt) +function Scroll._update_free_scroll(self, dt) local target = self.target_position if self._is_inert and (self.inertion.x ~= 0 or self.inertion.y ~= 0) then @@ -543,7 +567,7 @@ function Scroll:_update_free_scroll(dt) end -function Scroll:_update_hand_scroll(dt) +function Scroll._update_hand_scroll(self, dt) local dx = self.target_position.x - self.position.x local dy = self.target_position.y - self.position.y @@ -554,7 +578,7 @@ function Scroll:_update_hand_scroll(dt) end -function Scroll:_on_touch_start() +function Scroll._on_touch_start(self) self.inertion.x = 0 self.inertion.y = 0 self.target_position.x = self.position.x @@ -562,12 +586,12 @@ function Scroll:_on_touch_start() end -function Scroll:_on_touch_end() +function Scroll._on_touch_end(self) self:_check_threshold() end -function Scroll:_update_size() +function Scroll._update_size(self) local view_border = helper.get_border(self.view_node) local view_size = vmath.mul_per_elem(gui.get_size(self.view_node), gui.get_scale(self.view_node)) diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 4f0a6b2..a2b8898 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -18,13 +18,14 @@ -- @see druid.progress -- @see druid.static_grid -- @see druid.dynamic_grid --- @see druid.scroll +-- @see Scroll -- @see druid.slider -- @see druid.checkbox -- @see druid.checkbox_group -- @see druid.radio_group -- @see druid.swipe --- @see druid.drag +-- @see Drag +-- @see Hover local const = require("druid.const") local helper = require("druid.helper")