Update Docs

This commit is contained in:
Insality
2025-04-16 01:01:00 +03:00
parent 9e2a14c6dd
commit d1d54896fb
13 changed files with 530 additions and 5 deletions

View File

@@ -37,9 +37,9 @@ local utf8 = utf8 or utf8_lua --[[@as utf8]]
---@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
---@field private scale vector3 The current scale of the text
---@field start_pivot userdata The start pivot of the text
---@field start_scale vector3 The start scale of the text
---@field scale vector3 The current scale of the text
local M = component.create("text")

View File

@@ -34,8 +34,21 @@ local function set_selection_width(self, selection_width)
end
---@param self druid.rich_input
local function update_text(self)
local left_text_part = utf8.sub(self.input:get_text(), 0, self.input.cursor_index)
local full_text = self.input:get_text()
local visible_text = self.input.text:get_text()
local is_truncated = visible_text ~= full_text
local cursor_index = self.input.cursor_index
if is_truncated then
-- If text is truncated, we need to adjust the cursor index
-- to the last visible character
cursor_index = utf8.len(visible_text)
end
local left_text_part = utf8.sub(self.input:get_text(), 0, cursor_index)
local selected_text_part = utf8.sub(self.input:get_text(), self.input.start_index + 1, self.input.end_index)
local left_part_width = self.input.text:get_text_size(left_text_part)
@@ -44,7 +57,7 @@ local function update_text(self)
local pivot_text = gui.get_pivot(self.input.text.node)
local pivot_offset = helper.get_pivot_offset(pivot_text)
self.cursor_position.x = self.text_position.x - self.input.total_width * (0.5 + pivot_offset.x) + left_part_width
self.cursor_position.x = self.text_position.x - self.input.text_width * (0.5 + pivot_offset.x) + left_part_width
gui.set_position(self.cursor, self.cursor_position)
gui.set_scale(self.cursor, self.input.text.scale)