Refactor text setting methods and remove ldoc files

This commit is contained in:
Insality
2024-12-08 13:35:41 +02:00
parent 9a1cd795b8
commit 6b8bbe1970
26 changed files with 158 additions and 544 deletions

View File

@@ -485,7 +485,11 @@ end
---@param key hash|string The action_id of the input key. Example: "key_space"
---@return druid.button self
function M:set_key_trigger(key)
self.key_trigger = hash(key)
if type(key) == "string" then
self.key_trigger = hash(key)
else
self.key_trigger = key
end
return self
end
@@ -498,22 +502,24 @@ function M:get_key_trigger()
end
--- Set function for additional check for button click availability
---Set function for additional check for button click availability
---@param check_function function|nil Should return true or false. If true - button can be pressed.
---@param failure_callback function|nil Function will be called on button click, if check function return false
---@return druid.button self
function M:set_check_function(check_function, failure_callback)
self._check_function = check_function
self._failure_callback = failure_callback
return self
end
--- Set Button mode to work inside user HTML5 interaction event.
--
-- It's required to make protected things like copy & paste text, show mobile keyboard, etc
-- The HTML5 button's doesn't call any events except on_click event.
--
-- If the game is not HTML, html mode will be not enabled
---Set Button mode to work inside user HTML5 interaction event.
---
---It's required to make protected things like copy & paste text, show mobile keyboard, etc
---The HTML5 button's doesn't call any events except on_click event.
---
---If the game is not HTML, html mode will be not enabled
---@param is_web_mode boolean|nil If true - button will be called inside html5 callback
---@return druid.button self
function M:set_web_user_interaction(is_web_mode)

View File

@@ -206,9 +206,10 @@ end
-- @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)
self.style = {}
self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10
self.style.NO_USE_SCREEN_KOEF = style.NO_USE_SCREEN_KOEF or false
self.style = {
DRAG_DEADZONE = style.DRAG_DEADZONE or 10,
NO_USE_SCREEN_KOEF = style.NO_USE_SCREEN_KOEF or false,
}
end

View File

@@ -27,9 +27,9 @@ local component = require("druid.component")
---@field on_mouse_hover event
---@field style table
---@field click_zone node
---@field private _is_hovered boolean
---@field private _is_mouse_hovered boolean
---@field private _is_enabled boolean
---@field private _is_hovered boolean|nil
---@field private _is_mouse_hovered boolean|nil
---@field private _is_enabled boolean|nil
---@field private _is_mobile boolean
local M = component.create("hover")
@@ -163,6 +163,11 @@ end
-- no click events outside stencil node
---@param zone node|string|nil Gui node
function M:set_click_zone(zone)
if not zone then
self.click_zone = nil
return
end
self.click_zone = self:get_node(zone)
end

View File

@@ -515,22 +515,22 @@ function M:set_pivot(pivot)
end
--- Return true, if text with line break
---Return true, if text with line break
---@return boolean Is text node with line break
function M:is_multiline()
return gui.get_line_break(self.node)
end
--- Set text adjust, refresh the current text visuals, if needed
---Set text adjust, refresh the current text visuals, if needed
---Values are: "downscale", "trim", "no_adjust", "downscale_limited",
---"scroll", "scale_then_scroll", "trim_left", "scale_then_trim", "scale_then_trim_left"
---@param adjust_type string|nil See const.TEXT_ADJUST. If pass nil - use current adjust type
---@param minimal_scale number|nil If pass nil - not use minimal scale
---@param minimal_scale number|nil To remove minimal scale, use `text:set_minimal_scale(nil)`, if pass nil - not change minimal scale
---@return druid.text self Current text instance
function M:set_text_adjust(adjust_type, minimal_scale)
self.adjust_type = adjust_type
self._minimal_scale = minimal_scale
self._minimal_scale = minimal_scale or self._minimal_scale
self:set_text(self.last_value)
return self

View File

