mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update
This commit is contained in:
parent
2c2789f1f9
commit
c3b132187a
@ -16,14 +16,11 @@ function M:init(callback, params)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param action_id string
|
---@param action_id hash
|
||||||
---@param action table
|
---@param action table
|
||||||
|
---@return boolean
|
||||||
function M:on_input(action_id, action)
|
function M:on_input(action_id, action)
|
||||||
if not action.released then
|
if action.released and (action_id == const.ACTION_BACK or action_id == const.ACTION_BACKSPACE) then
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if action_id == const.ACTION_BACK or action_id == const.ACTION_BACKSPACE then
|
|
||||||
self.on_back:trigger(self:get_context(), self.params)
|
self.on_back:trigger(self:get_context(), self.params)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -211,7 +211,7 @@ end
|
|||||||
|
|
||||||
---Get button enabled state.
|
---Get button enabled state.
|
||||||
---By default all Buttons is enabled on creating.
|
---By default all Buttons is enabled on creating.
|
||||||
---@return boolean @True, if button is enabled now, False overwise
|
---@return boolean is_enabled True, if button is enabled now, False overwise
|
||||||
function M:is_enabled()
|
function M:is_enabled()
|
||||||
return not self.disabled
|
return not self.disabled
|
||||||
end
|
end
|
||||||
|
@ -1,62 +1,3 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
|
||||||
|
|
||||||
--- Component to handle drag action on node.
|
|
||||||
-- 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
|
|
||||||
--
|
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_drag" target="_blank"><b>Example Link</b></a>
|
|
||||||
-- @module Drag
|
|
||||||
-- @within BaseComponent
|
|
||||||
-- @alias druid.drag
|
|
||||||
|
|
||||||
--- Drag node
|
|
||||||
-- @tfield node node
|
|
||||||
|
|
||||||
--- Event on touch start callback(self)
|
|
||||||
-- @tfield event on_touch_start event
|
|
||||||
|
|
||||||
--- Event on touch end callback(self)
|
|
||||||
-- @tfield event on_touch_end event
|
|
||||||
|
|
||||||
--- Event on drag start callback(self, touch)
|
|
||||||
-- @tfield event on_drag_start event
|
|
||||||
|
|
||||||
--- on drag progress callback(self, dx, dy, total_x, total_y, touch)
|
|
||||||
-- @tfield event on_drag Event event
|
|
||||||
|
|
||||||
--- Event on drag end callback(self, total_x, total_y, touch)
|
|
||||||
-- @tfield event on_drag_end event
|
|
||||||
|
|
||||||
--- Is component now touching
|
|
||||||
-- @tfield boolean is_touch
|
|
||||||
|
|
||||||
--- Is component now dragging
|
|
||||||
-- @tfield boolean is_drag
|
|
||||||
|
|
||||||
--- Is drag component process vertical dragging. Default - true
|
|
||||||
-- @tfield boolean can_x
|
|
||||||
|
|
||||||
--- Is drag component process horizontal. Default - true
|
|
||||||
-- @tfield boolean can_y
|
|
||||||
|
|
||||||
--- Current touch x position
|
|
||||||
-- @tfield number x
|
|
||||||
|
|
||||||
--- Current touch y position
|
|
||||||
-- @tfield number y
|
|
||||||
|
|
||||||
--- Current touch x screen position
|
|
||||||
-- @tfield number screen_x
|
|
||||||
|
|
||||||
--- Current touch y screen position
|
|
||||||
-- @tfield number screen_y
|
|
||||||
|
|
||||||
--- Touch start position
|
|
||||||
-- @tfield vector3 touch_start_pos
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
local event = require("event.event")
|
local event = require("event.event")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
@ -150,8 +91,12 @@ local function process_touch(self, touch)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current touch action from action input data
|
---Return current touch action from action input data
|
||||||
-- If touch_id stored - return exact this touch action
|
---If touch_id stored - return exact this touch action
|
||||||
|
---@param action_id hash Action id from on_input
|
||||||
|
---@param action table Action from on_input
|
||||||
|
---@param touch_id number Touch id
|
||||||
|
---@return table|nil Touch action
|
||||||
local function find_touch(action_id, action, touch_id)
|
local function find_touch(action_id, action, touch_id)
|
||||||
local act = helper.is_mobile() and const.ACTION_MULTITOUCH or const.ACTION_TOUCH
|
local act = helper.is_mobile() and const.ACTION_MULTITOUCH or const.ACTION_TOUCH
|
||||||
|
|
||||||
@ -173,8 +118,11 @@ local function find_touch(action_id, action, touch_id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Process on touch release. We should to find, if any other
|
---Process on touch release. We should to find, if any other
|
||||||
-- touches exists to switch to another touch.
|
---touches exists to switch to another touch.
|
||||||
|
---@param self druid.drag
|
||||||
|
---@param action_id hash Action id from on_input
|
||||||
|
---@param action table Action from on_input
|
||||||
local function on_touch_release(self, action_id, action)
|
local function on_touch_release(self, action_id, action)
|
||||||
if #action.touch >= 2 then
|
if #action.touch >= 2 then
|
||||||
-- Find next unpressed touch
|
-- Find next unpressed touch
|
||||||
@ -199,12 +147,7 @@ local function on_touch_release(self, action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---@param style druid.drag.style
|
||||||
-- You can override this component styles params in druid styles table
|
|
||||||
-- or create your own style
|
|
||||||
-- @table style
|
|
||||||
-- @tfield number|nil DRAG_DEADZONE Distance in pixels to start dragging. Default: 10
|
|
||||||
-- @tfield boolean|nil NO_USE_SCREEN_KOEF If screen aspect ratio affects on drag values. Default: false
|
|
||||||
function M:on_style_change(style)
|
function M:on_style_change(style)
|
||||||
self.style = {
|
self.style = {
|
||||||
DRAG_DEADZONE = style.DRAG_DEADZONE or 10,
|
DRAG_DEADZONE = style.DRAG_DEADZONE or 10,
|
||||||
@ -289,7 +232,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---@local
|
---@local
|
||||||
---@param action_id string
|
---@param action_id hash
|
||||||
---@param action table
|
---@param action table
|
||||||
function M:on_input(action_id, action)
|
function M:on_input(action_id, action)
|
||||||
if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then
|
if action_id ~= const.ACTION_TOUCH and action_id ~= const.ACTION_MULTITOUCH then
|
||||||
@ -388,7 +331,7 @@ function M:set_enabled(is_enabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---Check if Drag component is enabled
|
---Check if Drag component is capture input
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M:is_enabled()
|
function M:is_enabled()
|
||||||
return self._is_enabled
|
return self._is_enabled
|
||||||
|
@ -1,31 +1,17 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
|
||||||
|
|
||||||
--- Component to handle hover node interaction
|
|
||||||
-- @module Hover
|
|
||||||
-- @within BaseComponent
|
|
||||||
-- @alias druid.hover
|
|
||||||
|
|
||||||
--- Hover node
|
|
||||||
-- @tfield node node
|
|
||||||
|
|
||||||
--- On hover callback(self, state, hover_instance)
|
|
||||||
-- @tfield event on_hover event
|
|
||||||
|
|
||||||
--- On mouse hover callback(self, state, hover_instance)
|
|
||||||
-- @tfield event on_mouse_hover event
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
local event = require("event.event")
|
local event = require("event.event")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
|
---@class druid.hover.style
|
||||||
|
---@field ON_HOVER_CURSOR string|nil Mouse hover style on node hover
|
||||||
|
---@field ON_MOUSE_HOVER_CURSOR string|nil Mouse hover style on node mouse hover
|
||||||
|
|
||||||
---@class druid.hover: druid.component
|
---@class druid.hover: druid.component
|
||||||
---@field node node
|
---@field node node
|
||||||
---@field on_hover event
|
---@field on_hover event
|
||||||
---@field on_mouse_hover event
|
---@field on_mouse_hover event
|
||||||
---@field style table
|
---@field style druid.hover.style
|
||||||
---@field click_zone node
|
---@field click_zone node
|
||||||
---@field private _is_hovered boolean|nil
|
---@field private _is_hovered boolean|nil
|
||||||
---@field private _is_mouse_hovered boolean|nil
|
---@field private _is_mouse_hovered boolean|nil
|
||||||
@ -34,7 +20,6 @@ local component = require("druid.component")
|
|||||||
local M = component.create("hover")
|
local M = component.create("hover")
|
||||||
|
|
||||||
|
|
||||||
--- The Hover constructor
|
|
||||||
---@param node node Gui node
|
---@param node node Gui node
|
||||||
---@param on_hover_callback function Hover callback
|
---@param on_hover_callback function Hover callback
|
||||||
---@param on_mouse_hover function On mouse hover callback
|
---@param on_mouse_hover function On mouse hover callback
|
||||||
@ -61,12 +46,7 @@ function M:on_late_init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---@param style druid.hover.style
|
||||||
-- You can override this component styles params in druid styles table
|
|
||||||
-- or create your own style
|
|
||||||
-- @table style
|
|
||||||
-- @tfield[opt] string ON_HOVER_CURSOR Mouse hover style on node hover
|
|
||||||
-- @tfield[opt] string ON_MOUSE_HOVER_CURSOR Mouse hover style on node mouse hover
|
|
||||||
function M:on_style_change(style)
|
function M:on_style_change(style)
|
||||||
self.style = {}
|
self.style = {}
|
||||||
self.style.ON_HOVER_CURSOR = style.ON_HOVER_CURSOR or nil
|
self.style.ON_HOVER_CURSOR = style.ON_HOVER_CURSOR or nil
|
||||||
@ -74,6 +54,9 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param action_id hash
|
||||||
|
---@param action table
|
||||||
|
---@return boolean
|
||||||
function M:on_input(action_id, action)
|
function M:on_input(action_id, action)
|
||||||
if action_id ~= const.ACTION_TOUCH and action_id ~= nil then
|
if action_id ~= const.ACTION_TOUCH and action_id ~= nil then
|
||||||
return false
|
return false
|
||||||
@ -113,7 +96,7 @@ function M:on_input_interrupt()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set hover state
|
---Set hover state
|
||||||
---@param state boolean|nil The hover state
|
---@param state boolean|nil The hover state
|
||||||
function M:set_hover(state)
|
function M:set_hover(state)
|
||||||
if self._is_hovered == state then
|
if self._is_hovered == state then
|
||||||
@ -129,14 +112,14 @@ function M:set_hover(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current hover state. True if touch action was on the node at current time
|
---Return current hover state. True if touch action was on the node at current time
|
||||||
---@return boolean The current hovered state
|
---@return boolean is_hovered The current hovered state
|
||||||
function M:is_hovered()
|
function M:is_hovered()
|
||||||
return self._is_hovered
|
return self._is_hovered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set mouse hover state
|
---Set mouse hover state
|
||||||
---@param state boolean|nil The mouse hover state
|
---@param state boolean|nil The mouse hover state
|
||||||
function M:set_mouse_hover(state)
|
function M:set_mouse_hover(state)
|
||||||
if self._is_mouse_hovered == state then
|
if self._is_mouse_hovered == state then
|
||||||
@ -152,15 +135,14 @@ function M:set_mouse_hover(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current hover state. True if nil action_id (usually desktop mouse) was on the node at current time
|
---Return current hover state. True if nil action_id (usually desktop mouse) was on the node at current time
|
||||||
---@return boolean The current hovered state
|
---@return boolean The current hovered state
|
||||||
function M:is_mouse_hovered()
|
function M:is_mouse_hovered()
|
||||||
return self._is_mouse_hovered
|
return self._is_mouse_hovered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Strict hover click area. Useful for
|
---Strict hover click area. Useful for no click events outside stencil node
|
||||||
-- no click events outside stencil node
|
|
||||||
---@param zone node|string|nil Gui node
|
---@param zone node|string|nil Gui node
|
||||||
function M:set_click_zone(zone)
|
function M:set_click_zone(zone)
|
||||||
if not zone then
|
if not zone then
|
||||||
@ -172,9 +154,9 @@ function M:set_click_zone(zone)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set enable state of hover component.
|
---Set enable state of hover component.
|
||||||
-- If hover is not enabled, it will not generate
|
---If hover is not enabled, it will not generate
|
||||||
-- any hover events
|
---any hover events
|
||||||
---@param state boolean|nil The hover enabled state
|
---@param state boolean|nil The hover enabled state
|
||||||
function M:set_enabled(state)
|
function M:set_enabled(state)
|
||||||
self._is_enabled = state
|
self._is_enabled = state
|
||||||
@ -190,7 +172,7 @@ function M:set_enabled(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current hover enabled state
|
---Return current hover enabled state
|
||||||
---@return boolean The hover enabled state
|
---@return boolean The hover enabled state
|
||||||
function M:is_enabled()
|
function M:is_enabled()
|
||||||
return self._is_enabled
|
return self._is_enabled
|
||||||
|
@ -51,7 +51,7 @@ local function inverse_lerp(min, max, current)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update vector with next conditions:
|
---Update vector with next conditions:
|
||||||
-- Field x have to <= field z
|
-- Field x have to <= field z
|
||||||
-- Field y have to <= field w
|
-- Field y have to <= field w
|
||||||
local function get_border_vector(vector, offset)
|
local function get_border_vector(vector, offset)
|
||||||
@ -69,7 +69,7 @@ local function get_border_vector(vector, offset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return size from scroll border vector4
|
---Return size from scroll border vector4
|
||||||
local function get_size_vector(vector)
|
local function get_size_vector(vector)
|
||||||
return vmath.vector3(vector.z - vector.x, vector.w - vector.y, 0)
|
return vmath.vector3(vector.z - vector.x, vector.w - vector.y, 0)
|
||||||
end
|
end
|
||||||
@ -99,7 +99,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The Scroll constructor
|
---The Scroll constructor
|
||||||
---@param view_node string|node GUI view scroll node
|
---@param view_node string|node GUI view scroll node
|
||||||
---@param content_node string|node GUI content scroll node
|
---@param content_node string|node GUI content scroll node
|
||||||
function M:init(view_node, content_node)
|
function M:init(view_node, content_node)
|
||||||
@ -180,7 +180,7 @@ function M:on_remove()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Start scroll to target point.
|
---Start scroll to target point.
|
||||||
---@param point vector3 Target point
|
---@param point vector3 Target point
|
||||||
---@param is_instant boolean|nil Instant scroll flag
|
---@param is_instant boolean|nil Instant scroll flag
|
||||||
-- @usage scroll:scroll_to(vmath.vector3(0, 50, 0))
|
-- @usage scroll:scroll_to(vmath.vector3(0, 50, 0))
|
||||||
@ -213,7 +213,7 @@ function M:scroll_to(point, is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Scroll to item in scroll by point index.
|
---Scroll to item in scroll by point index.
|
||||||
---@param index number Point index
|
---@param index number Point index
|
||||||
---@param skip_cb boolean|nil If true, skip the point callback
|
---@param skip_cb boolean|nil If true, skip the point callback
|
||||||
function M:scroll_to_index(index, skip_cb)
|
function M:scroll_to_index(index, skip_cb)
|
||||||
@ -235,7 +235,7 @@ function M:scroll_to_index(index, skip_cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Start scroll to target scroll percent
|
---Start scroll to target scroll percent
|
||||||
---@param percent vector3 target percent
|
---@param percent vector3 target percent
|
||||||
---@param is_instant boolean|nil instant scroll flag
|
---@param is_instant boolean|nil instant scroll flag
|
||||||
-- @usage scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0))
|
-- @usage scroll:scroll_to_percent(vmath.vector3(0.5, 0, 0))
|
||||||
@ -259,7 +259,7 @@ function M:scroll_to_percent(percent, is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current scroll progress status.
|
---Return current scroll progress status.
|
||||||
-- Values will be in [0..1] interval
|
-- Values will be in [0..1] interval
|
||||||
---@return vector3 New vector with scroll progress values
|
---@return vector3 New vector with scroll progress values
|
||||||
function M:get_percent()
|
function M:get_percent()
|
||||||
@ -270,7 +270,7 @@ function M:get_percent()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set scroll content size.
|
---Set scroll content size.
|
||||||
-- It will change content gui node size
|
-- It will change content gui node size
|
||||||
---@param size vector3 The new size for content node
|
---@param size vector3 The new size for content node
|
||||||
---@param offset vector3|nil Offset value to set, where content is starts
|
---@param offset vector3|nil Offset value to set, where content is starts
|
||||||
@ -286,7 +286,7 @@ function M:set_size(size, offset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new scroll view size in case the node size was changed.
|
---Set new scroll view size in case the node size was changed.
|
||||||
---@param size vector3 The new size for view node
|
---@param size vector3 The new size for view node
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
function M:set_view_size(size)
|
function M:set_view_size(size)
|
||||||
@ -299,7 +299,7 @@ function M:set_view_size(size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Refresh scroll view size
|
---Refresh scroll view size
|
||||||
function M:update_view_size()
|
function M:update_view_size()
|
||||||
self.view_size = helper.get_scaled_size(self.view_node)
|
self.view_size = helper.get_scaled_size(self.view_node)
|
||||||
self.view_border = helper.get_border(self.view_node)
|
self.view_border = helper.get_border(self.view_node)
|
||||||
@ -309,7 +309,7 @@ function M:update_view_size()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Enable or disable scroll inert.
|
---Enable or disable scroll inert.
|
||||||
-- If disabled, scroll through points (if exist)
|
-- If disabled, scroll through points (if exist)
|
||||||
-- If no points, just simple drag without inertion
|
-- If no points, just simple drag without inertion
|
||||||
---@param state boolean Inert scroll state
|
---@param state boolean Inert scroll state
|
||||||
@ -321,14 +321,14 @@ function M:set_inert(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return if scroll have inertion.
|
---Return if scroll have inertion.
|
||||||
---@return boolean @If scroll have inertion
|
---@return boolean @If scroll have inertion
|
||||||
function M:is_inert()
|
function M:is_inert()
|
||||||
return self._is_inert
|
return self._is_inert
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set extra size for scroll stretching.
|
---Set extra size for scroll stretching.
|
||||||
-- Set 0 to disable stretching effect
|
-- Set 0 to disable stretching effect
|
||||||
---@param stretch_size number|nil Size in pixels of additional scroll area
|
---@param stretch_size number|nil Size in pixels of additional scroll area
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
@ -340,14 +340,14 @@ function M:set_extra_stretch_size(stretch_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return vector of scroll size with width and height.
|
---Return vector of scroll size with width and height.
|
||||||
---@return vector3 Available scroll size
|
---@return vector3 Available scroll size
|
||||||
function M:get_scroll_size()
|
function M:get_scroll_size()
|
||||||
return self.available_size
|
return self.available_size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set points of interest.
|
---Set points of interest.
|
||||||
-- Scroll will always centered on closer points
|
-- Scroll will always centered on closer points
|
||||||
---@param points table Array of vector3 points
|
---@param points table Array of vector3 points
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
@ -364,7 +364,7 @@ function M:set_points(points)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Lock or unlock horizontal scroll
|
---Lock or unlock horizontal scroll
|
||||||
---@param state boolean True, if horizontal scroll is enabled
|
---@param state boolean True, if horizontal scroll is enabled
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
function M:set_horizontal_scroll(state)
|
function M:set_horizontal_scroll(state)
|
||||||
@ -374,7 +374,7 @@ function M:set_horizontal_scroll(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Lock or unlock vertical scroll
|
---Lock or unlock vertical scroll
|
||||||
---@param state boolean True, if vertical scroll is enabled
|
---@param state boolean True, if vertical scroll is enabled
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
function M:set_vertical_scroll(state)
|
function M:set_vertical_scroll(state)
|
||||||
@ -384,7 +384,7 @@ function M:set_vertical_scroll(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Check node if it visible now on scroll.
|
---Check node if it visible now on scroll.
|
||||||
-- Extra border is not affected. Return true for elements in extra scroll zone
|
-- Extra border is not affected. Return true for elements in extra scroll zone
|
||||||
---@param node node The node to check
|
---@param node node The node to check
|
||||||
---@return boolean True if node in visible scroll area
|
---@return boolean True if node in visible scroll area
|
||||||
@ -424,7 +424,7 @@ function M:is_node_in_view(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Bind the grid component (Static or Dynamic) to recalculate
|
---Bind the grid component (Static or Dynamic) to recalculate
|
||||||
-- scroll size on grid changes
|
-- scroll size on grid changes
|
||||||
---@param grid druid.grid|nil Druid grid component
|
---@param grid druid.grid|nil Druid grid component
|
||||||
---@return druid.scroll Current scroll instance
|
---@return druid.scroll Current scroll instance
|
||||||
@ -453,7 +453,7 @@ function M:bind_grid(grid)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Strict drag scroll area. Useful for
|
---Strict drag scroll area. Useful for
|
||||||
-- restrict events outside stencil node
|
-- restrict events outside stencil node
|
||||||
---@param node node|string Gui node
|
---@param node node|string Gui node
|
||||||
function M:set_click_zone(node)
|
function M:set_click_zone(node)
|
||||||
@ -560,7 +560,7 @@ function M:_set_scroll_position(position_x, position_y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Find closer point of interest
|
---Find closer point of interest
|
||||||
-- if no inert, scroll to next point by scroll direction
|
-- if no inert, scroll to next point by scroll direction
|
||||||
-- if inert, find next point by scroll director
|
-- if inert, find next point by scroll director
|
||||||
---@private
|
---@private
|
||||||
|
@ -1,87 +1,12 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
|
||||||
|
|
||||||
--- Component to handle component's position by row and columns.
|
|
||||||
-- <b># Overview #</b>
|
|
||||||
--
|
|
||||||
-- The Static Grid component allows for positioning components in rows and columns.
|
|
||||||
-- It provides a static grid layout with constant node sizes, allowing for pre-calculated
|
|
||||||
-- node positions and the option to include gaps between nodes.
|
|
||||||
--
|
|
||||||
-- <b># Notes #</b>
|
|
||||||
--
|
|
||||||
-- • In a static grid, the node size remains constant, enabling the calculation of node
|
|
||||||
-- positions before placement. If you want add gaps between nodes, increase the root prefab size,
|
|
||||||
-- including the padding and margin.
|
|
||||||
--
|
|
||||||
-- • The static grid can automatically shift elements when nodes are added or removed.
|
|
||||||
--
|
|
||||||
-- • When a node is added, the grid will set the node's parent to the specified parent_node.
|
|
||||||
--
|
|
||||||
-- • You can obtain an array of positions for each element, which can be used to set
|
|
||||||
-- points of interest in a scroll component.
|
|
||||||
--
|
|
||||||
-- • The size of all elements can be retrieved for setting up the size in a scroll component.
|
|
||||||
--
|
|
||||||
-- • The grid can be bound to a scroll component for automatic resizing of the scroll content size.
|
|
||||||
--
|
|
||||||
-- • The pivot of the parent_node affects the node placement within the grid.
|
|
||||||
--
|
|
||||||
-- • A prefab node is used to determine the node size and anchor.
|
|
||||||
--
|
|
||||||
-- • You can specify a position_function for animations using the
|
|
||||||
-- _static_grid:set_position_function(node, pos) callback. The default position function is gui.set_position().
|
|
||||||
--
|
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_grid" target="_blank"><b>Example Link</b></a>
|
|
||||||
-- @module StaticGrid
|
|
||||||
-- @within BaseComponent
|
|
||||||
-- @alias druid.grid
|
|
||||||
|
|
||||||
--- On item add callback(self, node, index)
|
|
||||||
-- @tfield event on_add_item event
|
|
||||||
|
|
||||||
--- On item remove callback(self, index)
|
|
||||||
-- @tfield event on_remove_item event
|
|
||||||
|
|
||||||
--- On item add, remove or change in_row callback(self, index|nil)
|
|
||||||
-- @tfield event on_change_items event
|
|
||||||
|
|
||||||
--- On grid clear callback(self)
|
|
||||||
-- @tfield event on_clear event
|
|
||||||
|
|
||||||
--- On update item positions callback(self)
|
|
||||||
-- @tfield event on_update_positions event
|
|
||||||
|
|
||||||
--- Parent gui node
|
|
||||||
-- @tfield node parent
|
|
||||||
|
|
||||||
--- List of all grid nodes
|
|
||||||
-- @tfield node[] nodes
|
|
||||||
|
|
||||||
--- The first index of node in grid
|
|
||||||
-- @tfield number first_index
|
|
||||||
|
|
||||||
--- The last index of node in grid
|
|
||||||
-- @tfield number last_index
|
|
||||||
|
|
||||||
--- Item anchor [0..1]
|
|
||||||
-- @tfield vector3 anchor
|
|
||||||
|
|
||||||
--- Item pivot [-0.5..0.5]
|
|
||||||
-- @tfield vector3 pivot
|
|
||||||
|
|
||||||
--- Item size
|
|
||||||
-- @tfield vector3 node_size
|
|
||||||
|
|
||||||
--- The size of item content
|
|
||||||
-- @tfield vector4 border
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local event = require("event.event")
|
local event = require("event.event")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
|
---@class druid.grid.style
|
||||||
|
---@field IS_DYNAMIC_NODE_POSES boolean|nil If true, always center grid content as grid pivot sets. Default: false
|
||||||
|
---@field IS_ALIGN_LAST_ROW boolean|nil If true, always align last row of the grid as grid pivot sets. Default: false
|
||||||
|
|
||||||
---@class druid.grid: druid.component
|
---@class druid.grid: druid.component
|
||||||
---@field on_add_item event
|
---@field on_add_item event
|
||||||
---@field on_remove_item event
|
---@field on_remove_item event
|
||||||
@ -98,7 +23,7 @@ local component = require("druid.component")
|
|||||||
---@field border vector4
|
---@field border vector4
|
||||||
---@field in_row number
|
---@field in_row number
|
||||||
---@field style table
|
---@field style table
|
||||||
local M = component.create("static_grid")
|
local M = component.create("grid")
|
||||||
|
|
||||||
|
|
||||||
local function _extend_border(border, pos, size, pivot)
|
local function _extend_border(border, pos, size, pivot)
|
||||||
@ -114,20 +39,15 @@ local function _extend_border(border, pos, size, pivot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---@param style druid.grid.style
|
||||||
-- You can override this component styles params in druid styles table
|
|
||||||
-- or create your own style
|
|
||||||
-- @table style
|
|
||||||
-- @tfield boolean|nil IS_DYNAMIC_NODE_POSES If true, always center grid content as grid pivot sets. Default: false
|
|
||||||
-- @tfield boolean|nil IS_ALIGN_LAST_ROW If true, always align last row of the grid as grid pivot sets. Default: false
|
|
||||||
function M:on_style_change(style)
|
function M:on_style_change(style)
|
||||||
self.style = {}
|
self.style = {
|
||||||
self.style.IS_DYNAMIC_NODE_POSES = style.IS_DYNAMIC_NODE_POSES or false
|
IS_DYNAMIC_NODE_POSES = style.IS_DYNAMIC_NODE_POSES or false,
|
||||||
self.style.IS_ALIGN_LAST_ROW = style.IS_ALIGN_LAST_ROW or false
|
IS_ALIGN_LAST_ROW = style.IS_ALIGN_LAST_ROW or false,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The StaticGrid constructor
|
|
||||||
---@param parent string|node The GUI Node container, where grid's items will be placed
|
---@param parent string|node The GUI Node container, where grid's items will be placed
|
||||||
---@param element node Element prefab. Need to get it size
|
---@param element node Element prefab. Need to get it size
|
||||||
---@param in_row number|nil How many nodes in row can be placed. By default 1
|
---@param in_row number|nil How many nodes in row can be placed. By default 1
|
||||||
@ -163,7 +83,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local _temp_pos = vmath.vector3(0)
|
local _temp_pos = vmath.vector3(0)
|
||||||
--- Return pos for grid node index
|
---Return pos for grid node index
|
||||||
---@param index number The grid element index
|
---@param index number The grid element index
|
||||||
---@return vector3 @Node position
|
---@return vector3 @Node position
|
||||||
function M:get_pos(index)
|
function M:get_pos(index)
|
||||||
@ -180,7 +100,7 @@ function M:get_pos(index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return index for grid pos
|
---Return index for grid pos
|
||||||
---@param pos vector3 The node position in the grid
|
---@param pos vector3 The node position in the grid
|
||||||
---@return number The node index
|
---@return number The node index
|
||||||
function M:get_index(pos)
|
function M:get_index(pos)
|
||||||
@ -199,7 +119,7 @@ function M:get_index(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return grid index by node
|
---Return grid index by node
|
||||||
---@param node node The gui node in the grid
|
---@param node node The gui node in the grid
|
||||||
---@return number|nil index The node index
|
---@return number|nil index The node index
|
||||||
function M:get_index_by_node(node)
|
function M:get_index_by_node(node)
|
||||||
@ -218,7 +138,7 @@ function M:on_layout_change()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set grid anchor. Default anchor is equal to anchor of grid parent node
|
---Set grid anchor. Default anchor is equal to anchor of grid parent node
|
||||||
---@param anchor vector3 Anchor
|
---@param anchor vector3 Anchor
|
||||||
function M:set_anchor(anchor)
|
function M:set_anchor(anchor)
|
||||||
self.anchor = anchor
|
self.anchor = anchor
|
||||||
@ -226,7 +146,7 @@ function M:set_anchor(anchor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update grid content
|
---Update grid content
|
||||||
function M:refresh()
|
function M:refresh()
|
||||||
self:_update(true)
|
self:_update(true)
|
||||||
end
|
end
|
||||||
@ -238,11 +158,6 @@ function M:set_pivot(pivot)
|
|||||||
|
|
||||||
local width = gui.get(self.parent, "size.x")
|
local width = gui.get(self.parent, "size.x")
|
||||||
local height = gui.get(self.parent, "size.y")
|
local height = gui.get(self.parent, "size.y")
|
||||||
--local pos_offset = vmath.vector3(
|
|
||||||
-- width * (self.pivot.x - prev_pivot.x),
|
|
||||||
-- height * (self.pivot.y - prev_pivot.y),
|
|
||||||
-- 0
|
|
||||||
--)
|
|
||||||
|
|
||||||
local position = gui.get_position(self.parent)
|
local position = gui.get_position(self.parent)
|
||||||
position.x = position.x + width * (self.pivot.x - prev_pivot.x)
|
position.x = position.x + width * (self.pivot.x - prev_pivot.x)
|
||||||
@ -263,7 +178,7 @@ function M:set_pivot(pivot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add new item to the grid
|
---Add new item to the grid
|
||||||
---@param item node GUI node
|
---@param item node GUI node
|
||||||
---@param index number|nil The item position. By default add as last item
|
---@param index number|nil The item position. By default add as last item
|
||||||
---@param shift_policy number|nil How shift nodes, if required. Default: const.SHIFT.RIGHT
|
---@param shift_policy number|nil How shift nodes, if required. Default: const.SHIFT.RIGHT
|
||||||
@ -287,7 +202,7 @@ function M:add(item, index, shift_policy, is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new items to the grid. All previous items will be removed
|
---Set new items to the grid. All previous items will be removed
|
||||||
---@param nodes node[] The new grid nodes
|
---@param nodes node[] The new grid nodes
|
||||||
-- @tparam[opt=false] boolean is_instant If true, update node positions instantly
|
-- @tparam[opt=false] boolean is_instant If true, update node positions instantly
|
||||||
function M:set_items(nodes, is_instant)
|
function M:set_items(nodes, is_instant)
|
||||||
@ -303,7 +218,7 @@ function M:set_items(nodes, is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove the item from the grid. Note that gui node will be not deleted
|
---Remove the item from the grid. Note that gui node will be not deleted
|
||||||
---@param index number The grid node index to remove
|
---@param index number The grid node index to remove
|
||||||
---@param shift_policy number|nil How shift nodes, if required. Default: const.SHIFT.RIGHT
|
---@param shift_policy number|nil How shift nodes, if required. Default: const.SHIFT.RIGHT
|
||||||
---@param is_instant boolean|nil If true, update node positions instantly
|
---@param is_instant boolean|nil If true, update node positions instantly
|
||||||
@ -323,7 +238,7 @@ function M:remove(index, shift_policy, is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return grid content size
|
---Return grid content size
|
||||||
---@return vector3 The grid content size
|
---@return vector3 The grid content size
|
||||||
function M:get_size()
|
function M:get_size()
|
||||||
return vmath.vector3(
|
return vmath.vector3(
|
||||||
@ -355,14 +270,14 @@ function M:get_size_for(count)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return grid content borders
|
---Return grid content borders
|
||||||
---@return vector4 The grid content borders
|
---@return vector4 The grid content borders
|
||||||
function M:get_borders()
|
function M:get_borders()
|
||||||
return self.border
|
return self.border
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return array of all node positions
|
---Return array of all node positions
|
||||||
---@return vector3[] All grid node positions
|
---@return vector3[] All grid node positions
|
||||||
function M:get_all_pos()
|
function M:get_all_pos()
|
||||||
local result = {}
|
local result = {}
|
||||||
@ -374,7 +289,7 @@ function M:get_all_pos()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Change set position function for grid nodes. It will call on
|
---Change set position function for grid nodes. It will call on
|
||||||
-- update poses on grid elements. Default: gui.set_position
|
-- update poses on grid elements. Default: gui.set_position
|
||||||
---@param callback function Function on node set position
|
---@param callback function Function on node set position
|
||||||
---@return druid.grid Current grid instance
|
---@return druid.grid Current grid instance
|
||||||
@ -385,7 +300,7 @@ function M:set_position_function(callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Clear grid nodes array. GUI nodes will be not deleted!
|
---Clear grid nodes array. GUI nodes will be not deleted!
|
||||||
-- If you want to delete GUI nodes, use static_grid.nodes array before grid:clear
|
-- If you want to delete GUI nodes, use static_grid.nodes array before grid:clear
|
||||||
---@return druid.grid Current grid instance
|
---@return druid.grid Current grid instance
|
||||||
function M:clear()
|
function M:clear()
|
||||||
@ -404,7 +319,7 @@ function M:clear()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return StaticGrid offset, where StaticGrid content starts.
|
---Return StaticGrid offset, where StaticGrid content starts.
|
||||||
---@return vector3 The StaticGrid offset
|
---@return vector3 The StaticGrid offset
|
||||||
function M:get_offset()
|
function M:get_offset()
|
||||||
local borders = self:get_borders()
|
local borders = self:get_borders()
|
||||||
@ -419,7 +334,7 @@ function M:get_offset()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new in_row elements for grid
|
---Set new in_row elements for grid
|
||||||
---@param in_row number The new in_row value
|
---@param in_row number The new in_row value
|
||||||
---@return druid.grid Current grid instance
|
---@return druid.grid Current grid instance
|
||||||
function M:set_in_row(in_row)
|
function M:set_in_row(in_row)
|
||||||
@ -437,7 +352,7 @@ function M:set_in_row(in_row)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new node size for grid
|
---Set new node size for grid
|
||||||
-- @tparam[opt] number width The new node width
|
-- @tparam[opt] number width The new node width
|
||||||
-- @tparam[opt] number height The new node height
|
-- @tparam[opt] number height The new node height
|
||||||
---@return druid.grid Current grid instance
|
---@return druid.grid Current grid instance
|
||||||
@ -461,7 +376,7 @@ function M:set_item_size(width, height)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Sort grid nodes by custom comparator function
|
---Sort grid nodes by custom comparator function
|
||||||
---@param comparator function The comparator function. (a, b) -> boolean
|
---@param comparator function The comparator function. (a, b) -> boolean
|
||||||
---@return druid.grid self Current grid instance
|
---@return druid.grid self Current grid instance
|
||||||
function M:sort_nodes(comparator)
|
function M:sort_nodes(comparator)
|
||||||
@ -472,7 +387,7 @@ function M:sort_nodes(comparator)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update grid inner state
|
---Update grid inner state
|
||||||
---@param is_instant boolean|nil If true, node position update instantly, otherwise with set_position_function callback
|
---@param is_instant boolean|nil If true, node position update instantly, otherwise with set_position_function callback
|
||||||
---@private
|
---@private
|
||||||
function M:_update(is_instant)
|
function M:_update(is_instant)
|
||||||
@ -482,7 +397,7 @@ function M:_update(is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update first and last indexes of grid nodes
|
---Update first and last indexes of grid nodes
|
||||||
---@private
|
---@private
|
||||||
function M:_update_indexes()
|
function M:_update_indexes()
|
||||||
self.first_index = nil
|
self.first_index = nil
|
||||||
@ -497,7 +412,7 @@ function M:_update_indexes()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update grid content borders, recalculate min and max values
|
---Update grid content borders, recalculate min and max values
|
||||||
---@private
|
---@private
|
||||||
function M:_update_borders()
|
function M:_update_borders()
|
||||||
if not self.first_index then
|
if not self.first_index then
|
||||||
@ -515,7 +430,7 @@ function M:_update_borders()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update grid nodes position
|
---Update grid nodes position
|
||||||
---@param is_instant boolean|nil If true, node position update instantly, otherwise with set_position_function callback
|
---@param is_instant boolean|nil If true, node position update instantly, otherwise with set_position_function callback
|
||||||
---@private
|
---@private
|
||||||
function M:_update_pos(is_instant)
|
function M:_update_pos(is_instant)
|
||||||
@ -537,7 +452,7 @@ function M:_update_pos(is_instant)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return elements offset for correct posing nodes. Correct posing at
|
---Return elements offset for correct posing nodes. Correct posing at
|
||||||
-- parent pivot node (0:0) with adjusting of node sizes and anchoring
|
-- parent pivot node (0:0) with adjusting of node sizes and anchoring
|
||||||
---@return vector3 The offset vector
|
---@return vector3 The offset vector
|
||||||
---@private
|
---@private
|
||||||
@ -555,7 +470,7 @@ function M:_get_zero_offset()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return offset x for last row in grid. Used to align this row accorting to grid's anchor
|
---Return offset x for last row in grid. Used to align this row accorting to grid's anchor
|
||||||
---@return number The offset x value
|
---@return number The offset x value
|
||||||
---@private
|
---@private
|
||||||
function M:_get_zero_offset_x(row_index)
|
function M:_get_zero_offset_x(row_index)
|
||||||
|
@ -1,81 +1,3 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
|
||||||
|
|
||||||
--- Component for Wrapping GUI Text Nodes: Druid Text
|
|
||||||
--
|
|
||||||
-- ## Overview ##
|
|
||||||
--
|
|
||||||
-- Druid Text is a component that provides various adjustment modes for text nodes. It allows text to be scaled down to fit within the size of the text node.
|
|
||||||
--
|
|
||||||
-- ## Notes ##
|
|
||||||
--
|
|
||||||
-- • The text pivot can be changed using the text:set_pivot method.
|
|
||||||
-- The anchoring will be inside the text node's area size.
|
|
||||||
--
|
|
||||||
-- • There are several text adjustment types available. The default is DOWNSCALE.
|
|
||||||
-- You can change the default adjustment type in the Text style. Refer to the example below to see all available adjustment types:
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.DOWNSCALE: Changes the text's scale to fit within the text node's size.
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.TRIM: Trims the text with a postfix (default: "...", can be overridden in styles)
|
|
||||||
-- to fit within the text node's size.
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.NO_ADJUST: No adjustment is applied, similar
|
|
||||||
-- to the default Defold Text Node behavior.
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.DOWNSCALE_LIMITED: Changes the text's scale
|
|
||||||
-- with a limited downscale. You can set the minimum scale using the text:set_minimal_scale() function.
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.SCROLL: Changes the text's pivot to imitate scrolling within the text box.
|
|
||||||
-- For better effect, use with a stencil node.
|
|
||||||
--
|
|
||||||
-- - const.TEXT_ADJUST.SCALE_THEN_SCROLL: Combines two modes: limited downscale first, then scroll.
|
|
||||||
--
|
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=texts_general" target="_blank"><b>Example Link</b></a>
|
|
||||||
-- @module Text
|
|
||||||
-- @within BaseComponent
|
|
||||||
-- @alias druid.text
|
|
||||||
|
|
||||||
--- On set text callback(self, text)
|
|
||||||
-- @tfield event on_set_text event
|
|
||||||
|
|
||||||
--- On adjust text size callback(self, new_scale, text_metrics)
|
|
||||||
-- @tfield event on_update_text_scale event
|
|
||||||
|
|
||||||
--- On change pivot callback(self, pivot)
|
|
||||||
-- @tfield event on_set_pivot event
|
|
||||||
|
|
||||||
--- Text node
|
|
||||||
-- @tfield node node
|
|
||||||
|
|
||||||
--- The node id of text node
|
|
||||||
-- @tfield hash node_id
|
|
||||||
|
|
||||||
--- Current text position
|
|
||||||
-- @tfield vector3 pos
|
|
||||||
|
|
||||||
--- The last text value
|
|
||||||
-- @tfield string last_value
|
|
||||||
|
|
||||||
--- 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 number adjust_type
|
|
||||||
|
|
||||||
--- Current text color
|
|
||||||
-- @tfield vector3 color
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
local event = require("event.event")
|
local event = require("event.event")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
@ -83,14 +5,20 @@ local utf8_lua = require("druid.system.utf8")
|
|||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
local utf8 = utf8 or utf8_lua --[[@as utf8]]
|
local utf8 = utf8 or utf8_lua --[[@as utf8]]
|
||||||
|
|
||||||
|
---@class druid.text.style
|
||||||
|
---@field TRIM_POSTFIX string|nil The postfix for TRIM adjust type. Default: ...
|
||||||
|
---@field DEFAULT_ADJUST string|nil The default adjust type for any text component. Default: DOWNSCALE
|
||||||
|
---@field ADJUST_STEPS number|nil Amount of iterations for text adjust by height. Default: 20
|
||||||
|
---@field ADJUST_SCALE_DELTA number|nil Scale step on each height adjust step. Default: 0.02
|
||||||
|
|
||||||
---@class druid.text: druid.component
|
---@class druid.text: druid.component
|
||||||
---@field node node
|
---@field node node The text node
|
||||||
---@field on_set_text event
|
---@field on_set_text event The event triggered when the text is set, fun(self, text)
|
||||||
---@field on_update_text_scale event
|
---@field on_update_text_scale event The event triggered when the text scale is updated, fun(self, scale, metrics)
|
||||||
---@field on_set_pivot event
|
---@field on_set_pivot event The event triggered when the text pivot is set, fun(self, pivot)
|
||||||
---@field style table
|
---@field style druid.text.style The style of the text
|
||||||
---@field private start_pivot userdata
|
---@field private start_pivot userdata The start pivot of the text
|
||||||
---@field private start_scale vector3
|
---@field private start_scale vector3 The start scale of the text
|
||||||
---@field private scale vector3
|
---@field private scale vector3
|
||||||
local M = component.create("text")
|
local M = component.create("text")
|
||||||
|
|
||||||
@ -111,7 +39,7 @@ local function update_text_size(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Reset initial scale for text
|
---Reset initial scale for text
|
||||||
local function reset_default_scale(self)
|
local function reset_default_scale(self)
|
||||||
self.scale.x = self.start_scale.x
|
self.scale.x = self.start_scale.x
|
||||||
self.scale.y = self.start_scale.y
|
self.scale.y = self.start_scale.y
|
||||||
@ -127,7 +55,7 @@ local function is_fit_info_area(self, metrics)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Setup scale x, but can only be smaller, than start text scale
|
---Setup scale x, but can only be smaller, than start text scale
|
||||||
local function update_text_area_size(self)
|
local function update_text_area_size(self)
|
||||||
reset_default_scale(self)
|
reset_default_scale(self)
|
||||||
|
|
||||||
@ -305,24 +233,18 @@ local function update_adjust(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---@param style druid.text.style
|
||||||
-- You can override this component styles params in druid styles table
|
|
||||||
-- or create your own style
|
|
||||||
-- @table style
|
|
||||||
-- @tfield string|nil TRIM_POSTFIX The postfix for TRIM adjust type. Default: ...
|
|
||||||
-- @tfield string|nil DEFAULT_ADJUST The default adjust type for any text component. Default: DOWNSCALE
|
|
||||||
-- @tfield string|nil ADJUST_STEPS Amount of iterations for text adjust by height. Default: 20
|
|
||||||
-- @tfield string|nil ADJUST_SCALE_DELTA Scale step on each height adjust step. Default: 0.02
|
|
||||||
function M:on_style_change(style)
|
function M:on_style_change(style)
|
||||||
self.style = {}
|
self.style = {
|
||||||
self.style.TRIM_POSTFIX = style.TRIM_POSTFIX or "..."
|
TRIM_POSTFIX = style.TRIM_POSTFIX or "...",
|
||||||
self.style.DEFAULT_ADJUST = style.DEFAULT_ADJUST or const.TEXT_ADJUST.DOWNSCALE
|
DEFAULT_ADJUST = style.DEFAULT_ADJUST or const.TEXT_ADJUST.DOWNSCALE,
|
||||||
self.style.ADJUST_STEPS = style.ADJUST_STEPS or 20
|
ADJUST_STEPS = style.ADJUST_STEPS or 20,
|
||||||
self.style.ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02
|
ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The Text constructor
|
---The Text constructor
|
||||||
---@param node string|node Node name or GUI Text Node itself
|
---@param node string|node Node name or GUI Text Node itself
|
||||||
---@param value string|nil Initial text. Default value is node text from GUI scene. Default: nil
|
---@param value string|nil Initial text. Default value is node text from GUI scene. Default: nil
|
||||||
---@param adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
|
---@param adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
|
||||||
@ -357,7 +279,7 @@ function M:on_layout_change()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Calculate text width with font with respect to trailing space
|
---Calculate text width with font with respect to trailing space
|
||||||
---@param text string|nil
|
---@param text string|nil
|
||||||
---@return number Width
|
---@return number Width
|
||||||
---@return number Height
|
---@return number Height
|
||||||
@ -381,7 +303,7 @@ function M:get_text_size(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get chars count by width
|
---Get chars count by width
|
||||||
---@param width number
|
---@param width number
|
||||||
---@return number Chars count
|
---@return number Chars count
|
||||||
function M:get_text_index_by_width(width)
|
function M:get_text_index_by_width(width)
|
||||||
@ -414,7 +336,7 @@ function M:get_text_index_by_width(width)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set text to text field
|
---Set text to text field
|
||||||
---@deprecated
|
---@deprecated
|
||||||
---@param set_to string Text for node
|
---@param set_to string Text for node
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
@ -443,7 +365,7 @@ function M:get_text()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set text area size
|
---Set text area size
|
||||||
---@param size vector3 The new text area size
|
---@param size vector3 The new text area size
|
||||||
---@return druid.text self Current text instance
|
---@return druid.text self Current text instance
|
||||||
function M:set_size(size)
|
function M:set_size(size)
|
||||||
@ -457,7 +379,7 @@ function M:set_size(size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set color
|
---Set color
|
||||||
---@param color vector4 Color for node
|
---@param color vector4 Color for node
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function M:set_color(color)
|
function M:set_color(color)
|
||||||
@ -468,7 +390,7 @@ function M:set_color(color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set alpha
|
---Set alpha
|
||||||
---@param alpha number Alpha for node
|
---@param alpha number Alpha for node
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function M:set_alpha(alpha)
|
function M:set_alpha(alpha)
|
||||||
@ -479,7 +401,7 @@ function M:set_alpha(alpha)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set scale
|
---Set scale
|
||||||
---@param scale vector3 Scale for node
|
---@param scale vector3 Scale for node
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function M:set_scale(scale)
|
function M:set_scale(scale)
|
||||||
@ -490,7 +412,7 @@ function M:set_scale(scale)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set text pivot. Text will re-anchor inside text area
|
---Set text pivot. Text will re-anchor inside text area
|
||||||
---@param pivot userdata The gui.PIVOT_* constant
|
---@param pivot userdata The gui.PIVOT_* constant
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function M:set_pivot(pivot)
|
function M:set_pivot(pivot)
|
||||||
@ -537,7 +459,7 @@ function M:set_text_adjust(adjust_type, minimal_scale)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
|
---Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
|
||||||
---@param minimal_scale number If pass nil - not use minimal scale
|
---@param minimal_scale number If pass nil - not use minimal scale
|
||||||
---@return druid.text Current text instance
|
---@return druid.text Current text instance
|
||||||
function M:set_minimal_scale(minimal_scale)
|
function M:set_minimal_scale(minimal_scale)
|
||||||
@ -547,7 +469,7 @@ function M:set_minimal_scale(minimal_scale)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current text adjust type
|
---Return current text adjust type
|
||||||
---@return string adjust_type The current text adjust type
|
---@return string adjust_type The current text adjust type
|
||||||
function M:get_text_adjust()
|
function M:get_text_adjust()
|
||||||
return self.adjust_type
|
return self.adjust_type
|
||||||
|
@ -113,10 +113,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---Convert hsb color to rgb color
|
---Convert hsb color to rgb color
|
||||||
---@param r number @Red value
|
---@param r number Red value
|
||||||
---@param g number @Green value
|
---@param g number Green value
|
||||||
---@param b number @Blue value
|
---@param b number Blue value
|
||||||
---@param alpha number|nil @Alpha value. Default is 1
|
---@param alpha number|nil Alpha value. Default is 1
|
||||||
function M.rgb2hsb(r, g, b, alpha)
|
function M.rgb2hsb(r, g, b, alpha)
|
||||||
alpha = alpha or 1
|
alpha = alpha or 1
|
||||||
local min, max = math.min(r, g, b), math.max(r, g, b)
|
local min, max = math.min(r, g, b), math.max(r, g, b)
|
||||||
@ -143,10 +143,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---Convert hsb color to rgb color
|
---Convert hsb color to rgb color
|
||||||
---@param h number @Hue
|
---@param h number Hue
|
||||||
---@param s number @Saturation
|
---@param s number Saturation
|
||||||
---@param v number @Value
|
---@param v number Value
|
||||||
---@param alpha number|nil @Alpha value. Default is 1
|
---@param alpha number|nil Alpha value. Default is 1
|
||||||
function M.hsb2rgb(h, s, v, alpha)
|
function M.hsb2rgb(h, s, v, alpha)
|
||||||
local r, g, b
|
local r, g, b
|
||||||
local i = math.floor(h * 6)
|
local i = math.floor(h * 6)
|
||||||
@ -170,9 +170,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---Convert rgb color to hex color
|
---Convert rgb color to hex color
|
||||||
---@param red number @Red value
|
---@param red number Red value
|
||||||
---@param green number @Green value
|
---@param green number Green value
|
||||||
---@param blue number @Blue value
|
---@param blue number Blue value
|
||||||
function M.rgb2hex(red, green, blue)
|
function M.rgb2hex(red, green, blue)
|
||||||
local r = string.format("%x", math.floor(red * 255))
|
local r = string.format("%x", math.floor(red * 255))
|
||||||
local g = string.format("%x", math.floor(green * 255))
|
local g = string.format("%x", math.floor(green * 255))
|
||||||
|
@ -241,7 +241,7 @@ function M:get_parent_component()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Setup component context and his style table
|
---Setup component context and his style table
|
||||||
---@param druid_instance druid.instance The parent druid instance
|
---@param druid_instance druid.instance The parent druid instance
|
||||||
---@param context table Druid context. Usually it is self of script
|
---@param context table Druid context. Usually it is self of script
|
||||||
---@param style table Druid style module
|
---@param style table Druid style module
|
||||||
@ -272,21 +272,21 @@ function M:setup_component(druid_instance, context, style, instance_class)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return true, if input priority was changed
|
---Return true, if input priority was changed
|
||||||
---@private
|
---@private
|
||||||
function M:_is_input_priority_changed()
|
function M:_is_input_priority_changed()
|
||||||
return self._component._is_input_priority_changed
|
return self._component._is_input_priority_changed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Reset is_input_priority_changed field
|
---Reset is_input_priority_changed field
|
||||||
---@private
|
---@private
|
||||||
function M:_reset_input_priority_changed()
|
function M:_reset_input_priority_changed()
|
||||||
self._component._is_input_priority_changed = false
|
self._component._is_input_priority_changed = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get current component interests
|
---Get current component interests
|
||||||
---@return table List of component interests
|
---@return table List of component interests
|
||||||
---@private
|
---@private
|
||||||
function M:__get_interests()
|
function M:__get_interests()
|
||||||
@ -351,7 +351,7 @@ function M:__remove_child(child)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return all children components, recursive
|
---Return all children components, recursive
|
||||||
---@return table Array of childrens if the Druid component instance
|
---@return table Array of childrens if the Druid component instance
|
||||||
function M:get_childrens()
|
function M:get_childrens()
|
||||||
local childrens = {}
|
local childrens = {}
|
||||||
|
@ -114,5 +114,4 @@ M.SIDE = {
|
|||||||
Y = "y"
|
Y = "y"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid Rich Input custom component.
|
---Druid Rich Input custom component.
|
||||||
-- It's wrapper on Input component with cursor and placeholder text
|
-- It's wrapper on Input component with cursor and placeholder text
|
||||||
-- @module RichInput
|
-- @module RichInput
|
||||||
-- @alias druid.rich_input
|
-- @alias druid.rich_input
|
||||||
|
|
||||||
--- The component druid instance
|
---The component druid instance
|
||||||
-- @tfield DruidInstance druid DruidInstance
|
-- @tfield DruidInstance druid DruidInstance
|
||||||
|
|
||||||
--- Root node
|
---Root node
|
||||||
-- @tfield node root
|
-- @tfield node root
|
||||||
|
|
||||||
--- On input field text change callback(self, input_text)
|
---On input field text change callback(self, input_text)
|
||||||
-- @tfield Input input Input
|
-- @tfield Input input Input
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield node cursor
|
-- @tfield node cursor
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield node cursor_text
|
-- @tfield node cursor_text
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield vector3 cursor_position
|
-- @tfield vector3 cursor_position
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield druid.text input_text
|
-- @tfield druid.text input_text
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield druid.drag drag
|
-- @tfield druid.drag drag
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield druid.text placeholder
|
-- @tfield druid.text placeholder
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield vector3 text_position
|
-- @tfield vector3 text_position
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -120,7 +120,7 @@ local function on_unselect(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Update selection
|
---Update selection
|
||||||
local function update_selection(self)
|
local function update_selection(self)
|
||||||
update_text(self)
|
update_text(self)
|
||||||
end
|
end
|
||||||
@ -264,7 +264,7 @@ function M:on_input(action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set placeholder text
|
---Set placeholder text
|
||||||
---@param placeholder_text string The placeholder text
|
---@param placeholder_text string The placeholder text
|
||||||
function M:set_placeholder(placeholder_text)
|
function M:set_placeholder(placeholder_text)
|
||||||
self.placeholder:set_text(placeholder_text)
|
self.placeholder:set_text(placeholder_text)
|
||||||
@ -272,13 +272,13 @@ function M:set_placeholder(placeholder_text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Select input field
|
---Select input field
|
||||||
function M:select()
|
function M:select()
|
||||||
self.input:select()
|
self.input:select()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set input field text
|
---Set input field text
|
||||||
---@param text string The input text
|
---@param text string The input text
|
||||||
---@return druid.rich_input self Current instance
|
---@return druid.rich_input self Current instance
|
||||||
function M:set_text(text)
|
function M:set_text(text)
|
||||||
@ -289,7 +289,7 @@ function M:set_text(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set input field font
|
---Set input field font
|
||||||
---@param font hash The font hash
|
---@param font hash The font hash
|
||||||
---@return druid.rich_input self Current instance
|
---@return druid.rich_input self Current instance
|
||||||
function M:set_font(font)
|
function M:set_font(font)
|
||||||
@ -300,13 +300,13 @@ function M:set_font(font)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set input field text
|
---Set input field text
|
||||||
function M:get_text()
|
function M:get_text()
|
||||||
return self.input:get_text()
|
return self.input:get_text()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set allowed charaters for input field.
|
---Set allowed charaters for input field.
|
||||||
-- See: https://defold.com/ref/stable/string/
|
-- See: https://defold.com/ref/stable/string/
|
||||||
-- ex: [%a%d] for alpha and numeric
|
-- ex: [%a%d] for alpha and numeric
|
||||||
---@param characters string Regulax exp. for validate user input
|
---@param characters string Regulax exp. for validate user input
|
||||||
|
@ -50,7 +50,7 @@ local function compare_words(one, two)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get the length of a text ignoring any tags except image tags
|
---Get the length of a text ignoring any tags except image tags
|
||||||
-- which are treated as having a length of 1
|
-- which are treated as having a length of 1
|
||||||
-- @param text String with text or a list of words (from richtext.create)
|
-- @param text String with text or a list of words (from richtext.create)
|
||||||
-- @return Length of text
|
-- @return Length of text
|
||||||
@ -152,12 +152,12 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Create rich text gui nodes from text
|
-- Create rich text gui nodes from text
|
||||||
--- @param text string The text to create rich text nodes from
|
---@param text string The text to create rich text nodes from
|
||||||
--- @param settings table Optional settings table (refer to documentation for details)
|
---@param settings table Optional settings table (refer to documentation for details)
|
||||||
--- @param style druid.rich_text.style
|
---@param style druid.rich_text.style
|
||||||
--- @return druid.rich_text.word[]
|
---@return druid.rich_text.word[]
|
||||||
--- @return druid.rich_text.settings
|
---@return druid.rich_text.settings
|
||||||
--- @return druid.rich_text.lines_metrics
|
---@return druid.rich_text.lines_metrics
|
||||||
function M.create(text, settings, style)
|
function M.create(text, settings, style)
|
||||||
assert(text, "You must provide a text")
|
assert(text, "You must provide a text")
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ function M.is_fit_info_area(lines, settings)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get all words with a specific tag
|
---Get all words with a specific tag
|
||||||
-- @param words The words to search (as received from richtext.create)
|
-- @param words The words to search (as received from richtext.create)
|
||||||
-- @param tag The tag to search for. Nil to search for words without a tag
|
-- @param tag The tag to search for. Nil to search for words without a tag
|
||||||
-- @return Words matching the tag
|
-- @return Words matching the tag
|
||||||
|
@ -107,7 +107,7 @@ local function merge_tags(dst, src)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Parse the text into individual words
|
---Parse the text into individual words
|
||||||
-- @param text The text to parse
|
-- @param text The text to parse
|
||||||
-- @param default_settings Default settings for each word
|
-- @param default_settings Default settings for each word
|
||||||
-- @param color_aliases Color aliases table
|
-- @param color_aliases Color aliases table
|
||||||
@ -184,7 +184,7 @@ function M.parse(text, default_settings, style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get the length of a text, excluding any tags (except image and spine tags)
|
---Get the length of a text, excluding any tags (except image and spine tags)
|
||||||
function M.length(text)
|
function M.length(text)
|
||||||
return utf8.len(text:gsub("<img.-/>", " "):gsub("<.->", ""))
|
return utf8.len(text:gsub("<img.-/>", " "):gsub("<.->", ""))
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid Rich Text Custom Component.
|
---Druid Rich Text Custom Component.
|
||||||
-- <b># Overview #</b>
|
-- <b># Overview #</b>
|
||||||
--
|
--
|
||||||
-- This custom component is inspired by <a href="https://github.com/britzl/defold-richtext" target="_blank">defold-richtext</a> by britzl.
|
-- This custom component is inspired by <a href="https://github.com/britzl/defold-richtext" target="_blank">defold-richtext</a> by britzl.
|
||||||
@ -62,13 +62,13 @@
|
|||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.rich_text
|
-- @alias druid.rich_text
|
||||||
|
|
||||||
--- The component druid instance
|
---The component druid instance
|
||||||
-- @tfield DruidInstance druid DruidInstance
|
-- @tfield DruidInstance druid DruidInstance
|
||||||
|
|
||||||
--- The root node of the Rich Text
|
---The root node of the Rich Text
|
||||||
-- @tfield node root
|
-- @tfield node root
|
||||||
|
|
||||||
--- The text prefab node
|
---The text prefab node
|
||||||
-- @tfield node text_prefab
|
-- @tfield node text_prefab
|
||||||
|
|
||||||
--
|
--
|
||||||
@ -150,7 +150,7 @@ local rich_text = require("druid.custom.rich_text.module.rt")
|
|||||||
local M = component.create("rich_text")
|
local M = component.create("rich_text")
|
||||||
|
|
||||||
|
|
||||||
--- The RichText constructor
|
---The RichText constructor
|
||||||
---@param text_node node|string The text node to make Rich Text
|
---@param text_node node|string The text node to make Rich Text
|
||||||
---@param value string|nil The initial text value. Default will be gui.get_text(text_node)
|
---@param value string|nil The initial text value. Default will be gui.get_text(text_node)
|
||||||
function M:init(text_node, value)
|
function M:init(text_node, value)
|
||||||
@ -175,7 +175,7 @@ function M:on_layout_change()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---Component style params.
|
||||||
-- You can override this component styles params in Druid styles table
|
-- You can override this component styles params in Druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
-- @table style
|
-- @table style
|
||||||
@ -190,7 +190,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set text for Rich Text
|
---Set text for Rich Text
|
||||||
---@param text string|nil The text to set
|
---@param text string|nil The text to set
|
||||||
---@return druid.rich_text.word[] words
|
---@return druid.rich_text.word[] words
|
||||||
---@return druid.rich_text.lines_metrics line_metrics
|
---@return druid.rich_text.lines_metrics line_metrics
|
||||||
@ -252,7 +252,7 @@ function M:set_text(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get current text
|
---Get current text
|
||||||
---@return string text
|
---@return string text
|
||||||
function M:get_text()
|
function M:get_text()
|
||||||
return self._last_value
|
return self._last_value
|
||||||
@ -266,7 +266,7 @@ function M:on_remove()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Clear all created words.
|
---Clear all created words.
|
||||||
function M:clear()
|
function M:clear()
|
||||||
if self._words then
|
if self._words then
|
||||||
rich_text.remove(self._words)
|
rich_text.remove(self._words)
|
||||||
@ -276,7 +276,7 @@ function M:clear()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get all words, which has a passed tag.
|
---Get all words, which has a passed tag.
|
||||||
---@param tag string
|
---@param tag string
|
||||||
---@return druid.rich_text.word[] words
|
---@return druid.rich_text.word[] words
|
||||||
function M:tagged(tag)
|
function M:tagged(tag)
|
||||||
@ -296,14 +296,14 @@ function M:characters(word)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get all current words.
|
---Get all current words.
|
||||||
---@return druid.rich_text.word[]
|
---@return druid.rich_text.word[]
|
||||||
function M:get_words()
|
function M:get_words()
|
||||||
return self._words
|
return self._words
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Get current line metrics
|
---Get current line metrics
|
||||||
----@return druid.rich_text.lines_metrics
|
----@return druid.rich_text.lines_metrics
|
||||||
function M:get_line_metric()
|
function M:get_line_metric()
|
||||||
return self._line_metrics
|
return self._line_metrics
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
--- Container component
|
---Container component
|
||||||
-- Container setup in GUI
|
-- Container setup in GUI
|
||||||
-- parent container - container that contains this container. If not, then it's a window default container or parent node
|
-- parent container - container that contains this container. If not, then it's a window default container or parent node
|
||||||
-- container pivot - the point of the parent container that will be used as a pivot point for positioning
|
-- container pivot - the point of the parent container that will be used as a pivot point for positioning
|
||||||
@ -47,7 +47,7 @@ local CORNER_PIVOTS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--- The Container init
|
---The Container init
|
||||||
---@param node node Gui node
|
---@param node node Gui node
|
||||||
---@param mode string Layout mode
|
---@param mode string Layout mode
|
||||||
---@param callback fun(self: druid.container, size: vector3)|nil Callback on size changed
|
---@param callback fun(self: druid.container, size: vector3)|nil Callback on size changed
|
||||||
@ -118,7 +118,7 @@ function M:set_pivot(pivot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---Component style params.
|
||||||
-- You can override this component styles params in Druid styles table
|
-- You can override this component styles params in Druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
-- @table style
|
-- @table style
|
||||||
@ -131,7 +131,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new size of layout node
|
---Set new size of layout node
|
||||||
---@param width number|nil
|
---@param width number|nil
|
||||||
---@param height number|nil
|
---@param height number|nil
|
||||||
---@param anchor_pivot constant|nil If set will keep the corner possition relative to the new size
|
---@param anchor_pivot constant|nil If set will keep the corner possition relative to the new size
|
||||||
@ -207,7 +207,7 @@ function M:get_scale()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set size for layout node to fit inside it
|
---Set size for layout node to fit inside it
|
||||||
---@param target_size vector3
|
---@param target_size vector3
|
||||||
---@return druid.container Container
|
---@return druid.container Container
|
||||||
function M:fit_into_size(target_size)
|
function M:fit_into_size(target_size)
|
||||||
@ -218,7 +218,7 @@ function M:fit_into_size(target_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set current size for layout node to fit inside it
|
---Set current size for layout node to fit inside it
|
||||||
---@return druid.container Container
|
---@return druid.container Container
|
||||||
function M:fit_into_window()
|
function M:fit_into_window()
|
||||||
return self:fit_into_size(vmath.vector3(gui.get_width(), gui.get_height(), 0))
|
return self:fit_into_size(vmath.vector3(gui.get_width(), gui.get_height(), 0))
|
||||||
@ -388,7 +388,7 @@ function M:refresh()
|
|||||||
stretch_side_y = parent.size.y - (abs(self.node_offset.y) + abs(self.node_offset.w))
|
stretch_side_y = parent.size.y - (abs(self.node_offset.y) + abs(self.node_offset.w))
|
||||||
end
|
end
|
||||||
|
|
||||||
---- Size Update (for stretch)
|
----Size Update (for stretch)
|
||||||
if self.mode == const.LAYOUT_MODE.STRETCH then
|
if self.mode == const.LAYOUT_MODE.STRETCH then
|
||||||
self:set_size(
|
self:set_size(
|
||||||
abs(stretch_side_x * self.node_fill_x),
|
abs(stretch_side_x * self.node_fill_x),
|
||||||
@ -522,7 +522,7 @@ function M:_on_corner_drag(x, y, corner_offset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set node for layout node to fit inside it. Pass nil to reset
|
---Set node for layout node to fit inside it. Pass nil to reset
|
||||||
---@param node string|node The node_id or gui.get_node(node_id)
|
---@param node string|node The node_id or gui.get_node(node_id)
|
||||||
---@return druid.container Layout
|
---@return druid.container Layout
|
||||||
function M:fit_into_node(node)
|
function M:fit_into_node(node)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Component to manage data for huge dataset in scroll.
|
---Component to manage data for huge dataset in scroll.
|
||||||
-- It requires Druid Scroll and Druid Grid (Static or Dynamic) components
|
-- It requires Druid Scroll and Druid Grid (Static or Dynamic) components
|
||||||
--
|
--
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_data_list" target="_blank"><b>Example Link</b></a>
|
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_data_list" target="_blank"><b>Example Link</b></a>
|
||||||
@ -9,22 +9,22 @@
|
|||||||
-- @alias druid.data_list
|
-- @alias druid.data_list
|
||||||
|
|
||||||
|
|
||||||
--- The Druid scroll component
|
---The Druid scroll component
|
||||||
-- @tfield Scroll scroll Scroll
|
-- @tfield Scroll scroll Scroll
|
||||||
|
|
||||||
--- The Druid Grid component
|
---The Druid Grid component
|
||||||
-- @tfield StaticGrid grid StaticGrid}, @{DynamicGrid
|
-- @tfield StaticGrid grid StaticGrid}, @{DynamicGrid
|
||||||
|
|
||||||
--- The current progress of scroll posititon
|
---The current progress of scroll posititon
|
||||||
-- @tfield number scroll_progress
|
-- @tfield number scroll_progress
|
||||||
|
|
||||||
--- The current top index of visual elements
|
---The current top index of visual elements
|
||||||
-- @tfield number top_index
|
-- @tfield number top_index
|
||||||
|
|
||||||
--- The current last index of visual elements
|
---The current last index of visual elements
|
||||||
-- @tfield number last_index
|
-- @tfield number last_index
|
||||||
|
|
||||||
--- Event triggered when scroll progress is changed; event(self, progress_value)
|
---Event triggered when scroll progress is changed; event(self, progress_value)
|
||||||
-- @tfield event on_scroll_progress_change event
|
-- @tfield event on_scroll_progress_change event
|
||||||
|
|
||||||
---On DataList visual element created Event callback(self, index, node, instance)
|
---On DataList visual element created Event callback(self, index, node, instance)
|
||||||
@ -55,7 +55,7 @@ local event = require("event.event")
|
|||||||
local M = component.create("data_list")
|
local M = component.create("data_list")
|
||||||
|
|
||||||
|
|
||||||
--- The DataList constructor
|
---The DataList constructor
|
||||||
---@param scroll druid.scroll The Scroll instance for Data List component
|
---@param scroll druid.scroll The Scroll instance for Data List component
|
||||||
---@param grid druid.grid The StaticGrid} or @{DynamicGrid instance for Data List component
|
---@param grid druid.grid The StaticGrid} or @{DynamicGrid instance for Data List component
|
||||||
---@param create_function function The create function callback(self, data, index, data_list). Function should return (node, [component])
|
---@param create_function function The create function callback(self, data, index, data_list). Function should return (node, [component])
|
||||||
@ -85,14 +85,14 @@ function M:init(scroll, grid, create_function)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Druid System on_remove function
|
---Druid System on_remove function
|
||||||
function M:on_remove()
|
function M:on_remove()
|
||||||
self:clear()
|
self:clear()
|
||||||
self.scroll.on_scroll:unsubscribe(self._refresh, self)
|
self.scroll.on_scroll:unsubscribe(self._refresh, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set refresh function for DataList component
|
---Set refresh function for DataList component
|
||||||
---@param is_use_cache boolean Use cache version of DataList. Requires make setup of components in on_element_add callback and clean in on_element_remove
|
---@param is_use_cache boolean Use cache version of DataList. Requires make setup of components in on_element_add callback and clean in on_element_remove
|
||||||
---@return druid.data_list Current DataList instance
|
---@return druid.data_list Current DataList instance
|
||||||
function M:set_use_cache(is_use_cache)
|
function M:set_use_cache(is_use_cache)
|
||||||
@ -101,7 +101,7 @@ function M:set_use_cache(is_use_cache)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set new data set for DataList component
|
---Set new data set for DataList component
|
||||||
---@param data table The new data array
|
---@param data table The new data array
|
||||||
---@return druid.data_list Current DataList instance
|
---@return druid.data_list Current DataList instance
|
||||||
function M:set_data(data)
|
function M:set_data(data)
|
||||||
@ -112,14 +112,14 @@ function M:set_data(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current data from DataList component
|
---Return current data from DataList component
|
||||||
---@return table The current data array
|
---@return table The current data array
|
||||||
function M:get_data()
|
function M:get_data()
|
||||||
return self._data
|
return self._data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add element to DataList. Currenly untested
|
---Add element to DataList. Currenly untested
|
||||||
---@param data table
|
---@param data table
|
||||||
---@param index number|nil
|
---@param index number|nil
|
||||||
---@param shift_policy number|nil The constant from const.SHIFT.*
|
---@param shift_policy number|nil The constant from const.SHIFT.*
|
||||||
@ -132,7 +132,7 @@ function M:add(data, index, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove element from DataList. Currenly untested
|
---Remove element from DataList. Currenly untested
|
||||||
---@param index number|nil
|
---@param index number|nil
|
||||||
---@param shift_policy number|nil The constant from const.SHIFT.*
|
---@param shift_policy number|nil The constant from const.SHIFT.*
|
||||||
function M:remove(index, shift_policy)
|
function M:remove(index, shift_policy)
|
||||||
@ -141,7 +141,7 @@ function M:remove(index, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove element from DataList by data value. Currenly untested
|
---Remove element from DataList by data value. Currenly untested
|
||||||
---@param data table
|
---@param data table
|
||||||
---@param shift_policy number|nil The constant from const.SHIFT.*
|
---@param shift_policy number|nil The constant from const.SHIFT.*
|
||||||
function M:remove_by_data(data, shift_policy)
|
function M:remove_by_data(data, shift_policy)
|
||||||
@ -153,14 +153,14 @@ function M:remove_by_data(data, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Clear the DataList and refresh visuals
|
---Clear the DataList and refresh visuals
|
||||||
function M:clear()
|
function M:clear()
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self:_refresh()
|
self:_refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return index for data value
|
---Return index for data value
|
||||||
---@param data table
|
---@param data table
|
||||||
function M:get_index(data)
|
function M:get_index(data)
|
||||||
for index, value in pairs(self._data) do
|
for index, value in pairs(self._data) do
|
||||||
@ -173,7 +173,7 @@ function M:get_index(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return all currenly created nodes in DataList
|
---Return all currenly created nodes in DataList
|
||||||
---@return node[] List of created nodes
|
---@return node[] List of created nodes
|
||||||
function M:get_created_nodes()
|
function M:get_created_nodes()
|
||||||
local nodes = {}
|
local nodes = {}
|
||||||
@ -186,7 +186,7 @@ function M:get_created_nodes()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return all currenly created components in DataList
|
---Return all currenly created components in DataList
|
||||||
---@return druid.component[] List of created nodes
|
---@return druid.component[] List of created nodes
|
||||||
function M:get_created_components()
|
function M:get_created_components()
|
||||||
local components = {}
|
local components = {}
|
||||||
@ -199,7 +199,7 @@ function M:get_created_components()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Instant scroll to element with passed index
|
---Instant scroll to element with passed index
|
||||||
---@param index number
|
---@param index number
|
||||||
function M:scroll_to_index(index)
|
function M:scroll_to_index(index)
|
||||||
local pos = self.grid:get_pos(index)
|
local pos = self.grid:get_pos(index)
|
||||||
@ -207,7 +207,7 @@ function M:scroll_to_index(index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add element at passed index using cache or create new
|
---Add element at passed index using cache or create new
|
||||||
---@param index number
|
---@param index number
|
||||||
---@private
|
---@private
|
||||||
function M:_add_at(index)
|
function M:_add_at(index)
|
||||||
@ -240,7 +240,7 @@ function M:_add_at(index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove element from passed index and add it to cache if applicable
|
---Remove element from passed index and add it to cache if applicable
|
||||||
---@param index number
|
---@param index number
|
||||||
---@private
|
---@private
|
||||||
function M:_remove_at(index)
|
function M:_remove_at(index)
|
||||||
@ -270,7 +270,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Refresh all elements in DataList
|
---Refresh all elements in DataList
|
||||||
---@private
|
---@private
|
||||||
function M:_refresh()
|
function M:_refresh()
|
||||||
self.scroll:set_size(self.grid:get_size_for(#self._data))
|
self.scroll:set_size(self.grid:get_size_for(#self._data))
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid hotkey component
|
---Druid hotkey component
|
||||||
--
|
--
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_hotkey" target="_blank"><b>Example Link</b></a>
|
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_hotkey" target="_blank"><b>Example Link</b></a>
|
||||||
-- @module Hotkey
|
-- @module Hotkey
|
||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.hotkey
|
-- @alias druid.hotkey
|
||||||
|
|
||||||
--- On hotkey released callback(self, argument)
|
---On hotkey released callback(self, argument)
|
||||||
-- @tfield event on_hotkey_pressed event
|
-- @tfield event on_hotkey_pressed event
|
||||||
|
|
||||||
--- On hotkey released callback(self, argument)
|
---On hotkey released callback(self, argument)
|
||||||
-- @tfield event on_hotkey_released event
|
-- @tfield event on_hotkey_released event
|
||||||
|
|
||||||
--- Visual node
|
---Visual node
|
||||||
-- @tfield node node
|
-- @tfield node node
|
||||||
|
|
||||||
--- Button trigger node
|
---Button trigger node
|
||||||
-- @tfield node|nil click_node
|
-- @tfield node|nil click_node
|
||||||
|
|
||||||
--- Button component from click_node
|
---Button component from click_node
|
||||||
-- @tfield Button button Button
|
-- @tfield Button button Button
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -37,7 +37,7 @@ local event = require("event.event")
|
|||||||
local M = component.create("hotkey")
|
local M = component.create("hotkey")
|
||||||
|
|
||||||
|
|
||||||
--- The Hotkey constructor
|
---The Hotkey constructor
|
||||||
---@param keys string[]|string The keys to be pressed for trigger callback. Should contains one key and any modificator keys
|
---@param keys string[]|string The keys to be pressed for trigger callback. Should contains one key and any modificator keys
|
||||||
---@param callback function The callback function
|
---@param callback function The callback function
|
||||||
---@param callback_argument any|nil The argument to pass into the callback function
|
---@param callback_argument any|nil The argument to pass into the callback function
|
||||||
@ -56,7 +56,7 @@ function M:init(keys, callback, callback_argument)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---Component style params.
|
||||||
-- You can override this component styles params in druid styles table
|
-- You can override this component styles params in druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
-- @table style
|
-- @table style
|
||||||
@ -71,7 +71,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add hotkey for component callback
|
---Add hotkey for component callback
|
||||||
---@param keys string[]|hash[]|string|hash that have to be pressed before key pressed to activate
|
---@param keys string[]|hash[]|string|hash that have to be pressed before key pressed to activate
|
||||||
---@param callback_argument any|nil The argument to pass into the callback function
|
---@param callback_argument any|nil The argument to pass into the callback function
|
||||||
---@return druid.hotkey Current instance
|
---@return druid.hotkey Current instance
|
||||||
@ -186,7 +186,7 @@ function M:on_input(action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- If true, the callback will be triggered on action.repeated
|
---If true, the callback will be triggered on action.repeated
|
||||||
---@param is_enabled_repeated bool The flag value
|
---@param is_enabled_repeated bool The flag value
|
||||||
---@return druid.hotkey
|
---@return druid.hotkey
|
||||||
function M:set_repeat(is_enabled_repeated)
|
function M:set_repeat(is_enabled_repeated)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid input text component.
|
---Druid input text component.
|
||||||
-- Carry on user text input
|
-- Carry on user text input
|
||||||
--
|
--
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_input" target="_blank"><b>Example Link</b></a>
|
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_input" target="_blank"><b>Example Link</b></a>
|
||||||
@ -9,73 +9,73 @@
|
|||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.input
|
-- @alias druid.input
|
||||||
|
|
||||||
--- On input field select callback(self, input_instance)
|
---On input field select callback(self, input_instance)
|
||||||
-- @tfield event on_input_select event
|
-- @tfield event on_input_select event
|
||||||
|
|
||||||
--- On input field unselect callback(self, input_text, input_instance)
|
---On input field unselect callback(self, input_text, input_instance)
|
||||||
-- @tfield event on_input_unselect event
|
-- @tfield event on_input_unselect event
|
||||||
|
|
||||||
--- On input field text change callback(self, input_text)
|
---On input field text change callback(self, input_text)
|
||||||
-- @tfield event on_input_text event
|
-- @tfield event on_input_text event
|
||||||
|
|
||||||
--- On input field text change to empty string callback(self, input_text)
|
---On input field text change to empty string callback(self, input_text)
|
||||||
-- @tfield event on_input_empty event
|
-- @tfield event on_input_empty event
|
||||||
|
|
||||||
--- On input field text change to max length string callback(self, input_text)
|
---On input field text change to max length string callback(self, input_text)
|
||||||
-- @tfield event on_input_full event
|
-- @tfield event on_input_full event
|
||||||
|
|
||||||
--- On trying user input with not allowed character callback(self, params, input_text)
|
---On trying user input with not allowed character callback(self, params, input_text)
|
||||||
-- @tfield event on_input_wrong event
|
-- @tfield event on_input_wrong event
|
||||||
|
|
||||||
--- On cursor position change callback(self, cursor_index, start_index, end_index)
|
---On cursor position change callback(self, cursor_index, start_index, end_index)
|
||||||
-- @tfield event on_select_cursor_change event
|
-- @tfield event on_select_cursor_change event
|
||||||
|
|
||||||
--- The cursor index. The index of letter cursor after. Leftmost cursor - 0
|
---The cursor index. The index of letter cursor after. Leftmost cursor - 0
|
||||||
-- @tfield number cursor_index
|
-- @tfield number cursor_index
|
||||||
|
|
||||||
--- The selection start index. The index of letter cursor after. Leftmost selection - 0
|
---The selection start index. The index of letter cursor after. Leftmost selection - 0
|
||||||
-- @tfield number start_index
|
-- @tfield number start_index
|
||||||
|
|
||||||
--- Theselection end index. The index of letter cursor before. Rightmost selection - #text
|
---Theselection end index. The index of letter cursor before. Rightmost selection - #text
|
||||||
-- @tfield number end_index
|
-- @tfield number end_index
|
||||||
|
|
||||||
--- Text component
|
---Text component
|
||||||
-- @tfield Text text Text
|
-- @tfield Text text Text
|
||||||
|
|
||||||
--- Current input value
|
---Current input value
|
||||||
-- @tfield string value
|
-- @tfield string value
|
||||||
|
|
||||||
--- Previous input value
|
---Previous input value
|
||||||
-- @tfield string previous_value
|
-- @tfield string previous_value
|
||||||
|
|
||||||
--- Current input value with marked text
|
---Current input value with marked text
|
||||||
-- @tfield string current_value
|
-- @tfield string current_value
|
||||||
|
|
||||||
--- Marked text for input field. Info: https://defold.com/manuals/input-key-and-text/#marked-text
|
---Marked text for input field. Info: https://defold.com/manuals/input-key-and-text/#marked-text
|
||||||
-- @tfield string marked_value
|
-- @tfield string marked_value
|
||||||
|
|
||||||
--- Text width
|
---Text width
|
||||||
-- @tfield number text_width
|
-- @tfield number text_width
|
||||||
|
|
||||||
--- Marked text width
|
---Marked text width
|
||||||
-- @tfield number marked_text_width
|
-- @tfield number marked_text_width
|
||||||
|
|
||||||
--- Button component
|
---Button component
|
||||||
-- @tfield Button button Button
|
-- @tfield Button button Button
|
||||||
|
|
||||||
--- Is current input selected now
|
---Is current input selected now
|
||||||
-- @tfield boolean is_selected
|
-- @tfield boolean is_selected
|
||||||
|
|
||||||
--- Is current input is empty now
|
---Is current input is empty now
|
||||||
-- @tfield boolean is_empty
|
-- @tfield boolean is_empty
|
||||||
|
|
||||||
--- Max length for input text
|
---Max length for input text
|
||||||
-- @tfield number|nil max_length
|
-- @tfield number|nil max_length
|
||||||
|
|
||||||
--- Pattern matching for user input
|
---Pattern matching for user input
|
||||||
-- @tfield string|nil allowerd_characters
|
-- @tfield string|nil allowerd_characters
|
||||||
|
|
||||||
--- Gui keyboard type for input field
|
---Gui keyboard type for input field
|
||||||
-- @tfield number keyboard_type
|
-- @tfield number keyboard_type
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -108,7 +108,7 @@ M.ALLOWED_ACTIONS = {
|
|||||||
[const.ACTION_ESC] = true,
|
[const.ACTION_ESC] = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Mask text by replacing every character with a mask character
|
---Mask text by replacing every character with a mask character
|
||||||
---@param text string
|
---@param text string
|
||||||
---@param mask string
|
---@param mask string
|
||||||
---@return string Masked text
|
---@return string Masked text
|
||||||
@ -132,7 +132,7 @@ local function clear_and_select(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---Component style params.
|
||||||
-- You can override this component styles params in druid styles table
|
-- You can override this component styles params in druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
-- @table style
|
-- @table style
|
||||||
@ -155,7 +155,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The Input constructor
|
---The Input constructor
|
||||||
---@param click_node node Node to enabled input component
|
---@param click_node node Node to enabled input component
|
||||||
---@param text_node node|druid.text Text node what will be changed on user input. You can pass text component instead of text node name Text
|
---@param text_node node|druid.text Text node what will be changed on user input. You can pass text component instead of text node name Text
|
||||||
---@param keyboard_type number|nil Gui keyboard type for input field
|
---@param keyboard_type number|nil Gui keyboard type for input field
|
||||||
@ -326,7 +326,7 @@ function M:get_text_selected()
|
|||||||
return utf8.sub(self.value, self.start_index + 1, self.end_index)
|
return utf8.sub(self.value, self.start_index + 1, self.end_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Replace selected text with new text
|
---Replace selected text with new text
|
||||||
---@param text string The text to replace selected text
|
---@param text string The text to replace selected text
|
||||||
---@return string New input text
|
---@return string New input text
|
||||||
function M:get_text_selected_replaced(text)
|
function M:get_text_selected_replaced(text)
|
||||||
@ -343,7 +343,7 @@ function M:get_text_selected_replaced(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set text for input field
|
---Set text for input field
|
||||||
---@param input_text string The string to apply for input field
|
---@param input_text string The string to apply for input field
|
||||||
function M:set_text(input_text)
|
function M:set_text(input_text)
|
||||||
input_text = tostring(input_text or "")
|
input_text = tostring(input_text or "")
|
||||||
@ -391,7 +391,7 @@ function M:set_text(input_text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Select input field. It will show the keyboard and trigger on_select events
|
---Select input field. It will show the keyboard and trigger on_select events
|
||||||
function M:select()
|
function M:select()
|
||||||
gui.reset_keyboard()
|
gui.reset_keyboard()
|
||||||
self.marked_value = ""
|
self.marked_value = ""
|
||||||
@ -415,7 +415,7 @@ function M:select()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove selection from input. It will hide the keyboard and trigger on_unselect events
|
---Remove selection from input. It will hide the keyboard and trigger on_unselect events
|
||||||
function M:unselect()
|
function M:unselect()
|
||||||
gui.reset_keyboard()
|
gui.reset_keyboard()
|
||||||
self.marked_value = ""
|
self.marked_value = ""
|
||||||
@ -433,7 +433,7 @@ function M:unselect()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current input field text
|
---Return current input field text
|
||||||
---@return string The current input field text
|
---@return string The current input field text
|
||||||
function M:get_text()
|
function M:get_text()
|
||||||
if self.marked_value ~= "" then
|
if self.marked_value ~= "" then
|
||||||
@ -444,7 +444,7 @@ function M:get_text()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set maximum length for input field.
|
---Set maximum length for input field.
|
||||||
-- Pass nil to make input field unliminted (by default)
|
-- Pass nil to make input field unliminted (by default)
|
||||||
---@param max_length number Maximum length for input text field
|
---@param max_length number Maximum length for input text field
|
||||||
---@return druid.input Current input instance
|
---@return druid.input Current input instance
|
||||||
@ -454,7 +454,7 @@ function M:set_max_length(max_length)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set allowed charaters for input field.
|
---Set allowed charaters for input field.
|
||||||
-- See: https://defold.com/ref/stable/string/
|
-- See: https://defold.com/ref/stable/string/
|
||||||
-- ex: [%a%d] for alpha and numeric
|
-- ex: [%a%d] for alpha and numeric
|
||||||
---@param characters string Regulax exp. for validate user input
|
---@param characters string Regulax exp. for validate user input
|
||||||
@ -465,7 +465,7 @@ function M:set_allowed_characters(characters)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Reset current input selection and return previous value
|
---Reset current input selection and return previous value
|
||||||
---@return druid.input Current input instance
|
---@return druid.input Current input instance
|
||||||
function M:reset_changes()
|
function M:reset_changes()
|
||||||
self:set_text(self.previous_value)
|
self:set_text(self.previous_value)
|
||||||
@ -474,7 +474,7 @@ function M:reset_changes()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set cursor position in input field
|
---Set cursor position in input field
|
||||||
---@param cursor_index number|nil Cursor index for cursor position, if nil - will be set to the end of the text
|
---@param cursor_index number|nil Cursor index for cursor position, if nil - will be set to the end of the text
|
||||||
---@param start_index number|nil Start index for cursor position, if nil - will be set to the end of the text
|
---@param start_index number|nil Start index for cursor position, if nil - will be set to the end of the text
|
||||||
---@param end_index number|nil End index for cursor position, if nil - will be set to the start_index
|
---@param end_index number|nil End index for cursor position, if nil - will be set to the start_index
|
||||||
@ -496,7 +496,7 @@ function M:select_cursor(cursor_index, start_index, end_index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Change cursor position by delta
|
---Change cursor position by delta
|
||||||
---@param delta number side for cursor position, -1 for left, 1 for right
|
---@param delta number side for cursor position, -1 for left, 1 for right
|
||||||
---@param is_add_to_selection boolean (Shift key)
|
---@param is_add_to_selection boolean (Shift key)
|
||||||
---@param is_move_to_end boolean (Ctrl key)
|
---@param is_move_to_end boolean (Ctrl key)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Component to wrap over GUI Text nodes with localization helpers
|
---Component to wrap over GUI Text nodes with localization helpers
|
||||||
--
|
--
|
||||||
-- <b># Overview #</b>
|
-- <b># Overview #</b>
|
||||||
--
|
--
|
||||||
@ -17,13 +17,13 @@
|
|||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.lang_text
|
-- @alias druid.lang_text
|
||||||
|
|
||||||
--- On change text callback
|
---On change text callback
|
||||||
-- @tfield event on_change event
|
-- @tfield event on_change event
|
||||||
|
|
||||||
--- The text component
|
---The text component
|
||||||
-- @tfield Text text Text
|
-- @tfield Text text Text
|
||||||
|
|
||||||
--- Text node
|
---Text node
|
||||||
-- @tfield node node
|
-- @tfield node node
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -41,7 +41,7 @@ local component = require("druid.component")
|
|||||||
local M = component.create("lang_text")
|
local M = component.create("lang_text")
|
||||||
|
|
||||||
|
|
||||||
--- The LangText constructor
|
---The LangText constructor
|
||||||
---@param node string|node The node_id or gui.get_node(node_id)
|
---@param node string|node The node_id or gui.get_node(node_id)
|
||||||
---@param locale_id string|nil Default locale id or text from node as default
|
---@param locale_id string|nil Default locale id or text from node as default
|
||||||
---@param adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
|
---@param adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
|
||||||
@ -67,7 +67,7 @@ function M:on_language_change()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Setup raw text to lang_text component
|
---Setup raw text to lang_text component
|
||||||
---@param text string Text for text node
|
---@param text string Text for text node
|
||||||
---@return druid.lang_text Current instance
|
---@return druid.lang_text Current instance
|
||||||
function M:set_to(text)
|
function M:set_to(text)
|
||||||
@ -79,7 +79,7 @@ function M:set_to(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Setup raw text to lang_text component
|
---Setup raw text to lang_text component
|
||||||
---@param text string Text for text node
|
---@param text string Text for text node
|
||||||
---@return druid.lang_text Current instance
|
---@return druid.lang_text Current instance
|
||||||
function M:set_text(text)
|
function M:set_text(text)
|
||||||
@ -87,7 +87,7 @@ function M:set_text(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Translate the text by locale_id
|
---Translate the text by locale_id
|
||||||
---@param locale_id string Locale id
|
---@param locale_id string Locale id
|
||||||
---@param ... string Optional params for string.format
|
---@param ... string Optional params for string.format
|
||||||
---@return druid.lang_text Current instance
|
---@return druid.lang_text Current instance
|
||||||
@ -100,7 +100,7 @@ function M:translate(locale_id, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Format string with new text params on localized text
|
---Format string with new text params on localized text
|
||||||
---@param ... string Optional params for string.format
|
---@param ... string Optional params for string.format
|
||||||
---@return druid.lang_text Current instance
|
---@return druid.lang_text Current instance
|
||||||
function M:format(...)
|
function M:format(...)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid component to handle the progress bars.
|
---Druid component to handle the progress bars.
|
||||||
-- <b># Overview #</b>
|
-- <b># Overview #</b>
|
||||||
--
|
--
|
||||||
-- <b># Notes #</b>
|
-- <b># Notes #</b>
|
||||||
@ -19,27 +19,27 @@
|
|||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.progress
|
-- @alias druid.progress
|
||||||
|
|
||||||
--- On progress bar change callback(self, new_value)
|
---On progress bar change callback(self, new_value)
|
||||||
-- @tfield event on_change event
|
-- @tfield event on_change event
|
||||||
|
|
||||||
--- Progress bar fill node
|
---Progress bar fill node
|
||||||
-- @tfield node node
|
-- @tfield node node
|
||||||
|
|
||||||
--- The progress bar direction.
|
---The progress bar direction.
|
||||||
--
|
--
|
||||||
-- The values are: "x" or "y". (const.SIDE.X or const.SIDE.Y)
|
-- The values are: "x" or "y". (const.SIDE.X or const.SIDE.Y)
|
||||||
-- @tfield string key
|
-- @tfield string key
|
||||||
|
|
||||||
--- Current progress bar scale
|
---Current progress bar scale
|
||||||
-- @tfield vector3 scale
|
-- @tfield vector3 scale
|
||||||
|
|
||||||
--- Current progress bar size
|
---Current progress bar size
|
||||||
-- @tfield vector3 size
|
-- @tfield vector3 size
|
||||||
|
|
||||||
--- Maximum size of progress bar
|
---Maximum size of progress bar
|
||||||
-- @tfield number max_size
|
-- @tfield number max_size
|
||||||
|
|
||||||
--- Progress bar slice9 settings
|
---Progress bar slice9 settings
|
||||||
-- @tfield vector4 slice
|
-- @tfield vector4 slice
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -117,7 +117,7 @@ local function set_bar_to(self, set_to, is_silent)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Component style params.
|
---Component style params.
|
||||||
-- You can override this component styles params in druid styles table
|
-- You can override this component styles params in druid styles table
|
||||||
-- or create your own style
|
-- or create your own style
|
||||||
-- @table style
|
-- @table style
|
||||||
@ -130,7 +130,7 @@ function M:on_style_change(style)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The Progress constructor
|
---The Progress constructor
|
||||||
---@param node string|node Node name or GUI Node itself.
|
---@param node string|node Node name or GUI Node itself.
|
||||||
---@param key string Progress bar direction: const.SIDE.X or const.SIDE.Y
|
---@param key string Progress bar direction: const.SIDE.X or const.SIDE.Y
|
||||||
---@param init_value number|nil Initial value of progress bar. Default: 1
|
---@param init_value number|nil Initial value of progress bar. Default: 1
|
||||||
@ -191,19 +191,19 @@ function M:update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Fill a progress bar and stop progress animation
|
---Fill a progress bar and stop progress animation
|
||||||
function M:fill()
|
function M:fill()
|
||||||
set_bar_to(self, 1, true)
|
set_bar_to(self, 1, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Empty a progress bar
|
---Empty a progress bar
|
||||||
function M:empty()
|
function M:empty()
|
||||||
set_bar_to(self, 0, true)
|
set_bar_to(self, 0, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Instant fill progress bar to value
|
---Instant fill progress bar to value
|
||||||
---@param to number Progress bar value, from 0 to 1
|
---@param to number Progress bar value, from 0 to 1
|
||||||
function M:set_to(to)
|
function M:set_to(to)
|
||||||
to = helper.clamp(to, 0, 1)
|
to = helper.clamp(to, 0, 1)
|
||||||
@ -211,13 +211,13 @@ function M:set_to(to)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return current progress bar value
|
---Return current progress bar value
|
||||||
function M:get()
|
function M:get()
|
||||||
return self.last_value
|
return self.last_value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set points on progress bar to fire the callback
|
---Set points on progress bar to fire the callback
|
||||||
---@param steps number[] Array of progress bar values
|
---@param steps number[] Array of progress bar values
|
||||||
---@param callback function Callback on intersect step value
|
---@param callback function Callback on intersect step value
|
||||||
-- @usage progress:set_steps({0, 0.3, 0.6, 1}, function(self, step) end)
|
-- @usage progress:set_steps({0, 0.3, 0.6, 1}, function(self, step) end)
|
||||||
@ -227,7 +227,7 @@ function M:set_steps(steps, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Start animation of a progress bar
|
---Start animation of a progress bar
|
||||||
---@param to number value between 0..1
|
---@param to number value between 0..1
|
||||||
---@param callback function|nil Callback on animation ends
|
---@param callback function|nil Callback on animation ends
|
||||||
function M:to(to, callback)
|
function M:to(to, callback)
|
||||||
@ -245,7 +245,7 @@ function M:to(to, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set progress bar max node size
|
---Set progress bar max node size
|
||||||
---@param max_size vector3 The new node maximum (full) size
|
---@param max_size vector3 The new node maximum (full) size
|
||||||
---@return druid.progress Progress
|
---@return druid.progress Progress
|
||||||
function M:set_max_size(max_size)
|
function M:set_max_size(max_size)
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||||
|
|
||||||
--- Druid slider component
|
---Druid slider component
|
||||||
--
|
--
|
||||||
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_sliders" target="_blank"><b>Example Link</b></a>
|
-- <a href="https://insality.github.io/druid/druid/index.html?example=general_sliders" target="_blank"><b>Example Link</b></a>
|
||||||
-- @module Slider
|
-- @module Slider
|
||||||
-- @within BaseComponent
|
-- @within BaseComponent
|
||||||
-- @alias druid.slider
|
-- @alias druid.slider
|
||||||
|
|
||||||
--- On change value callback(self, value)
|
---On change value callback(self, value)
|
||||||
-- @tfield event on_change_value event
|
-- @tfield event on_change_value event
|
||||||
|
|
||||||
--- Slider pin node
|
---Slider pin node
|
||||||
-- @tfield node node
|
-- @tfield node node
|
||||||
|
|
||||||
--- Start pin node position
|
---Start pin node position
|
||||||
-- @tfield vector3 start_pos
|
-- @tfield vector3 start_pos
|
||||||
|
|
||||||
--- Current pin node position
|
---Current pin node position
|
||||||
-- @tfield vector3 pos
|
-- @tfield vector3 pos
|
||||||
|
|
||||||
--- Targer pin node position
|
---Targer pin node position
|
||||||
-- @tfield vector3 target_pos
|
-- @tfield vector3 target_pos
|
||||||
|
|
||||||
--- End pin node position
|
---End pin node position
|
||||||
-- @tfield vector3 end_pos
|
-- @tfield vector3 end_pos
|
||||||
|
|
||||||
--- Length between start and end position
|
---Length between start and end position
|
||||||
-- @tfield vector3 dist
|
-- @tfield vector3 dist
|
||||||
|
|
||||||
--- Current drag state
|
---Current drag state
|
||||||
-- @tfield boolean is_drag
|
-- @tfield boolean is_drag
|
||||||
|
|
||||||
--- Current slider value
|
---Current slider value
|
||||||
-- @tfield number value
|
-- @tfield number value
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -68,7 +68,7 @@ local function set_position(self, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- The Slider constructor
|
---The Slider constructor
|
||||||
---@param node node Gui pin node
|
---@param node node Gui pin node
|
||||||
---@param end_pos vector3 The end position of slider
|
---@param end_pos vector3 The end position of slider
|
||||||
---@param callback function|nil On slider change callback
|
---@param callback function|nil On slider change callback
|
||||||
@ -195,7 +195,7 @@ function M:on_input(action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set value for slider
|
---Set value for slider
|
||||||
---@param value number Value from 0 to 1
|
---@param value number Value from 0 to 1
|
||||||
---@param is_silent boolean|nil Don't trigger event if true
|
---@param is_silent boolean|nil Don't trigger event if true
|
||||||
function M:set(value, is_silent)
|
function M:set(value, is_silent)
|
||||||
@ -208,7 +208,7 @@ function M:set(value, is_silent)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set slider steps. Pin node will
|
---Set slider steps. Pin node will
|
||||||
-- apply closest step position
|
-- apply closest step position
|
||||||
---@param steps number[] Array of steps
|
---@param steps number[] Array of steps
|
||||||
-- @usage slider:set_steps({0, 0.2, 0.6, 1})
|
-- @usage slider:set_steps({0, 0.2, 0.6, 1})
|
||||||
@ -219,7 +219,7 @@ function M:set_steps(steps)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set input zone for slider.
|
---Set input zone for slider.
|
||||||
-- User can touch any place of node, pin instantly will
|
-- User can touch any place of node, pin instantly will
|
||||||
-- move at this position and node drag will start.
|
-- move at this position and node drag will start.
|
||||||
-- This function require the Defold version 1.3.0+
|
-- This function require the Defold version 1.3.0+
|
||||||
@ -236,14 +236,14 @@ function M:set_input_node(input_node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set Slider input enabled or disabled
|
---Set Slider input enabled or disabled
|
||||||
---@param is_enabled boolean
|
---@param is_enabled boolean
|
||||||
function M:set_enabled(is_enabled)
|
function M:set_enabled(is_enabled)
|
||||||
self._is_enabled = is_enabled
|
self._is_enabled = is_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Check if Slider component is enabled
|
---Check if Slider component is enabled
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M:is_enabled()
|
function M:is_enabled()
|
||||||
return self._is_enabled
|
return self._is_enabled
|
||||||
|
@ -96,7 +96,7 @@ function M:on_input_interrupt()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Strict swipe click area. Useful for
|
---Strict swipe click area. Useful for
|
||||||
-- restrict events outside stencil node
|
-- restrict events outside stencil node
|
||||||
---@param zone node|string|nil Gui node
|
---@param zone node|string|nil Gui node
|
||||||
function M:set_click_zone(zone)
|
function M:set_click_zone(zone)
|
||||||
|
@ -7,7 +7,7 @@ local gui_pick_node = gui.pick_node
|
|||||||
|
|
||||||
---The helper module contains various functions that are used in the Druid library.
|
---The helper module contains various functions that are used in the Druid library.
|
||||||
---You can use these functions in your projects as well.
|
---You can use these functions in your projects as well.
|
||||||
---@class druid.system.helper
|
---@class druid.helper
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local POSITION_X = hash("position.x")
|
local POSITION_X = hash("position.x")
|
||||||
@ -44,15 +44,15 @@ local function is_text_node(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Text node or icon node can be nil
|
---Text node or icon node can be nil
|
||||||
local function get_width(node)
|
local function get_width(node)
|
||||||
return is_text_node(node) and get_text_width(node) or get_icon_width(node)
|
return is_text_node(node) and get_text_width(node) or get_icon_width(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---Center two nodes.
|
---Center two nodes.
|
||||||
--Nodes will be center around 0 x position
|
---Nodes will be center around 0 x position
|
||||||
--text_node will be first (at left side)
|
---text_node will be first (at left side)
|
||||||
---@param text_node node|nil Gui text node
|
---@param text_node node|nil Gui text node
|
||||||
---@param icon_node node|nil Gui box node
|
---@param icon_node node|nil Gui box node
|
||||||
---@param margin number Offset between nodes
|
---@param margin number Offset between nodes
|
||||||
@ -63,8 +63,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---Center two nodes.
|
---Center two nodes.
|
||||||
--Nodes will be center around 0 x position
|
---Nodes will be center around 0 x position
|
||||||
--icon_node will be first (at left side)
|
---icon_node will be first (at left side)
|
||||||
---@param icon_node node|nil Gui box node
|
---@param icon_node node|nil Gui box node
|
||||||
---@param text_node node|nil Gui text node
|
---@param text_node node|nil Gui text node
|
||||||
---@param margin number|nil Offset between nodes
|
---@param margin number|nil Offset between nodes
|
||||||
@ -115,8 +115,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---@param node_id string|node
|
---@param node_id string|node
|
||||||
---@param template string|nil @Full Path to the template
|
---@param template string|nil Full Path to the template
|
||||||
---@param nodes table<hash, node>|nil @Nodes what created with gui.clone_tree
|
---@param nodes table<hash, node>|nil Nodes what created with gui.clone_tree
|
||||||
---@return node
|
---@return node
|
||||||
function M.get_node(node_id, template, nodes)
|
function M.get_node(node_id, template, nodes)
|
||||||
if type(node_id) ~= "string" then
|
if type(node_id) ~= "string" then
|
||||||
@ -177,7 +177,7 @@ function M.step(current, target, step)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---Clamp value between min and max
|
---Clamp value between min and max. Works with nil values and swap min and max if needed.
|
||||||
---@param value number Value
|
---@param value number Value
|
||||||
---@param v1 number|nil Min value. If nil, value will be clamped to positive infinity
|
---@param v1 number|nil Min value. If nil, value will be clamped to positive infinity
|
||||||
---@param v2 number|nil Max value If nil, value will be clamped to negative infinity
|
---@param v2 number|nil Max value If nil, value will be clamped to negative infinity
|
||||||
@ -450,15 +450,20 @@ function M.get_border(node, offset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local TEXT_METRICS_OPTIONS = {
|
||||||
|
line_break = false,
|
||||||
|
tracking = 0,
|
||||||
|
leading = 0,
|
||||||
|
width = 0,
|
||||||
|
}
|
||||||
|
|
||||||
---Get text metric from GUI node.
|
---Get text metric from GUI node.
|
||||||
---@param text_node node
|
---@param text_node node
|
||||||
---@return GUITextMetrics
|
---@return GUITextMetrics
|
||||||
function M.get_text_metrics_from_node(text_node)
|
function M.get_text_metrics_from_node(text_node)
|
||||||
local font_resource = gui.get_font_resource(gui.get_font(text_node))
|
local options = TEXT_METRICS_OPTIONS
|
||||||
local options = {
|
options.tracking = gui.get_tracking(text_node)
|
||||||
tracking = gui.get_tracking(text_node),
|
options.line_break = gui.get_line_break(text_node)
|
||||||
line_break = gui.get_line_break(text_node),
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Gather other options only if it used in node
|
-- Gather other options only if it used in node
|
||||||
if options.line_break then
|
if options.line_break then
|
||||||
@ -466,6 +471,7 @@ function M.get_text_metrics_from_node(text_node)
|
|||||||
options.leading = gui.get_leading(text_node)
|
options.leading = gui.get_leading(text_node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local font_resource = gui.get_font_resource(gui.get_font(text_node))
|
||||||
return resource.get_text_metrics(font_resource, gui.get_text(text_node), options)
|
return resource.get_text_metrics(font_resource, gui.get_text(text_node), options)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -548,16 +554,16 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---@class druid.animation_data
|
---@class druid.animation_data
|
||||||
---@field frames table<number, table<string, number>> @List of frames with uv coordinates and size
|
---@field frames table<number, table<string, number>> List of frames with uv coordinates and size
|
||||||
---@field width number @Width of the animation
|
---@field width number Width of the animation
|
||||||
---@field height number @Height of the animation
|
---@field height number Height of the animation
|
||||||
---@field fps number @Frames per second
|
---@field fps number Frames per second
|
||||||
---@field current_frame number @Current frame
|
---@field current_frame number Current frame
|
||||||
---@field node node @Node with flipbook animation
|
---@field node node Node with flipbook animation
|
||||||
---@field v vector4 @Vector with UV coordinates and size
|
---@field v vector4 Vector with UV coordinates and size
|
||||||
|
|
||||||
---@param node node
|
---@param node node
|
||||||
---@param atlas_path string @Path to the atlas
|
---@param atlas_path string Path to the atlas
|
||||||
---@return druid.animation_data
|
---@return druid.animation_data
|
||||||
function M.get_animation_data_from_node(node, atlas_path)
|
function M.get_animation_data_from_node(node, atlas_path)
|
||||||
local atlas_data = resource.get_atlas(atlas_path)
|
local atlas_data = resource.get_atlas(atlas_path)
|
||||||
|
@ -204,7 +204,7 @@ local function schedule_late_init(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Druid class constructor
|
---Druid class constructor
|
||||||
---@param context table Druid context. Usually it is self of gui script
|
---@param context table Druid context. Usually it is self of gui script
|
||||||
---@param style table? Druid style table
|
---@param style table? Druid style table
|
||||||
function M:initialize(context, style)
|
function M:initialize(context, style)
|
||||||
@ -247,7 +247,7 @@ function M:new(component, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Call this in gui_script final function.
|
---Call this in gui_script final function.
|
||||||
function M:final()
|
function M:final()
|
||||||
local components = self.components_all
|
local components = self.components_all
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ function M:final()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Remove created component from Druid instance.
|
---Remove created component from Druid instance.
|
||||||
--
|
--
|
||||||
-- Component `on_remove` function will be invoked, if exist.
|
-- Component `on_remove` function will be invoked, if exist.
|
||||||
---@generic T: druid.component
|
---@generic T: druid.component
|
||||||
@ -369,7 +369,7 @@ function M:on_input(action_id, action)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Call this in gui_script on_message function.
|
---Call this in gui_script on_message function.
|
||||||
---@param message_id hash Message_id from on_message
|
---@param message_id hash Message_id from on_message
|
||||||
---@param message table Message from on_message
|
---@param message table Message from on_message
|
||||||
---@param sender url Sender from on_message
|
---@param sender url Sender from on_message
|
||||||
@ -410,7 +410,7 @@ function M:on_window_event(window_event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Calls the on_language_change function in all related components
|
---Calls the on_language_change function in all related components
|
||||||
-- This one called by global druid.on_language_change, but can be
|
-- This one called by global druid.on_language_change, but can be
|
||||||
-- call manualy to update all translations
|
-- call manualy to update all translations
|
||||||
---@private
|
---@private
|
||||||
|
@ -59,14 +59,14 @@ function M:on_click()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set the text property of the checkbox
|
---Set the text property of the checkbox
|
||||||
---@param text string
|
---@param text string
|
||||||
function M:set_text_property(text)
|
function M:set_text_property(text)
|
||||||
self.text_name:set_text(text)
|
self.text_name:set_text(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Set the callback function for when the checkbox value changes
|
---Set the callback function for when the checkbox value changes
|
||||||
---@param callback function
|
---@param callback function
|
||||||
function M:on_change(callback)
|
function M:on_change(callback)
|
||||||
self.on_change_value:subscribe(callback)
|
self.on_change_value:subscribe(callback)
|
||||||
|
@ -47,14 +47,14 @@ function M:set_text_function(callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Sets the text property of the slider
|
---Sets the text property of the slider
|
||||||
---@param text string
|
---@param text string
|
||||||
function M:set_text_property(text)
|
function M:set_text_property(text)
|
||||||
self.text_name:set_text(text)
|
self.text_name:set_text(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Sets the callback function for when the slider value changes
|
---Sets the callback function for when the slider value changes
|
||||||
---@param callback fun(value:number)
|
---@param callback fun(value:number)
|
||||||
function M:on_change(callback)
|
function M:on_change(callback)
|
||||||
self.on_change_value:subscribe(callback)
|
self.on_change_value:subscribe(callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user