Update Druid components

This commit is contained in:
Insality 2024-10-19 10:58:24 +03:00
parent ad339508cf
commit d73835a2d5
7 changed files with 81 additions and 53 deletions

View File

@ -838,6 +838,7 @@ function Scroll._process_scroll_wheel(self, action_id, action)
end
self:_set_scroll_position(self.target_position.x, self.target_position.y)
self:_check_points()
end
return true

View File

@ -215,6 +215,44 @@ function StaticGrid.set_anchor(self, anchor)
end
--- Update grid content
-- @tparam StaticGrid self @{StaticGrid}
function StaticGrid.refresh(self)
self:_update(true)
end
function StaticGrid.set_pivot(self, pivot)
local prev_pivot = helper.get_pivot_offset(gui.get_pivot(self.parent))
self.pivot = helper.get_pivot_offset(pivot)
local width = gui.get(self.parent, "size.x")
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)
position.x = position.x + width * (self.pivot.x - prev_pivot.x)
position.y = position.y + height * (self.pivot.y - prev_pivot.y)
gui.set_position(self.parent, position)
gui.set_pivot(self.parent, pivot)
self.anchor = vmath.vector3(0.5 + self.pivot.x, 0.5 - self.pivot.y, 0)
self._grid_horizonal_offset = self.node_size.x * (self.in_row - 1) * self.anchor.x
self._zero_offset = vmath.vector3(
self.node_size.x * self.node_pivot.x - self.node_size.x * self.pivot.x - self._grid_horizonal_offset,
self.node_size.y * self.node_pivot.y - self.node_size.y * self.pivot.y,
0
)
self:_update(true)
end
--- Add new item to the grid
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam node item GUI node
@ -411,6 +449,12 @@ function StaticGrid.set_item_size(self, width, height)
if height then
self.node_size.y = height
end
self._grid_horizonal_offset = self.node_size.x * (self.in_row - 1) * self.anchor.x
self._zero_offset = vmath.vector3(
self.node_size.x * self.node_pivot.x - self.node_size.x * self.pivot.x - self._grid_horizonal_offset,
self.node_size.y * self.node_pivot.y - self.node_size.y * self.pivot.y,
0)
self:_update()
self.on_change_items:trigger(self:get_context())

View File

@ -95,7 +95,6 @@ function RichText.init(self, text_node, value)
if value then
self:set_text(value)
end
end
@ -193,6 +192,8 @@ end
function RichText:on_remove()
gui.set_scale(self.root, self._default_scale)
gui.set_size(self.root, self._default_size)
self:clear()
end
@ -247,6 +248,9 @@ function RichText:_create_settings()
local root_size = gui.get_size(self.root)
local scale = gui.get_scale(self.root)
self._default_size = root_size
self._default_scale = scale
root_size.x = root_size.x * scale.x
root_size.y = root_size.y * scale.y
gui.set_size(self.root, root_size)

View File

@ -56,13 +56,18 @@ local M = {}
local _instances = {}
local function get_druid_instances()
local function clean_deleted_druid_instances()
for i = #_instances, 1, -1 do
if _instances[i]._deleted then
table.remove(_instances, i)
end
end
end
local function get_druid_instances()
clean_deleted_druid_instances()
return _instances
end
@ -103,6 +108,8 @@ end
-- self.druid = druid.new(self)
-- end
function M.new(context, style)
clean_deleted_druid_instances()
if settings.default_style == nil then
M.set_default_style(default_style)
end

View File

@ -406,6 +406,7 @@ function M.calculate_rows_data(self)
return rows_data
end
-- @tparam node node
-- @tparam number x
-- @tparam number y
@ -420,4 +421,5 @@ function M:set_node_position(node, x, y)
return node
end
return M

View File

