Remove html api, update docs

This commit is contained in:
Insality
2025-03-20 00:26:29 +02:00
parent f786b20951
commit 10556ba31a
69 changed files with 294 additions and 17870 deletions

View File

@@ -2,13 +2,21 @@ local event = require("event.event")
local const = require("druid.const")
local component = require("druid.component")
---The component that handles the back handler action, like backspace or android back button
---Component to handle back button. It handles Android back button and Backspace key.
---
---### Setup
---Create back handler component with druid: `druid:new_back_handler(callback)`
---
---### Notes
---- Key triggers in `input.binding` should be setup for correct working
---- It uses a key_back and key_backspace action ids
---@class druid.back_handler: druid.component
---@field on_back event Trigger on back handler action, fun(self, params)
---@field params any|nil Custom args to pass in the callback
local M = component.create("back_handler")
---The Back Handler constructor
---@param callback function|nil The callback to call when the back handler is triggered
---@param params any? Custom args to pass in the callback
function M:init(callback, params)

View File

@@ -1,12 +1,22 @@
local const = require("druid.const")
local component = require("druid.component")
---Druid component for block input. Use it to block input in special zone.
---
---### Setup
---Create blocker component with druid: `druid:new_blocker(node_name)`
---
---### Notes
---- Blocker can be used to create safe zones, where you have big buttons
---- Blocker will capture all input events that hit the node, preventing them from reaching other components
---- Blocker works placed as usual component in stack, so any other component can be placed on top of it and will work as usual
---@class druid.blocker: druid.component
---@field node node
---@field private _is_enabled boolean
---@field node node The node that will block input
---@field private _is_enabled boolean Whether blocker is enabled
local M = component.create("blocker")
---The Blocker constructor
---@param node node|string The node to use as a blocker
function M:init(node)
self.node = self:get_node(node)

View File

@@ -15,14 +15,29 @@ local component = require("druid.component")
---@field on_mouse_hover fun(self, node, hover_state)|nil
---@field on_set_enabled fun(self, node, enabled_state)|nil
---Druid component to make clickable node with various interaction callbacks
---Basic Druid input component. Handle input on node and provide different callbacks on touch events.
---
---### Setup
---Create button with druid: `button = druid:new_button(node_name, callback, [params], [animation_node])`
---Where node_name is name of node from GUI scene. You can use `node_name` as input trigger zone and point another node for animation via `animation_node`
---
---### Notes
---- Button callback have next params: (self, params, button_instance)
---- - **self** - Druid self context
---- - **params** - Additional params, specified on button creating
---- - **button_instance** - button itself
---- You can set _params_ on button callback on button creating: `druid:new_button("node_name", callback, params)`.
---- Button have several events like on_click, on_repeated_click, on_long_click, on_hold_click, on_double_click
---- Click event will not trigger if between pressed and released state cursor was outside of node zone
---- Button can have key trigger to use them by key: `button:set_key_trigger`
----
---@class druid.button: druid.component
---@field on_click event function(self, custom_args, button_instance)
---@field on_pressed event function(self, custom_args, button_instance)
---@field on_repeated_click event function(self, custom_args, button_instance, click_count)
---@field on_long_click event function(self, custom_args, button_instance, hold_time)
---@field on_double_click event function(self, custom_args, button_instance, click_amount)
---@field on_hold_callback event function(self, custom_args, button_instance, press_time)
---@field on_repeated_click event function(self, custom_args, button_instance, click_count) Repeated click callback, while holding the button
---@field on_long_click event function(self, custom_args, button_instance, hold_time) Callback on long button tap
---@field on_double_click event function(self, custom_args, button_instance, click_amount) Different callback, if tap button 2+ in row
---@field on_hold_callback event function(self, custom_args, button_instance, press_time) Hold callback, before long_click trigger
---@field on_click_outside event function(self, custom_args, button_instance)
---@field node node Clickable node
---@field node_id hash Node id
@@ -41,8 +56,8 @@ local M = component.create("button")
---The constructor for the button component
---@param node_or_node_id node|string Node name or GUI Node itself
---@param callback fun()|nil Callback on button click
---@param custom_args any|nil Custom args for any Button event
---@param anim_node node|string|nil Node to animate instead of trigger node
---@param custom_args any|nil Custom args for any Button event, will be passed to callbacks
---@param anim_node node|string|nil Node to animate instead of trigger node, useful for animating small icons on big panels
function M:init(node_or_node_id, callback, custom_args, anim_node)
self.druid = self:get_druid()
self.node = self:get_node(node_or_node_id)

View File

