function ItemTips.CreateEquipPanel(data, itemData, isWear, panelInsertIndex)
if not data or not itemData then
return
end
if SL:GetMetaValue("WINPLAYMODE") then
isWear = false
end
ResetDescParam()
ItemTips.itemCount = 0
if not ItemTips._PList then
I
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-07 15:07:59 |
👁️ 阅读: 0
根据你的代码,要实现顶部描述根据容器宽度居中显示,需要调整 `topDescs[1].x` 的赋值逻辑。目前你直接设置为 `100`,这是固定值,无法实现自适应居中。
关键修改点如下:
1. 在计算完 `maxWidth` 之后(即所有可能影响最大宽度的元素都计算完毕后),再计算居中位置。
2. 通过 `GUI:getContentSize` 获取 `topDescs[1]` 这个富文本控件的实际宽度。
3. 使用容器背景 `ListBg` 的宽度作为基准来计算居中坐标。
修改后的代码应插入在函数末尾,设置 `r_name` 居中位置的附近:
```lua
-- ... 前面所有代码,包括计算maxWidth ...
-- 设置名称居中
local nameTextWidth = GUI:getContentSize(r_name).width
local bgWidth = maxWidth + 30
local centerX = (bgWidth - nameTextWidth) / 2
GUI:setPositionX(r_name, centerX)
-- 设置顶部描述(topDescs[1])居中
if topDescs and topDescs[1] then
-- 1. 获取顶部描述控件的宽度
local topDescWidget = topDescs[1] -- 假设topDescs[1]已经是控件对象
local topDescWidth = GUI:getContentSize(topDescWidget).width
-- 2. 计算居中坐标
local topDescCenterX = (bgWidth - topDescWidth) / 2
-- 3. 设置位置
GUI:setPositionX(topDescWidget, topDescCenterX)
end
```
**说明:**
- `bgWidth` 是背景面板 `ListBg` 的宽度,即 `maxWidth + 30`,这是整个提示框的可视宽度基准。
- `topDescs[1]` 需要是一个已创建的控件对象(例如 `GUI:RichText_Create` 返回的对象),代码中 `pushDescItem(topDescs, 1)` 应该已经创建了它。
- 这段代码应放在 `GUI:setPositionX(r_name, centerX)` 之后,确保 `maxWidth` 和 `bgWidth` 已是最终值。
如果 `topDescs[1]` 不是直接的控件对象,而是包含控件引用的表,你需要根据 `pushDescItem` 的内部实现来获取实际的控件。一个常见的做法是 `pushDescItem` 会将创建的控件返回或存储在 `topDescs[1]` 中,请检查你的 `pushDescItem` 函数逻辑。
根据你的代码,要实现顶部描述根据容器宽度居中显示,需要调整 `topDescs[1].x` 的赋值逻辑。目前你直接设置为 `100`,这是固定值,无法实现自适应居中。
关键修改点如下:
1. 在计算完 `maxWidth` 之后(即所有可能影响最大宽度的元素都计算完毕后),再计算居中位置。
2. 通过 `GUI:getContentSize` 获取 `topDescs[1]` 这个富文本控件的实际宽度。
3. 使用容器背景 `ListBg` 的宽度作为基准来计算居中坐标。
修改后的代码应插入在函数末尾,设置 `r_name` 居中位置的附近:
```lua
-- ... 前面所有代码,包括计算maxWidth ...
-- 设置名称居中
local nameTextWidth = GUI:getContentSize(r_name).width
local bgWidth = maxWidth + 30
local centerX = (bgWidth - nameTextWidth) / 2
GUI:setPositionX(r_name, centerX)
-- 设置顶部描述(topDescs[1])居中
if topDescs and topDescs[1] then
-- 1. 获取顶部描述控件的宽度
local topDescWidget = topDescs[1] -- 假设topDescs[1]已经是控件对象
local topDescWidth = GUI:getContentSize(topDescWidget).width
-- 2. 计算居中坐标
local topDescCenterX = (bgWidth - topDescWidth) / 2
-- 3. 设置位置
GUI:setPositionX(topDescWidget, topDescCenterX)
end
```
**说明:**
- `bgWidth` 是背景面板 `ListBg` 的宽度,即 `maxWidth + 30`,这是整个提示框的可视宽度基准。
- `topDescs[1]` 需要是一个已创建的控件对象(例如 `GUI:RichText_Create` 返回的对象),代码中 `pushDescItem(topDescs, 1)` 应该已经创建了它。
- 这段代码应放在 `GUI:setPositionX(r_name, centerX)` 之后,确保 `maxWidth` 和 `bgWidth` 已是最终值。
如果 `topDescs[1]` 不是直接的控件对象,而是包含控件引用的表,你需要根据 `pushDescItem` 的内部实现来获取实际的控件。一个常见的做法是 `pushDescItem` 会将创建的控件返回或存储在 `topDescs[1]` 中,请检查你的 `pushDescItem` 函数逻辑。
← 返回问答库