This commit is contained in:
Insality
2025-03-20 09:46:13 +02:00
parent 10556ba31a
commit 330dabda09
8 changed files with 45 additions and 41 deletions

View File

@@ -77,7 +77,7 @@ end
function M:on_style_change(style)
self.style = {
TRIM_POSTFIX = style.TRIM_POSTFIX or "...",
DEFAULT_ADJUST = style.DEFAULT_ADJUST or const.TEXT_ADJUST.DOWNSCALE,
DEFAULT_ADJUST = style.DEFAULT_ADJUST or "downscale",
ADJUST_STEPS = style.ADJUST_STEPS or 20,
ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02
}
@@ -256,9 +256,7 @@ end
---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 adjust_type druid.text.adjust_type|nil The adjust type to set, values: "downscale", "trim", "no_adjust", "downscale_limited", "scroll", "scale_then_scroll", "trim_left", "scale_then_trim", "scale_then_trim_left"
---@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)
@@ -270,7 +268,7 @@ function M:set_text_adjust(adjust_type, minimal_scale)
end
---Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
---Set minimal scale for "downscale_limited" or "scale_then_scroll" adjust types
---@param minimal_scale number If pass nil - not use minimal scale
---@return druid.text self Current text instance
function M:set_minimal_scale(minimal_scale)
@@ -466,42 +464,42 @@ end
---@private
function M:_update_adjust()
if not self.adjust_type or self.adjust_type == const.TEXT_ADJUST.NO_ADJUST then
if not self.adjust_type or self.adjust_type == "no_adjust" then
self:_reset_default_scale()
return
end
if self.adjust_type == const.TEXT_ADJUST.DOWNSCALE then
if self.adjust_type == "downscale" then
self:_update_text_area_size()
end
if self.adjust_type == const.TEXT_ADJUST.TRIM then
if self.adjust_type == "trim" then
self:_update_text_with_trim(self.style.TRIM_POSTFIX)
end
if self.adjust_type == const.TEXT_ADJUST.TRIM_LEFT then
if self.adjust_type == "trim_left" then
self:_update_text_with_trim_left(self.style.TRIM_POSTFIX)
end
if self.adjust_type == const.TEXT_ADJUST.DOWNSCALE_LIMITED then
if self.adjust_type == "downscale_limited" then
self:_update_text_area_size()
end
if self.adjust_type == const.TEXT_ADJUST.SCROLL then
if self.adjust_type == "scroll" then
self:_update_text_with_anchor_shift()
end
if self.adjust_type == const.TEXT_ADJUST.SCALE_THEN_SCROLL then
if self.adjust_type == "scale_then_scroll" then
self:_update_text_area_size()
self:_update_text_with_anchor_shift()
end
if self.adjust_type == const.TEXT_ADJUST.SCALE_THEN_TRIM then
if self.adjust_type == "scale_then_trim" then
self:_update_text_area_size()
self:_update_text_with_trim(self.style.TRIM_POSTFIX)
end
if self.adjust_type == const.TEXT_ADJUST.SCALE_THEN_TRIM_LEFT then
if self.adjust_type == "scale_then_trim_left" then
self:_update_text_area_size()
self:_update_text_with_trim_left(self.style.TRIM_POSTFIX)
end

View File

@@ -79,8 +79,7 @@ M.LAYOUT_MODE = {
STRETCH = gui.ADJUST_STRETCH,
}
M.SYS_INFO = sys.get_sys_info()
M.CURRENT_SYSTEM_NAME = M.SYS_INFO.system_name
M.CURRENT_SYSTEM_NAME = sys.get_sys_info().system_name
M.OS = {
ANDROID = "Android",

View File

@@ -14,11 +14,6 @@ local POSITION_X = hash("position.x")
local SCALE_X = hash("scale.x")
local SIZE_X = hash("size.x")
M.PROP_SIZE_X = hash("size.x")
M.PROP_SIZE_Y = hash("size.y")
M.PROP_SCALE_X = hash("scale.x")
M.PROP_SCALE_Y = hash("scale.y")
local function get_text_width(text_node)
if text_node then
local text_metrics = M.get_text_metrics_from_node(text_node)

View File

@@ -130,7 +130,7 @@ M["input"] = {
M["text"] = {
TRIM_POSTFIX = "...",
DEFAULT_ADJUST = const.TEXT_ADJUST.DOWNSCALE
DEFAULT_ADJUST = "downscale"
}

View File

@@ -491,12 +491,15 @@ end
---@generic T: druid.component
---@param widget T The widget class to create
---@param template string|nil The template name used by widget
---@param nodes table<hash, node>|node|nil The nodes table from gui.clone_tree or prefab node to use for clone
---@param nodes table<hash, node>|node|string|nil The nodes table from gui.clone_tree or prefab node to use for clone or node id to clone
---@vararg any Additional arguments to pass to the widget's init function
---@return T widget The new ready to use widget
function M:new_widget(widget, template, nodes, ...)
local instance = create_widget(self, widget)
if type(nodes) == "string" then
nodes = gui.get_node(nodes)
end
if type(nodes) == "userdata" then
nodes = gui.clone_tree(nodes) --[[@as table<hash, node>]]
end
@@ -612,7 +615,7 @@ local lang_text = require("druid.extended.lang_text")
---Create LangText component
---@param node string|node The_node id or gui.get_node(node_id)
---@param locale_id string|nil Default locale id or text from node as default
---@param adjust_type string|nil Adjust type for text node. Default: const.TEXT_ADJUST.DOWNSCALE
---@param adjust_type string|nil Adjust type for text node. Default: "downscale"
---@return druid.lang_text lang_text The new lang text component
function M:new_lang_text(node, locale_id, adjust_type)
return self:new(lang_text, node, locale_id, adjust_type)

View File

@@ -8,6 +8,11 @@ local event_queue = require("druid.event_queue")
---@field time number
local M = {}
M.PROP_SIZE_X = hash("size.x")
M.PROP_SIZE_Y = hash("size.y")
M.PROP_SCALE_X = hash("scale.x")
M.PROP_SCALE_Y = hash("scale.y")
function M:init(node)
self.node = self:get_node(node)
self.animation = nil
@@ -42,10 +47,10 @@ function M:get_repeat()
if not self.is_inited then
return 1, 1
end
local size_x = gui.get(self.node, helper.PROP_SIZE_X)
local size_y = gui.get(self.node, helper.PROP_SIZE_Y)
local scale_x = gui.get(self.node, helper.PROP_SCALE_X)
local scale_y = gui.get(self.node, helper.PROP_SCALE_Y)
local size_x = gui.get(self.node, M.PROP_SIZE_X)
local size_y = gui.get(self.node, M.PROP_SIZE_Y)
local scale_x = gui.get(self.node, M.PROP_SCALE_X)
local scale_y = gui.get(self.node, M.PROP_SCALE_Y)
local repeat_x = (size_x / self.animation.width) / scale_x
local repeat_y = (size_y / self.animation.height) / scale_y