Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

文本Text的宽度计算似乎有问题 sizeDelta在某些时候并不表示文本宽高 #54

@acmmonter

Description

@acmmonter

有个疑问,为什么用sizeDelta 来计算文本宽度,这个矢量计算在锚点(0.5,0.5,0.5,0.5)可以正确表示文本宽高,但是在其他情况下计算出来的是边距向量,这时候文本宽高就计算出错了,还可能出现负值。
稍作修改似乎就没问题了但是这么做是否有其他的一些地方没考虑到的 修改位置是下面Modify
public override float preferredWidth
{
get
{
var settings = GetGenerationSettings(Vector2.zero);
float width = cachedTextGeneratorForLayout.GetPreferredWidth(m_Text, settings) / pixelsPerUnit;
return width < rectTransform.rect.width || horizontalOverflow == HorizontalWrapMode.Overflow ? width : rectTransform.rect.width; //Modify
}
}
public override float preferredHeight
{
get
{
var settings = GetGenerationSettings(new Vector2(rectTransform.rect.size.x, 0.0f));
float height = cachedTextGeneratorForLayout.GetPreferredHeight(m_Text, settings) / pixelsPerUnit;
return height < rectTransform.rect.height || verticalOverflow == VerticalWrapMode.Overflow ? height : rectTransform.rect.height ;//Modify
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions