mirror of
https://github.com/Insality/druid
synced 2025-09-27 10:02:19 +02:00
Update examples
This commit is contained in:
@@ -188,23 +188,9 @@ end
|
||||
-- @tparam[opt=SHIFT.RIGHT] number shift_policy How shift nodes, if required. See const.SHIFT
|
||||
-- @tparam[opt=false] boolean is_instant If true, update node positions instantly
|
||||
function StaticGrid.add(self, item, index, shift_policy, is_instant)
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
index = index or ((self.last_index or 0) + 1)
|
||||
|
||||
if self.nodes[index] then
|
||||
if shift_policy == const.SHIFT.RIGHT then
|
||||
for i = self.last_index, index, -1 do
|
||||
self.nodes[i + 1] = self.nodes[i]
|
||||
end
|
||||
end
|
||||
if shift_policy == const.SHIFT.LEFT then
|
||||
for i = self.first_index, index do
|
||||
self.nodes[i - 1] = self.nodes[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.nodes[index] = item
|
||||
helper.insert_with_shift(self.nodes, item, index, shift_policy)
|
||||
gui.set_parent(item, self.parent)
|
||||
|
||||
-- Add new item instantly in new pos. Break update function for correct positioning
|
||||
@@ -227,22 +213,10 @@ end
|
||||
-- @tparam[opt=false] boolean is_instant If true, update node positions instantly
|
||||
-- @treturn Node The deleted gui node from grid
|
||||
function StaticGrid.remove(self, index, shift_policy, is_instant)
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
assert(self.nodes[index], "No grid item at given index " .. index)
|
||||
|
||||
local remove_node = self.nodes[index]
|
||||
self.nodes[index] = nil
|
||||
|
||||
if shift_policy == const.SHIFT.RIGHT then
|
||||
for i = index, self.last_index do
|
||||
self.nodes[i] = self.nodes[i + 1]
|
||||
end
|
||||
end
|
||||
if shift_policy == const.SHIFT.LEFT then
|
||||
for i = index, self.first_index, -1 do
|
||||
self.nodes[i] = self.nodes[i - 1]
|
||||
end
|
||||
end
|
||||
helper.remove_with_shift(self.nodes, index, shift_policy)
|
||||
|
||||
self:_update(is_instant)
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
-- Modified by: Insality
|
||||
|
||||
local helper = require("druid.helper")
|
||||
local parser = require("druid.custom.rich_text.rich_text.parse")
|
||||
local parser = require("druid.custom.rich_text.module.rt_parse")
|
||||
local utf8_lua = require("druid.system.utf8")
|
||||
local utf8 = utf8 or utf8_lua
|
||||
|
||||
@@ -462,6 +462,7 @@ function M._update_nodes(lines, settings)
|
||||
gui.set_shadow(node, word.shadow)
|
||||
gui.set_text(node, word.text)
|
||||
gui.set_color(node, word.color or word.text_color)
|
||||
gui.set_font(node, word.font or settings.font)
|
||||
end
|
||||
word.node = node
|
||||
gui.set_enabled(node, true)
|
@@ -2,7 +2,7 @@
|
||||
-- Author: Britzl
|
||||
-- Modified by: Insality
|
||||
|
||||
local tags = require("druid.custom.rich_text.rich_text.tags")
|
||||
local tags = require("druid.custom.rich_text.module.rt_tags")
|
||||
local utf8_lua = require("druid.system.utf8")
|
||||
local utf8 = utf8 or utf8_lua
|
||||
|
@@ -2,7 +2,7 @@
|
||||
-- Author: Britzl
|
||||
-- Modified by: Insality
|
||||
|
||||
local color = require("druid.custom.rich_text.rich_text.color")
|
||||
local color = require("druid.custom.rich_text.module.rt_color")
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -41,6 +41,9 @@ local function split(s, token)
|
||||
end
|
||||
|
||||
|
||||
-- Format: <color=[#]{HEX_VALUE}>{Text}</color>
|
||||
-- Format: <color={COLOR_NAME}>{Text}</color>
|
||||
-- Example: <color=FF0000>Rich Text</color>
|
||||
M.register("color", function(params, settings)
|
||||
settings.color = color.parse(params)
|
||||
end)
|
||||
@@ -71,16 +74,22 @@ M.register("a", function(params, settings)
|
||||
end)
|
||||
|
||||
|
||||
-- Example: </br>
|
||||
M.register("br", function(params, settings)
|
||||
settings.br = true
|
||||
end)
|
||||
|
||||
|
||||
-- Example: <nobr></nobr>
|
||||
M.register("nobr", function(params, settings)
|
||||
settings.nobr = true
|
||||
end)
|
||||
|
||||
|
||||
-- Format: <img={animation_id},[width],[height]/>
|
||||
-- Example: <img=logo/>
|
||||
-- Example: <img=logo,48/>
|
||||
-- Example: <img=logo,48,48/>
|
||||
M.register("img", function(params, settings)
|
||||
local texture_and_anim, params = split(params, ",")
|
||||
local width, height
|
@@ -1,5 +1,5 @@
|
||||
local component = require("druid.component")
|
||||
local rich_text = require("druid.custom.rich_text.rich_text.richtext")
|
||||
local rich_text = require("druid.custom.rich_text.module.rt")
|
||||
|
||||
---@class druid.rich_text
|
||||
local RichText = component.create("rich_text")
|
||||
@@ -28,6 +28,7 @@ function RichText:init(template, nodes)
|
||||
end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return rich_text.word[], rich_text.lines_metrics
|
||||
function RichText:set_text(text)
|
||||
self:clean()
|
||||
@@ -64,6 +65,7 @@ end
|
||||
|
||||
function RichText:_get_settings()
|
||||
return {
|
||||
-- General settings
|
||||
adjust_scale = 1,
|
||||
parent = self.root,
|
||||
width = self.root_size.x,
|
||||
@@ -71,6 +73,7 @@ function RichText:_get_settings()
|
||||
text_prefab = self.text_prefab,
|
||||
node_prefab = self.icon_prefab,
|
||||
|
||||
-- Text Settings
|
||||
size = gui.get_scale(self.text_prefab).x,
|
||||
shadow = gui.get_shadow(self.text_prefab),
|
||||
outline = gui.get_outline(self.text_prefab),
|
||||
@@ -78,6 +81,7 @@ function RichText:_get_settings()
|
||||
text_leading = gui.get_leading(self.text_prefab),
|
||||
is_multiline = gui.get_line_break(self.text_prefab),
|
||||
|
||||
-- Image settings
|
||||
combine_words = false,
|
||||
image_pixel_grid_snap = false,
|
||||
node_scale = gui.get_scale(self.icon_prefab),
|
||||
@@ -88,12 +92,10 @@ end
|
||||
|
||||
|
||||
function RichText:clean()
|
||||
if not self._words then
|
||||
return
|
||||
if self._words then
|
||||
rich_text.remove(self._words)
|
||||
self._words = nil
|
||||
end
|
||||
|
||||
rich_text.remove(self._words)
|
||||
self._words = nil
|
||||
end
|
||||
|
||||
|
||||
|
@@ -115,19 +115,7 @@ function DataList.add(self, data, index, shift_policy)
|
||||
index = index or self._data_last_index + 1
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
|
||||
if self._data[index] then
|
||||
if shift_policy == const.SHIFT.RIGHT then
|
||||
for i = self._data_last_index, index, -1 do
|
||||
self._data[i + 1] = self._data[i]
|
||||
end
|
||||
end
|
||||
if shift_policy == const.SHIFT.LEFT then
|
||||
for i = self._data_first_index, index do
|
||||
self._data[i - 1] = self._data[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
self._data[index] = data
|
||||
helper.insert_with_shift(self._data, data, index, shift_policy)
|
||||
self:_update_data_info()
|
||||
self:_check_elements()
|
||||
|
||||
@@ -141,8 +129,10 @@ end
|
||||
-- @tparam number shift_policy The constant from const.SHIFT.*
|
||||
-- @local
|
||||
function DataList.remove(self, index, shift_policy)
|
||||
table.remove(self._data, index)
|
||||
self:_refresh()
|
||||
--self:_refresh()
|
||||
|
||||
helper.remove_with_shift(self._data, index, shift_policy)
|
||||
self:_update_data_info()
|
||||
|
||||
self:log_message("Remove element", { index = index })
|
||||
end
|
||||
@@ -156,7 +146,8 @@ end
|
||||
function DataList.remove_by_data(self, data, shift_policy)
|
||||
local index = helper.contains(self._data, data)
|
||||
if index then
|
||||
table.remove(self._data, index)
|
||||
helper.remove_with_shift(self._data, index, shift_policy)
|
||||
self:_update_data_info()
|
||||
self:_refresh()
|
||||
end
|
||||
end
|
||||
@@ -166,6 +157,7 @@ end
|
||||
-- @tparam DataList self @{DataList}
|
||||
function DataList.clear(self)
|
||||
self._data = {}
|
||||
self:_update_data_info()
|
||||
self:_refresh()
|
||||
end
|
||||
|
||||
@@ -289,7 +281,7 @@ function DataList._remove_at(self, index)
|
||||
end
|
||||
|
||||
|
||||
--- Fully refresh all DataList elements
|
||||
--- Refresh all elements in DataList
|
||||
-- @tparam DataList self @{DataList}
|
||||
-- @local
|
||||
function DataList._refresh(self)
|
||||
@@ -389,8 +381,8 @@ function DataList._update_data_info(self)
|
||||
end
|
||||
|
||||
if self._data_length == 0 then
|
||||
self._data_first_index = 1
|
||||
self._data_last_index = 1
|
||||
self._data_first_index = 0
|
||||
self._data_last_index = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -354,6 +354,53 @@ function M.get_text_metrics_from_node(text_node)
|
||||
end
|
||||
|
||||
|
||||
function M.insert_with_shift(array, item, index, shift_policy)
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
|
||||
local len = #array
|
||||
index = index or len + 1
|
||||
|
||||
if array[index] and shift_policy ~= const.SHIFT.NO_SHIFT then
|
||||
local check_index = index
|
||||
local next_element = array[check_index]
|
||||
while next_element or (check_index >= 1 and check_index <= len) do
|
||||
check_index = check_index + shift_policy
|
||||
local check_element = array[check_index]
|
||||
array[check_index] = next_element
|
||||
next_element = check_element
|
||||
end
|
||||
end
|
||||
|
||||
array[index] = item
|
||||
|
||||
return item
|
||||
end
|
||||
|
||||
|
||||
function M.remove_with_shift(array, index, shift_policy)
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
|
||||
local len = #array
|
||||
index = index or len
|
||||
|
||||
local item = array[index]
|
||||
array[index] = nil
|
||||
|
||||
if shift_policy ~= const.SHIFT.NO_SHIFT then
|
||||
local check_index = index + shift_policy
|
||||
local next_element = array[check_index]
|
||||
while next_element or (check_index >= 0 and check_index <= len + 1) do
|
||||
array[check_index - shift_policy] = next_element
|
||||
array[check_index] = nil
|
||||
check_index = check_index + shift_policy
|
||||
next_element = array[check_index]
|
||||
end
|
||||
end
|
||||
|
||||
return item
|
||||
end
|
||||
|
||||
|
||||
--- Show deprecated message. Once time per message
|
||||
-- @function helper.deprecated
|
||||
-- @tparam string message The deprecated message
|
||||
|
Reference in New Issue
Block a user