diff --git a/headers/enduro2d/high/components/layout.hpp b/headers/enduro2d/high/components/layout.hpp index efee1edd..2b8ba2bd 100644 --- a/headers/enduro2d/high/components/layout.hpp +++ b/headers/enduro2d/high/components/layout.hpp @@ -15,13 +15,35 @@ namespace e2d ENUM_HPP_CLASS_DECL(modes, u8, (vertical) (horizontal)) + + ENUM_HPP_CLASS_DECL(valigns, u8, + (top) + (center) + (bottom)) + + ENUM_HPP_CLASS_DECL(haligns, u8, + (left) + (center) + (right)) public: layout() = default; layout& mode(modes value) noexcept; [[nodiscard]] modes mode() const noexcept; + + layout& valign(valigns value) noexcept; + [[nodiscard]] valigns valign() const noexcept; + + layout& halign(haligns value) noexcept; + [[nodiscard]] haligns halign() const noexcept; + + layout& spacing(f32 value) noexcept; + [[nodiscard]] f32 spacing() const noexcept; private: modes mode_ = modes::vertical; + valigns valign_ = valigns::center; + haligns halign_ = haligns::center; + f32 spacing_ = 0.f; }; class layout_item final { @@ -31,6 +53,8 @@ namespace e2d } ENUM_HPP_REGISTER_TRAITS(e2d::layout::modes) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::haligns) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::valigns) namespace e2d { @@ -92,4 +116,31 @@ namespace e2d inline layout::modes layout::mode() const noexcept { return mode_; } + + inline layout& layout::valign(valigns value) noexcept { + valign_ = value; + return *this; + } + + inline layout::valigns layout::valign() const noexcept { + return valign_; + } + + inline layout& layout::halign(haligns value) noexcept { + halign_ = value; + return *this; + } + + inline layout::haligns layout::halign() const noexcept { + return halign_; + } + + inline layout& layout::spacing(f32 value) noexcept { + spacing_ = value; + return *this; + } + + inline f32 layout::spacing() const noexcept { + return spacing_; + } } diff --git a/samples/bin/library/scripts/emmy/components/layout.lua b/samples/bin/library/scripts/emmy/components/layout.lua index fbf6ce5a..4e8b5cb8 100644 --- a/samples/bin/library/scripts/emmy/components/layout.lua +++ b/samples/bin/library/scripts/emmy/components/layout.lua @@ -14,6 +14,15 @@ local layout = { ---@type layout_modes mode = layout.modes.vertical, + + ---@type layout_valigns + valign = layout.valigns.center, + + ---@type layout_haligns + halign = layout.haligns.center, + + ---@type number + spacing = 0.0 } ---@class layout_modes @@ -22,6 +31,20 @@ layout.modes = { horizontal = "horizontal" } +---@class layout_valigns +layout.valigns = { + top = "top", + center = "center", + bottom = "bottom" +} + +---@class layout_haligns +layout.haligns = { + left = "left", + center = "center", + right = "right" +} + ---@overload fun(self: layout) ---@param self layout function layout.enable(self) end 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 8078c4de..6eda23a1 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp @@ -56,6 +56,30 @@ namespace e2d::bindings::high }, [](gcomponent& c, layout::modes v){ c->mode(v); + }), + + "valign", sol::property( + [](const gcomponent& c) -> layout::valigns { + return c->valign(); + }, + [](gcomponent& c, layout::valigns v){ + c->valign(v); + }), + + "halign", sol::property( + [](const gcomponent& c) -> layout::haligns { + return c->halign(); + }, + [](gcomponent& c, layout::haligns v){ + c->halign(v); + }), + + "spacing", sol::property( + [](const gcomponent& c) -> f32 { + return c->spacing(); + }, + [](gcomponent& c, f32 v){ + c->spacing(v); }) ); @@ -67,6 +91,24 @@ namespace e2d::bindings::high }); #undef LAYOUT_MODE_PAIR + #define LAYOUT_HALIGN_PAIR(x) {#x, layout::haligns::x}, + l["layout"].get_or_create() + .new_enum("haligns", { + LAYOUT_HALIGN_PAIR(left) + LAYOUT_HALIGN_PAIR(center) + LAYOUT_HALIGN_PAIR(right) + }); + #undef LAYOUT_HALIGN_PAIR + + #define LAYOUT_VALIGN_PAIR(x) {#x, layout::valigns::x}, + l["layout"].get_or_create() + .new_enum("valigns", { + LAYOUT_VALIGN_PAIR(top) + LAYOUT_VALIGN_PAIR(center) + LAYOUT_VALIGN_PAIR(bottom) + }); + #undef LAYOUT_VALIGN_PAIR + l.new_usertype>("layout_item", sol::no_constructor, diff --git a/sources/enduro2d/high/components/layout.cpp b/sources/enduro2d/high/components/layout.cpp index 976ff7c1..0e6bffd5 100644 --- a/sources/enduro2d/high/components/layout.cpp +++ b/sources/enduro2d/high/components/layout.cpp @@ -13,7 +13,10 @@ namespace e2d "required" : [], "additionalProperties" : false, "properties" : { - "mode" : { "$ref": "#/definitions/modes" } + "mode" : { "$ref": "#/definitions/modes" }, + "valign" : { "$ref": "#/definitions/valigns" }, + "halign" : { "$ref": "#/definitions/haligns" }, + "spacing" : { "type" : "number" } }, "definitions" : { "modes" : { @@ -22,6 +25,22 @@ namespace e2d "vertical", "horizontal" ] + }, + "valigns" : { + "type" : "string", + "enum" : [ + "top", + "center", + "bottom" + ] + }, + "haligns" : { + "type" : "string", + "enum" : [ + "left", + "center", + "right" + ] } } })json"; @@ -39,6 +58,33 @@ namespace e2d component.mode(mode); } + if ( ctx.root.HasMember("valign") ) { + layout::valigns valign = component.valign(); + if ( !json_utils::try_parse_value(ctx.root["valign"], valign) ) { + the().error("LAYOUT: Incorrect formatting of 'valign' property"); + return false; + } + component.valign(valign); + } + + if ( ctx.root.HasMember("halign") ) { + layout::haligns halign = component.halign(); + if ( !json_utils::try_parse_value(ctx.root["halign"], halign) ) { + the().error("LAYOUT: Incorrect formatting of 'halign' property"); + return false; + } + component.halign(halign); + } + + if ( ctx.root.HasMember("spacing") ) { + f32 spacing = component.spacing(); + if ( !json_utils::try_parse_value(ctx.root["spacing"], spacing) ) { + the().error("LAYOUT: Incorrect formatting of 'spacing' property"); + return false; + } + component.spacing(spacing); + } + return true; } @@ -87,6 +133,24 @@ namespace e2d { c->mode(mode); } + + if ( layout::valigns valign = c->valign(); + imgui_utils::show_enum_combo_box("valign", &valign) ) + { + c->valign(valign); + } + + if ( layout::haligns halign = c->halign(); + imgui_utils::show_enum_combo_box("halign", &halign) ) + { + c->halign(halign); + } + + if ( f32 spacing = c->spacing(); + ImGui::DragFloat("spacing", &spacing, 1.f) ) + { + c->spacing(spacing); + } } }