About to cleanup truetype and newtruetype

This commit is contained in:
2023-06-16 10:29:08 -07:00
parent e70f71337f
commit 4f757c2ea9
3 changed files with 13 additions and 10 deletions

View File

@ -89,6 +89,9 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
struct FontShaderBufferData fontData;
quadCountTotal = 0;
std::vector<struct UILabelText> realNewTexts;
// Reset
lines.clear();
// Determine font dimensions.
auto itText = newTexts.begin();
@ -97,6 +100,10 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
++itText;
}
// Prepare values shared across all text parts/styles
float_t lineWidth = 0;
struct UILabelLine currentLine;
// Now generate quads
itText = newTexts.begin();
while(itText != newTexts.end()) {
@ -133,12 +140,9 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
// Prepare loop properties and shorthands
auto len = text.text.length();
float_t lineWidth = 0;
float_t wordWidth = 0;
int32_t lastSpaceCharacter = -1;
struct UILabelLine currentLine;
std::function<void(int32_t)> fnInsertNewline = [&](int32_t i){
if(i != len) {
// Update text.
@ -150,13 +154,13 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
vertices.push_back(std::make_pair(vert, uvs));
fontData.fontQuadMappings[quadCountTotal] = partIndex;
currentLine.quadCount++;
quadCountTotal++;
}
// Finalize current line
lineWidth += wordWidth;
currentLine.width = lineWidth;
currentLine.quadCount = quadCountTotal - currentLine.quadStart;
// Move to next line
position.x = 0;

View File

@ -32,23 +32,22 @@ namespace Dawn {
float_t width = 0.0f;
int32_t quadStart = -1;
int32_t quadCount = 0;
std::vector<struct UILabelText*> texts;
};
class UILabel : public UIComponentRenderable {
private:
Mesh mesh;
FontShaderBuffer shaderBuffer;
std::vector<struct UILabelText> texts;
std::vector<struct UILabelText> textsBuffered;
std::vector<struct UILabelLine> lines;
std::map<NewTrueTypeFaceTexture*, int32_t> textureMap;
public:
int32_t quadStart = 0;
int32_t quadCount = -1;
int32_t quadCountTotal = -1;
std::vector<struct UILabelText> texts;
std::vector<struct UILabelText> textsBuffered;
std::vector<struct UILabelLine> lines;
UILabel(SceneItem *item);

View File

@ -34,7 +34,7 @@ namespace Dawn {
// newLabel->maxWidth = 300.0f;
newLabel->richText = std::string(
"<font font=\"font_arial\" size=\"32\" color=\"COLOR_BLUE\">"
"Hello\nWorld"
"Hello World\nHow are you?"
// "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
// "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
// "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "