From e2a80e39248ec460a6592e95084ae0810ae27306 Mon Sep 17 00:00:00 2001 From: sebastian Date: Thu, 12 Feb 2026 11:07:29 +0100 Subject: [PATCH] UPD: Simplify Margin System to top and left --- src/engine/core/gui/uiComponent/layout/LayoutStyle.h | 4 ---- .../core/gui/uiComponent/layout/UiPositioner.cpp | 12 ++++-------- src/game/UILayer.cpp | 7 +++---- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/engine/core/gui/uiComponent/layout/LayoutStyle.h b/src/engine/core/gui/uiComponent/layout/LayoutStyle.h index 3d550e0..12015d8 100644 --- a/src/engine/core/gui/uiComponent/layout/LayoutStyle.h +++ b/src/engine/core/gui/uiComponent/layout/LayoutStyle.h @@ -17,9 +17,7 @@ struct SizeValue { struct Margin { SizeValue left; - SizeValue right; SizeValue top; - SizeValue bottom; }; enum class FlexDirection { @@ -47,9 +45,7 @@ struct LayoutStyle { Margin margin = { .left = {0.0f, SizeUnit::Percent}, - .right = {0.0f, SizeUnit::Percent}, .top = {0.0f, SizeUnit::Percent}, - .bottom = {0.0f, SizeUnit::Percent} }; float flexGrow = 0.0f; diff --git a/src/engine/core/gui/uiComponent/layout/UiPositioner.cpp b/src/engine/core/gui/uiComponent/layout/UiPositioner.cpp index 9038f25..3c96079 100644 --- a/src/engine/core/gui/uiComponent/layout/UiPositioner.cpp +++ b/src/engine/core/gui/uiComponent/layout/UiPositioner.cpp @@ -11,15 +11,11 @@ void UiPositioner::compute(const Dimensions &parent) { const float screenWidth = static_cast(Application::getInstance().getWindow().GetWidth()); const float screenHeight = static_cast(Application::getInstance().getWindow().GetHeight()); - float left = resolve(style.margin.left, parent.width, screenWidth); - float right = resolve(style.margin.right, parent.width, screenWidth); - float top = resolve(style.margin.top, parent.height, screenHeight); - float bottom = resolve(style.margin.bottom, parent.height, screenHeight); - screenSpace.x = parent.x + left; - screenSpace.y = parent.y + top; - screenSpace.width = resolve(style.width, parent.width, screenWidth) - left - right; - screenSpace.height = resolve(style.height, parent.height, screenHeight) - top - bottom; + screenSpace.x = parent.x + resolve(style.margin.left, parent.width, screenWidth); + screenSpace.y = parent.y + resolve(style.margin.top, parent.height, screenHeight); + screenSpace.width = resolve(style.width, parent.width, screenWidth); + screenSpace.height = resolve(style.height, parent.height, screenHeight); } diff --git a/src/game/UILayer.cpp b/src/game/UILayer.cpp index 40417cc..18fa8ff 100644 --- a/src/game/UILayer.cpp +++ b/src/game/UILayer.cpp @@ -23,12 +23,10 @@ void UILayer::onAttach() { rootContainer = std::make_unique(); auto imageStyle = LayoutStyle(); - imageStyle.width = SizeValue(1.f, SizeUnit::Percent); - imageStyle.height = SizeValue(1.f, SizeUnit::Percent); + imageStyle.width = SizeValue(0.5f, SizeUnit::Percent); + imageStyle.height = SizeValue(0.5f, SizeUnit::Percent); imageStyle.margin.left = {50.f, SizeUnit::Pixels}; // 50px imageStyle.margin.top = {0.1f, SizeUnit::Percent}; // 10% vom Parent - imageStyle.margin.right = {20.f, SizeUnit::Pixels}; // 20px - imageStyle.margin.bottom = {0.05f, SizeUnit::Percent}; // 5% vom Parent auto image = std::make_unique( Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(), @@ -37,6 +35,7 @@ void UILayer::onAttach() { rootContainer->addChild(std::move(image)); + Font myFont("/usr/share/fonts/TTF/DejaVuSans.ttf", 48); font = std::make_unique(myFont); //auto text = std::make_unique(*font, "Hello World!", glm::vec2(0.5f, 0.5f), glm::vec3(1,1,1));