mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Made text calculate proper width with different fonts
This commit is contained in:
@@ -29,7 +29,7 @@ namespace NuakeUI
|
||||
msdf_atlas::GeneratorAttributes generatorAttributes;
|
||||
bool preprocessGeometry;
|
||||
bool kerning;
|
||||
int threadCount = 1;
|
||||
int threadCount = 2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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 = "");
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user