@@ -21,18 +21,18 @@ local helper = require("druid.helper")
---@class druid.base_component
---@field druid druid_instance Druid instance to create inner components
---@field protected init fun(self:druid.base_component, ...)|nil
---@field protected update fun(self:druid.base_component, dt:number)|nil
---@field protected on_remove fun(self:druid.base_component)|nil
---@field protected on_input fun(self:druid.base_component, action_id:number, action:table)|nil
---@field protected on_message fun(self:druid.base_component, message_id:hash, message:table, sender:userdata)|nil
---@field protected on_late_init fun(self:druid.base_component)|nil
---@field protected on_focus_lost fun(self:druid.base_component)|nil
---@field protected on_focus_gained fun(self:druid.base_component)|nil
---@field protected on_style_change fun(self:druid.base_component, style: table)|nil
---@field protected on_layout_change fun(self:druid.base_component)|nil
---@field protected on_window_resized fun(self:druid.base_component, width:number, height:number)|nil
---@field protected on_language_change fun(self:druid.base_component, language:string)|nil
---@field init fun(self:druid.base_component, ...)|nil
---@field update fun(self:druid.base_component, dt:number)|nil
---@field on_remove fun(self:druid.base_component)|nil
---@field on_input fun(self:druid.base_component, action_id:number, action:table)|nil
---@field on_message fun(self:druid.base_component, message_id:hash, message:table, sender:userdata)|nil
---@field on_late_init fun(self:druid.base_component)|nil
---@field on_focus_lost fun(self:druid.base_component)|nil
---@field on_focus_gained fun(self:druid.base_component)|nil
---@field on_style_change fun(self:druid.base_component, style: table)|nil
---@field on_layout_change fun(self:druid.base_component)|nil
---@field on_window_resized fun(self:druid.base_component)|nil
---@field on_language_change fun(self:druid.base_component)|nil
---@field private _component druid.base_component.component
---@field private _meta druid.base_component.meta
local M = {}

View File

@@ -181,7 +181,7 @@ function M.create(text, settings, style)
outline = settings.outline,
font = gui.get_font(settings.text_prefab),
-- Image params
---@type druid.rich_text.image
---@type druid.rich_text.word.image
image = nil,
-- Tags
br = nil,

View File

@@ -76,6 +76,27 @@
local component = require("druid.component")
local rich_text = require("druid.custom.rich_text.module.rt")
---@class druid.rich_text.settings
---@field parent node
---@field size number
---@field fonts table<string, string>
---@field scale vector3
---@field color vector4
---@field shadow vector4
---@field outline vector4
---@field position vector3
---@field image_pixel_grid_snap boolean
---@field combine_words boolean
---@field default_animation string
---@field text_prefab node
---@field adjust_scale number
---@field default_texture string
---@field is_multiline boolean
---@field text_leading number
---@field font hash
---@field width number
---@field height number
---@class druid.rich_text.word
---@field node node
---@field relative_scale number

View File

