Skip to content

Commit

Permalink
Refactor text setting methods and remove ldoc files
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Dec 8, 2024
1 parent 9a1cd79 commit 6b8bbe1
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 544 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"utils/annotations_manual.lua"
],
"Lua.runtime.pathStrict": true,
"Lua.diagnostics.libraryFiles": "Enable",
"Lua.diagnostics.libraryFiles": "Disable",
"Lua.runtime.version": "Lua 5.1",
"Lua.workspace.library": [
"~/Library/Application Support/Code/User/globalStorage/astronachos.defold",
Expand Down
18 changes: 0 additions & 18 deletions config.ld

This file was deleted.

22 changes: 14 additions & 8 deletions druid/base/button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions druid/base/drag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 8 additions & 3 deletions druid/base/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions druid/base/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions druid/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion druid/custom/rich_text/module/rt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions druid/custom/rich_text/rich_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions druid/extended/data_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion druid/extended/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions druid/extended/swipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

---

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions druid/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 3 additions & 8 deletions druid/materials/gui_repeat/gui_repeat.vp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
55 changes: 54 additions & 1 deletion druid/system/druid_annotations.lua
Original file line number Diff line number Diff line change
@@ -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).
Loading

0 comments on commit 6b8bbe1

Please sign in to comment.