FIX: Correct text y positon
This commit is contained in:
parent
e52785ae14
commit
a61e5f4364
@ -44,6 +44,11 @@ Font::Font(const std::string &fontPath, unsigned int fontSize) {
|
|||||||
characters.insert({c, character});
|
characters.insert({c, character});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ascent = static_cast<float>(face->size->metrics.ascender) / 64.0f;
|
||||||
|
descent = static_cast<float>(face->size->metrics.descender) / 64.0f;
|
||||||
|
lineHeight = static_cast<float>(face->size->metrics.height) / 64.0f;
|
||||||
|
|
||||||
|
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
FT_Done_FreeType(ft);
|
FT_Done_FreeType(ft);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,11 +27,17 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] Character getCharacter(char c) const;
|
[[nodiscard]] Character getCharacter(char c) const;
|
||||||
|
float getAscent() const { return ascent; }
|
||||||
|
float getDescent() const { return descent; }
|
||||||
|
float getLineHeight() const { return lineHeight; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FT_Library ft;
|
FT_Library ft;
|
||||||
FT_Face face;
|
FT_Face face;
|
||||||
std::unordered_map<unsigned char, Character> characters;
|
std::unordered_map<unsigned char, Character> characters;
|
||||||
|
float ascent;
|
||||||
|
float descent;
|
||||||
|
float lineHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -30,11 +30,10 @@ void TextRenderer::renderText(const UiText &textToRender) {
|
|||||||
const std::string& text = textToRender.getText();
|
const std::string& text = textToRender.getText();
|
||||||
|
|
||||||
float screenX = d.x * Application::getInstance().getWindow().GetWidth();
|
float screenX = d.x * Application::getInstance().getWindow().GetWidth();
|
||||||
float screenY = d.y * Application::getInstance().getWindow().GetHeight();
|
float screenY = (1.f - d.y) * Application::getInstance().getWindow().GetHeight();
|
||||||
|
|
||||||
float x = screenX;
|
float x = screenX;
|
||||||
float y = screenY;
|
float y = screenY - font.getLineHeight();
|
||||||
|
|
||||||
|
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
shader.loadTextColor(textToRender.getColor());
|
shader.loadTextColor(textToRender.getColor());
|
||||||
|
|||||||
@ -23,13 +23,13 @@ void UILayer::onAttach() {
|
|||||||
|
|
||||||
rootContainer = std::make_unique<UiContainer>();
|
rootContainer = std::make_unique<UiContainer>();
|
||||||
LayoutStyle& rootLayout = rootContainer->getLayoutStyle();
|
LayoutStyle& rootLayout = rootContainer->getLayoutStyle();
|
||||||
rootLayout.justifyContent = JustifyContent::SpaceBetween;
|
rootLayout.justifyContent = JustifyContent::Start;
|
||||||
|
|
||||||
auto imageStyle = LayoutStyle();
|
auto imageStyle = LayoutStyle();
|
||||||
imageStyle.width = SizeValue(0.25f, SizeUnit::Percent);
|
imageStyle.width = SizeValue(0.25f, SizeUnit::Percent);
|
||||||
imageStyle.height = SizeValue(0.25f, SizeUnit::Percent);
|
imageStyle.height = SizeValue(0.25f, SizeUnit::Percent);
|
||||||
imageStyle.margin.left = {50.f, SizeUnit::Pixels}; // 50px
|
imageStyle.margin.left = {50.f, SizeUnit::Pixels}; // 50px
|
||||||
imageStyle.margin.top = {0.1f, SizeUnit::Percent};
|
imageStyle.margin.top = {0.f, SizeUnit::Percent};
|
||||||
|
|
||||||
auto image = std::make_unique<UiImage>(
|
auto image = std::make_unique<UiImage>(
|
||||||
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||||
@ -40,8 +40,14 @@ void UILayer::onAttach() {
|
|||||||
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||||
imageStyle
|
imageStyle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
auto image3 = std::make_unique<UiImage>(
|
||||||
|
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||||
|
imageStyle
|
||||||
|
);
|
||||||
rootContainer->addChild(std::move(image));
|
rootContainer->addChild(std::move(image));
|
||||||
rootContainer->addChild(std::move(image2));
|
rootContainer->addChild(std::move(image2));
|
||||||
|
rootContainer->addChild(std::move(image3));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -51,7 +57,7 @@ void UILayer::onAttach() {
|
|||||||
|
|
||||||
auto text = std::make_unique<UiText>(*font, "Hello World", imageStyle);
|
auto text = std::make_unique<UiText>(*font, "Hello World", imageStyle);
|
||||||
|
|
||||||
//rootContainer->addChild(std::move(text));
|
rootContainer->addChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UILayer::onUpdate() {
|
void UILayer::onUpdate() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user