@@ -51,13 +51,13 @@ local event = require("event.event")
---@field private _cache table
---@field private _data table
---@field private _data_visual table
---@field private top_index number
---@field top_index number
local M = component.create("data_list")
--- The DataList constructor
---@param scroll Scroll The Scroll instance for Data List component
---@param grid StaticGrid The StaticGrid} or @{DynamicGrid 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 create_function function The create function callback(self, data, index, data_list). Function should return (node, [component])
function M:init(scroll, grid, create_function)
self.scroll = scroll

View File

@@ -157,7 +157,7 @@ end
--- The Input constructor
---@param click_node node Node to enabled input component
---@param text_node node|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
function M:init(click_node, text_node, keyboard_type)
self.druid = self:get_druid()

View File

@@ -10,13 +10,13 @@
-- @alias druid.swipe
--- Swipe node
---@param node node
--@param node node
--- Restriction zone
---@param click_zone node|nil
--@param click_zone node|nil
--- Trigger on swipe event(self, swipe_side, dist, delta_time)
---@param event event on_swipe
--@param event event on_swipe
---
@@ -59,7 +59,7 @@ local function check_swipe(self, action)
if is_swipe then
local is_x_swipe = math.abs(dx) >= math.abs(dy)
local swipe_side = false
local swipe_side = "undefined"
if is_x_swipe and dx > 0 then
swipe_side = "right"
@@ -164,6 +164,11 @@ end
-- restrict events outside stencil node
---@param zone node|string|nil Gui node
function M:set_click_zone(zone)
if not zone then
self.click_zone = nil
return
end
self.click_zone = self:get_node(zone)
end

View File

@@ -311,9 +311,9 @@ end
---Get size of node with scale multiplier
---@param node node GUI node
---@treturn vector3 Scaled size
---@return vector3 scaled_size
function M.get_scaled_size(node)
return vmath.mul_per_elem(gui.get_size(node), gui.get_scale(node))
return vmath.mul_per_elem(gui.get_size(node), gui.get_scale(node)) --[[@as vector3]]
end

View File

@@ -32,16 +32,11 @@ void main()
var_perspective = perspective;
var_uv_rotated = uv_rotated;
float perspective_y = position.z;
float scale_x = 1.0 - abs(perspective.x);
float scale_y = 1.0 - abs(perspective_y);
mat4 transform = mat4(
scale_x, 0, 0, perspective.z,
0, scale_y, 0, perspective.w,
1.0, 0, 0, 0.0,
0, 1.0, 0, 0.0,
0, 0, 1, 0,
perspective.x, perspective_y, 0, 1.0
0.0, position.z, 0, 1.0
);
// Matrix Info = mat4(

View File

@@ -1,2 +1,55 @@
---@class druid.widget: druid.base_component
---@field druid druid_instance
---@field druid druid_instance
---@class GUITextMetrics
---@field width number
---@field height number
---@field max_ascent number
---@field max_descent number
---@class utf8
---@field len fun(s: string):number
---@field sub fun(s: string, start_index: number, length: number)
---@field reverse fun()
---@field char fun()
---@field unicode fun()
---@field gensub fun()
---@field byte fun()
---@field find fun()
---@field match fun(s: string, m: string)
---@field gmatch fun(s: string, m: string)
---@field gsub fun()
---@field dump fun()
---@field format fun()
---@field lower fun()
---@field upper fun()
---@field rep fun()
---@class action
---@field value number The amount of input given by the user. This is usually 1 for buttons and 0-1 for analogue inputs. This is not present for mouse movement.
---@field pressed boolean If the input was pressed this frame. This is not present for mouse movement.
---@field released boolean If the input was released this frame. This is not present for mouse movement.
---@field repeated boolean If the input was repeated this frame. This is similar to how a key on a keyboard is repeated when you hold it down. This is not present for mouse movement.
---@field x number The x value of a pointer device, if present.
---@field y number The y value of a pointer device, if present.
---@field screen_x number The screen space x value of a pointer device, if present.
---@field screen_y number The screen space y value of a pointer device, if present.
---@field dx number The change in x value of a pointer device, if present.
---@field dy number The change in y value of a pointer device, if present.
---@field screen_dx number The change in screen space x value of a pointer device, if present.
---@field screen_dy number The change in screen space y value of a pointer device, if present.
---@field gamepad number The index of the gamepad device that provided the input.
---@field touch touch[] List of touch input, one element per finger, if present. See table below about touch input
---@class touch
---@field id number A number identifying the touch input during its duration.
---@field pressed boolean True if the finger was pressed this frame.
---@field released boolean True if the finger was released this frame.
---@field tap_count number Number of taps, one for single, two for double-tap, etc
---@field x number The x touch location.
---@field y number The y touch location.
---@field dx number The change in x value.
---@field dy number The change in y value.
---@field acc_x number|nil Accelerometer x value (if present).
---@field acc_y number|nil Accelerometer y value (if present).
---@field acc_z number|nil Accelerometer z value (if present).

View File

@@ -147,10 +147,9 @@ end
---Check whitelists and blacklists for input components
---@param self druid_instance
---@param component druid.base_component
---@return boolean
local function can_use_input_component(self, component)
function M:_can_use_input_component(component)
local can_by_whitelist = true
local can_by_blacklist = true
@@ -166,13 +165,13 @@ local function can_use_input_component(self, component)
end
local function process_input(self, action_id, action, components)
function M:_process_input(action_id, action, components)
local is_input_consumed = false
for i = #components, 1, -1 do
local component = components[i]
local meta = component._meta
if meta.input_enabled and can_use_input_component(self, component) then
if meta.input_enabled and self:_can_use_input_component(component) then
if not is_input_consumed then
is_input_consumed = component:on_input(action_id, action) or false
else
@@ -356,7 +355,7 @@ function M:on_input(action_id, action)
local components = self.components_interest[const.ON_INPUT]
check_sort_input_stack(self, components)
local is_input_consumed = process_input(self, action_id, action, components)
local is_input_consumed = self:_process_input(action_id, action, components)
self._is_late_remove_enabled = false
self:_clear_late_remove()
@@ -421,7 +420,7 @@ end
---Set whitelist components for input processing.
---If whitelist is not empty and component not contains in this list,
---component will be not processed on input step
---@param whitelist_components table|druid.base_component[]|nil The array of component to whitelist
---@param whitelist_components table|druid.base_component[] The array of component to whitelist
---@return druid_instance
function M:set_whitelist(whitelist_components)
if whitelist_components and whitelist_components._component then
@@ -441,7 +440,7 @@ end
---Set blacklist components for input processing.
---If blacklist is not empty and component contains in this list,
---component will be not processed on input step DruidInstance
---@param blacklist_components table|druid.base_component[]|nil The array of component to blacklist
---@param blacklist_components table|druid.base_component[] The array of component to blacklist
---@return druid_instance
function M:set_blacklist(blacklist_components)
if blacklist_components and blacklist_components._component then