diff --git a/headers/enduro2d/high/components/layout.hpp b/headers/enduro2d/high/components/layout.hpp index 2b8ba2bd..61261264 100644 --- a/headers/enduro2d/high/components/layout.hpp +++ b/headers/enduro2d/high/components/layout.hpp @@ -49,6 +49,11 @@ namespace e2d class layout_item final { public: layout_item() = default; + + layout_item& size(const v2f& value) noexcept; + [[nodiscard]] const v2f& size() const noexcept; + private: + v2f size_ = v2f::unit(); }; } @@ -144,3 +149,15 @@ namespace e2d return spacing_; } } + +namespace e2d +{ + inline layout_item& layout_item::size(const v2f& value) noexcept { + size_ = value; + return *this; + } + + inline const v2f& layout_item::size() const noexcept { + return size_; + } +} diff --git a/samples/bin/library/scripts/emmy/components/layout.lua b/samples/bin/library/scripts/emmy/components/layout.lua index 4e8b5cb8..29ba7be9 100644 --- a/samples/bin/library/scripts/emmy/components/layout.lua +++ b/samples/bin/library/scripts/emmy/components/layout.lua @@ -65,7 +65,10 @@ local layout_item = { enabled = true, ---@type boolean - disabled = false + disabled = false, + + ---@type v2f + size = v2f.unit() } ---@overload fun(self: layout_item) diff --git a/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp index 6eda23a1..24e41a3a 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp @@ -144,7 +144,15 @@ namespace e2d::bindings::high c.owner().component>().remove(); } } - ) + ), + + "size", sol::property( + [](const gcomponent& c) -> v2f { + return c->size(); + }, + [](gcomponent& c, const v2f& v){ + c->size(v); + }) ); } } diff --git a/sources/enduro2d/high/components/layout.cpp b/sources/enduro2d/high/components/layout.cpp index 0e6bffd5..640c7afb 100644 --- a/sources/enduro2d/high/components/layout.cpp +++ b/sources/enduro2d/high/components/layout.cpp @@ -103,14 +103,24 @@ namespace e2d "type" : "object", "required" : [], "additionalProperties" : false, - "properties" : {} + "properties" : { + "size" : { "$ref": "#/common_definitions/v2" } + } })json"; bool factory_loader::operator()( layout_item& component, const fill_context& ctx) const { - E2D_UNUSED(component, ctx); + if ( ctx.root.HasMember("size") ) { + v2f size = component.size(); + if ( !json_utils::try_parse_value(ctx.root["size"], size) ) { + the().error("LAYOUT_ITEM: Incorrect formatting of 'size' property"); + return false; + } + component.size(size); + } + return true; } @@ -159,6 +169,10 @@ namespace e2d const char* component_inspector::title = ICON_FA_GRIP_LINES " layout_item"; void component_inspector::operator()(gcomponent& c) const { - E2D_UNUSED(c); + if ( v2f size = c->size(); + ImGui::DragFloat2("size", size.data(), 1.f) ) + { + c->size(size); + } } }