@@ -18,12 +18,29 @@ local component = require("druid.component")
---@field WHEEL_SCROLL_INVERTED boolean|nil If true, invert direction for touchpad and mouse wheel scroll. Default: false
---@field WHEEL_SCROLL_BY_INERTION boolean|nil If true, wheel will add inertion to scroll. Direct set position otherwise.. Default: false
---Basic Druid scroll component. Handles all scrolling behavior in Druid GUI.
---
---### Setup
---Create scroll component with druid: `druid:new_scroll(view_node, content_node)`
---
---### Notes
---- View_node is the static part that captures user input and recognizes scrolling touches
---- Content_node is the dynamic part that will change position according to the scroll system
---- Initial scroll size will be equal to content_node size
---- The initial view box will be equal to view_node size
---- Scroll by default style has inertia and extra size for stretching effect
---- You can setup "points of interest" to make scroll always center on closest point
---- Scroll events:
---- - on_scroll(self, position): On scroll move callback
---- - on_scroll_to(self, position, is_instant): On scroll_to function callback
---- - on_point_scroll(self, item_index, position): On scroll_to_index function callback
---- Multitouch is required for scroll. Scroll correctly handles touch_id swap while dragging
---@class druid.scroll: druid.component
---@field node node The root node
---@field click_zone node|nil Optional click zone to restrict scroll area
---@field on_scroll event Triggered on scroll move with (self, position)
---@field on_scroll_to event Triggered on scroll_to with (self, target, is_instant)
---@field on_point_scroll event Triggered on scroll_to_index with (self, index, point)
---@field on_scroll event Triggered on scroll move with fun(self, position)
---@field on_scroll_to event Triggered on scroll_to with fun(self, target, is_instant)
---@field on_point_scroll event Triggered on scroll_to_index with fun(self, index, point)
---@field view_node node The scroll view node (static part)
---@field view_border vector4 The scroll view borders
---@field content_node node The scroll content node (moving part)
@@ -47,8 +64,9 @@ local M = component.create("scroll")
---The Scroll constructor
---@param view_node string|node GUI view scroll node
---@param content_node string|node GUI content scroll node
---@param view_node string|node GUI view scroll node - the static part that captures user input
---@param content_node string|node GUI content scroll node - the dynamic part that will change position
---@return druid.scroll
function M:init(view_node, content_node)
self.druid = self:get_druid()

View File

@@ -11,12 +11,31 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]]
---@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
---The component to handle text behaviour over a GUI Text node, mainly used to automatically adjust text size to fit the text area
---@alias druid.text.adjust_type "downscale"|"trim"|"no_adjust"|"downscale_limited"|"scroll"|"scale_then_scroll"|"trim_left"|"scale_then_trim"|"scale_then_trim_left"
---Basic Druid text component. Text components by default have the text size adjusting.
---
---### Setup
---Create text node with druid: `text = druid:new_text(node_name, [initial_value], [text_adjust_type])`
---
---### Notes
---- Text component by default have auto adjust text sizing. Text never will be bigger, than text node size, which you can setup in GUI scene.
---- Text pivot can be changed with `text:set_pivot`, and text will save their position inside their text size box
---- There are several text adjust types:
---- - **"downscale"** - Change text's scale to fit in the text node size (default)
---- - **"trim"** - Trim the text with postfix (default - "...") to fit in the text node size
---- - **"no_adjust"** - No any adjust, like default Defold text node
---- - **"downscale_limited"** - Change text's scale like downscale, but there is limit for text's scale
---- - **"scroll"** - Change text's pivot to imitate scrolling in the text box. Use with stencil node for better effect.
---- - **"scale_then_scroll"** - Combine two modes: first limited downscale, then scroll
---- - **"trim_left"** - Trim the text with postfix (default - "...") to fit in the text node size
---- - **"scale_then_trim"** - Combine two modes: first limited downscale, then trim
---- - **"scale_then_trim_left"** - Combine two modes: first limited downscale, then trim left
---@class druid.text: druid.component
---@field node node The text node
---@field on_set_text event The event triggered when the text is set, fun(self, text)
---@field on_update_text_scale event The event triggered when the text scale is updated, fun(self, scale, metrics)
---@field on_set_pivot event The event triggered when the text pivot is set, fun(self, pivot)
---@field on_set_text event fun(self, text) The event triggered when the text is set
---@field on_update_text_scale event fun(self, scale, metrics) The event triggered when the text scale is updated
---@field on_set_pivot event fun(self, pivot) The event triggered when the text pivot is set
---@field style druid.text.style The style of the text
---@field private start_pivot userdata The start pivot of the text
---@field private start_scale vector3 The start scale of the text
@@ -27,7 +46,7 @@ local M = component.create("text")
---The Text constructor
---@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 adjust_type string|nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
---@param adjust_type druid.text.adjust_type|nil Adjust type for text. By default is "downscale". Options: "downscale", "trim", "no_adjust", "downscale_limited", "scroll", "scale_then_scroll", "trim_left", "scale_then_trim", "scale_then_trim_left"
function M:init(node, value, adjust_type)
self.node = self:get_node(node)
self.pos = gui.get_position(self.node)