@ -84,14 +84,10 @@ local back_handler = require("druid.base.back_handler")
-- local input = require("druid.extended.input")
-- local swipe = require("druid.extended.swipe")
-- local slider = require("druid.extended.slider")
-- local checkbox = require("druid.extended.checkbox")
-- local progress = require("druid.extended.progress")
-- local data_list = require("druid.extended.data_list")
-- local lang_text = require("druid.extended.lang_text")
-- local timer_component = require("druid.extended.timer")
-- local radio_group = require("druid.extended.radio_group")
-- local dynamic_grid = require("druid.extended.dynamic_grid")
-- local checkbox_group = require("druid.extended.checkbox_group")
local DruidInstance = {}
@ -608,7 +604,6 @@ end
--- Create @{StaticGrid} component
-- Deprecated
-- @tparam DruidInstance self
-- @tparam string|node parent_node The node_id or gui.get_node(node_id). Parent of all Grid items.
-- @tparam node item Element prefab. Required to get grid's item size. Can be adjusted separately.
@ -616,7 +611,6 @@ end
-- @treturn StaticGrid @{StaticGrid} component
-- @local
function DruidInstance.new_grid(self, parent_node, item, in_row)
helper.deprecated("The druid:new_grid is deprecated. Please use druid:new_static_grid instead")
return DruidInstance.new(self, static_grid, parent_node, item, in_row)
end
@ -663,6 +657,7 @@ end
--- Create @{DynamicGrid} component
-- Deprecated
-- @tparam DruidInstance self
-- @tparam string|node parent_node The node_id or gui.get_node(node_id). Parent of all Grid items.
-- @treturn DynamicGrid @{DynamicGrid} component
@ -693,18 +688,6 @@ function DruidInstance.new_slider(self, pin_node, end_pos, callback)
end
--- Create @{Checkbox} component
-- @tparam DruidInstance self
-- @tparam string|node node The_node id or gui.get_node(node_id).
-- @tparam function|nil callback Checkbox callback
-- @tparam node|nil click_node Trigger node, Default: node
-- @tparam boolean|nil initial_state The initial state of checkbox, Default: false
-- @treturn Checkbox @{Checkbox} component
function DruidInstance.new_checkbox(self, node, callback, click_node, initial_state)
return helper.require_component_message("checkbox")
end
--- Create @{Input} component
-- @tparam DruidInstance self
-- @tparam string|node click_node Button node to enabled input component
@ -716,17 +699,6 @@ function DruidInstance.new_input(self, click_node, text_node, keyboard_type)
end
--- Create @{CheckboxGroup} component
-- @tparam DruidInstance self
-- @tparam (node|string)[] nodes Array of gui node
-- @tparam function callback Checkbox callback
-- @tparam (node|string)[]|nil click_nodes Array of trigger nodes, by default equals to nodes
-- @treturn CheckboxGroup @{CheckboxGroup} component
function DruidInstance.new_checkbox_group(self, nodes, callback, click_nodes)
return helper.require_component_message("checkbox_group")
end
--- Create @{DataList} component
-- @tparam DruidInstance self
-- @tparam Scroll druid_scroll The Scroll instance for Data List component
@ -738,17 +710,6 @@ function DruidInstance.new_data_list(self, druid_scroll, druid_grid, create_func
end
--- Create @{RadioGroup} component
-- @tparam DruidInstance self
-- @tparam (node|string)[] nodes Array of gui node
-- @tparam function callback Radio callback
-- @tparam (node|string)[]|nil click_nodes Array of trigger nodes, by default equals to nodes
-- @treturn RadioGroup @{RadioGroup} component
function DruidInstance.new_radio_group(self, nodes, callback, click_nodes)
return helper.require_component_message("radio_group")
end
--- Create @{Timer} component
-- @tparam DruidInstance self
-- @tparam string|node node Gui text node
@ -794,14 +755,24 @@ end
--- Create @{RichText} component.
-- As a template please check rich_text.gui layout.
-- @tparam DruidInstance self
-- @tparam string|nil template Template name if used
-- @tparam table|nil nodes Nodes table from gui.clone_tree
-- @tparam string|node text_node The text node to make Rich Text
-- @tparam string|nil value The initial text value. Default will be gui.get_text(text_node)
-- @treturn RichText @{RichText} component
function DruidInstance.new_rich_text(self, template, nodes)
function DruidInstance.new_rich_text(self, text_node, value)
return helper.require_component_message("rich_text", "custom")
end
--- Create @{RichInput} component.
-- As a template please check rich_input.gui layout.
-- @tparam DruidInstance self
-- @tparam string template The template string name
-- @tparam table nodes Nodes table from gui.clone_tree
-- @treturn RichInput @{RichInput} component
function DruidInstance.new_rich_input(self, template, nodes)
return helper.require_component_message("rich_input", "custom")
end
return DruidInstance

View File

@ -13,16 +13,15 @@ high_dpi = 1
[project]
title = druid
version = 1.0.0
version = 1.0
publisher = Insality
developer = Maksim Tuprikov
custom_resources = /example/locales
dependencies#0 = https://github.com/insalitygames/deftest/archive/master.zip
dependencies#1 = https://github.com/britzl/monarch/archive/refs/tags/3.3.0.zip
dependencies#2 = https://github.com/Insality/defold-saver/archive/refs/tags/1.zip
dependencies#3 = https://github.com/Insality/defold-tweener/archive/refs/tags/3.zip
dependencies#4 = https://github.com/Insality/panthera/archive/refs/heads/develop.zip
dependencies#5 = https://github.com/Insality/defold-lang/archive/refs/tags/3.zip
dependencies#0 = https://github.com/britzl/deftest/archive/refs/tags/2.8.0.zip
dependencies#1 = https://github.com/Insality/defold-saver/archive/refs/tags/1.zip
dependencies#2 = https://github.com/Insality/defold-tweener/archive/refs/tags/3.zip
dependencies#3 = https://github.com/Insality/panthera/archive/refs/tags/runtime.4.zip
dependencies#4 = https://github.com/Insality/defold-lang/archive/refs/tags/3.zip
[library]
include_dirs = druid