diff --git a/src/engine/core/gui/text/Font.cpp b/src/engine/core/gui/text/Font.cpp index fa9ede2..d90f6b1 100644 --- a/src/engine/core/gui/text/Font.cpp +++ b/src/engine/core/gui/text/Font.cpp @@ -44,6 +44,11 @@ Font::Font(const std::string &fontPath, unsigned int fontSize) { characters.insert({c, character}); } + ascent = static_cast(face->size->metrics.ascender) / 64.0f; + descent = static_cast(face->size->metrics.descender) / 64.0f; + lineHeight = static_cast(face->size->metrics.height) / 64.0f; + + FT_Done_Face(face); FT_Done_FreeType(ft); } diff --git a/src/engine/core/gui/text/Font.h b/src/engine/core/gui/text/Font.h index 8c25c79..5439c58 100644 --- a/src/engine/core/gui/text/Font.h +++ b/src/engine/core/gui/text/Font.h @@ -27,11 +27,17 @@ public: }; [[nodiscard]] Character getCharacter(char c) const; + float getAscent() const { return ascent; } + float getDescent() const { return descent; } + float getLineHeight() const { return lineHeight; } private: FT_Library ft; FT_Face face; std::unordered_map characters; + float ascent; + float descent; + float lineHeight; }; diff --git a/src/engine/renderer/TextRenderer.cpp b/src/engine/renderer/TextRenderer.cpp index 3df13e5..44213c0 100644 --- a/src/engine/renderer/TextRenderer.cpp +++ b/src/engine/renderer/TextRenderer.cpp @@ -30,11 +30,10 @@ void TextRenderer::renderText(const UiText &textToRender) { const std::string& text = textToRender.getText(); 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 y = screenY; - + float y = screenY - font.getLineHeight(); float scale = 1.0f; shader.loadTextColor(textToRender.getColor()); diff --git a/src/game/UILayer.cpp b/src/game/UILayer.cpp index bd6d36b..3da7252 100644 --- a/src/game/UILayer.cpp +++ b/src/game/UILayer.cpp @@ -23,13 +23,13 @@ void UILayer::onAttach() { rootContainer = std::make_unique(); LayoutStyle& rootLayout = rootContainer->getLayoutStyle(); - rootLayout.justifyContent = JustifyContent::SpaceBetween; + rootLayout.justifyContent = JustifyContent::Start; auto imageStyle = LayoutStyle(); imageStyle.width = SizeValue(0.25f, SizeUnit::Percent); imageStyle.height = SizeValue(0.25f, SizeUnit::Percent); 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( Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(), @@ -40,8 +40,14 @@ void UILayer::onAttach() { Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(), imageStyle ); + + auto image3 = std::make_unique( + Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(), + imageStyle +); rootContainer->addChild(std::move(image)); rootContainer->addChild(std::move(image2)); + rootContainer->addChild(std::move(image3)); @@ -51,7 +57,7 @@ void UILayer::onAttach() { auto text = std::make_unique(*font, "Hello World", imageStyle); - //rootContainer->addChild(std::move(text)); + rootContainer->addChild(std::move(text)); } void UILayer::onUpdate() {