Made text calculate proper width with different fonts

This commit is contained in:
antopilo
2024-09-15 17:29:41 -04:00
parent c2e50822f1
commit 24be72b10a
4 changed files with 24 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ namespace NuakeUI
msdf_atlas::GeneratorAttributes generatorAttributes;
bool preprocessGeometry;
bool kerning;
int threadCount = 1;
int threadCount = 2;
};

View File

@@ -125,6 +125,8 @@ namespace NuakeUI
Vector2 ComputedPosition = { 0, 0 };
int32_t ComputedZIndex = 0;
NodeStyle ComputedStyle;
NodeStyle TargetStyle;
static NodePtr New(const std::string id, const std::string& value = "");
Node(const std::string& id, const std::string& value = "");

View File

@@ -130,8 +130,8 @@ namespace NuakeUI
// Iterate over each character and add up the advance.
for (char const& c : l)
{
Char letter = mFont->GetChar((int)c);
textWidth += (letter.Advance);
Char letter = ComputedStyle.FontFamily->GetChar((int)c);
textWidth += (letter.Advance * fontSize);
}
if (textWidth > maxWidth)
@@ -139,7 +139,7 @@ namespace NuakeUI
}
// Scale the width by the font size.
return maxWidth * fontSize;
return maxWidth;
}
void Text::Calculate()

View File

@@ -55,6 +55,9 @@ namespace NuakeUI
Value value;
std::string string;
Value targetValue;
float transitionTime = 0.2f;
PropValue()
{
@@ -64,20 +67,35 @@ namespace NuakeUI
{
type = t;
value.Number = f;
targetValue.Number = f;
}
PropValue(int i)
{
type = PropValueType::Enum;
value.Enum = i;
targetValue.Enum = i;
}
PropValue(Color c)
{
type = PropValueType::Color;
value.Color = c;
targetValue.Color = c;
}
Value GetInterpolatedValue(float t)
{
Value resultValue = value;
switch (type) {
case PropValueType::Percent:
case PropValueType::Pixel:
resultValue.Number = glm::mix(resultValue.Number, targetValue.Number, t);
break;
}
return resultValue;
}
};