diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index 53cc2896..205ba73b 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -45,6 +45,7 @@ #include "components/spine_player.hpp" #include "components/sprite_renderer.hpp" #include "components/touchable.hpp" +#include "components/widget.hpp" #include "resources/atlas.hpp" #include "resources/flipbook.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 8c01cf3d..61c3d0e4 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -65,6 +65,7 @@ namespace e2d class spine_player; class sprite_renderer; class touchable; + class widget; class atlas; class flipbook; diff --git a/headers/enduro2d/high/components/layout.hpp b/headers/enduro2d/high/components/layout.hpp index a7aae13b..36ecaef1 100644 --- a/headers/enduro2d/high/components/layout.hpp +++ b/headers/enduro2d/high/components/layout.hpp @@ -14,23 +14,31 @@ namespace e2d public: class dirty final {}; public: - ENUM_HPP_CLASS_DECL(haligns, u8, - (left) - (center) - (right) - (space_around) - (space_evenly) - (space_between)) - - ENUM_HPP_CLASS_DECL(valigns, u8, - (top) - (center) - (bottom) - (space_around) - (space_evenly) - (space_between)) - ENUM_HPP_CLASS_DECL(directions, u8, + (ltr) + (rtl)) + + ENUM_HPP_CLASS_DECL(align_modes, u8, + (flex_start) + (center) + (flex_end) + (space_between) + (space_around)) + + ENUM_HPP_CLASS_DECL(justify_modes, u8, + (flex_start) + (center) + (flex_end) + (space_between) + (space_around) + (space_evenly)) + + ENUM_HPP_CLASS_DECL(flex_wraps, u8, + (no_wrap) + (wrap) + (wrap_reversed)) + + ENUM_HPP_CLASS_DECL(flex_directions, u8, (row) (row_reversed) (column) @@ -38,37 +46,38 @@ namespace e2d public: layout() = default; - layout& halign(haligns value) noexcept; - [[nodiscard]] haligns halign() const noexcept; - - layout& valign(valigns value) noexcept; - [[nodiscard]] valigns valign() const noexcept; - layout& direction(directions value) noexcept; [[nodiscard]] directions direction() const noexcept; - public: - layout& size(const v2f& value) noexcept; - [[nodiscard]] const v2f& size() const noexcept; - layout& margin(const v2f& value) noexcept; - [[nodiscard]] const v2f& margin() const noexcept; + layout& align_items(align_modes value) noexcept; + [[nodiscard]] align_modes align_items() const noexcept; - layout& padding(const v2f& value) noexcept; - [[nodiscard]] const v2f& padding() const noexcept; + layout& align_content(align_modes value) noexcept; + [[nodiscard]] align_modes align_content() const noexcept; + + layout& justify_content(justify_modes value) noexcept; + [[nodiscard]] justify_modes justify_content() const noexcept; + + layout& flex_wrap(flex_wraps value) noexcept; + [[nodiscard]] flex_wraps flex_wrap() const noexcept; + + layout& flex_direction(flex_directions value) noexcept; + [[nodiscard]] flex_directions flex_direction() const noexcept; private: - haligns halign_ = haligns::center; - valigns valign_ = valigns::center; - directions direction_ = directions::row; - private: - v2f size_ = v2f::zero(); - v2f margin_ = v2f::zero(); - v2f padding_ = v2f::zero(); + directions direction_ = directions::ltr; + align_modes align_items_ = align_modes::flex_start; + align_modes align_content_ = align_modes::flex_start; + justify_modes justify_content_ = justify_modes::flex_start; + flex_wraps flex_wrap_ = flex_wraps::no_wrap; + flex_directions flex_direction_ = flex_directions::row; }; } -ENUM_HPP_REGISTER_TRAITS(e2d::layout::haligns) -ENUM_HPP_REGISTER_TRAITS(e2d::layout::valigns) ENUM_HPP_REGISTER_TRAITS(e2d::layout::directions) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::align_modes) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::justify_modes) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::flex_wraps) +ENUM_HPP_REGISTER_TRAITS(e2d::layout::flex_directions) namespace e2d { @@ -109,30 +118,11 @@ namespace e2d static const char* title; void operator()(gcomponent& c) const; - void operator()(gcomponent& c, gizmos_context& ctx) const; }; } namespace e2d { - inline layout& layout::halign(haligns value) noexcept { - halign_ = value; - return *this; - } - - inline layout::haligns layout::halign() const noexcept { - return halign_; - } - - inline layout& layout::valign(valigns value) noexcept { - valign_ = value; - return *this; - } - - inline layout::valigns layout::valign() const noexcept { - return valign_; - } - inline layout& layout::direction(directions value) noexcept { direction_ = value; return *this; @@ -142,31 +132,49 @@ namespace e2d return direction_; } - inline layout& layout::size(const v2f& value) noexcept { - size_ = value; + inline layout& layout::align_items(align_modes value) noexcept { + align_items_ = value; return *this; } - inline const v2f& layout::size() const noexcept { - return size_; + inline layout::align_modes layout::align_items() const noexcept { + return align_items_; } - inline layout& layout::margin(const v2f& value) noexcept { - margin_ = value; + inline layout& layout::align_content(align_modes value) noexcept { + align_content_ = value; return *this; } - inline const v2f& layout::margin() const noexcept { - return margin_; + inline layout::align_modes layout::align_content() const noexcept { + return align_content_; } - inline layout& layout::padding(const v2f& value) noexcept { - padding_ = value; + inline layout& layout::justify_content(justify_modes value) noexcept { + justify_content_ = value; return *this; } - inline const v2f& layout::padding() const noexcept { - return padding_; + inline layout::justify_modes layout::justify_content() const noexcept { + return justify_content_; + } + + inline layout& layout::flex_wrap(flex_wraps value) noexcept { + flex_wrap_ = value; + return *this; + } + + inline layout::flex_wraps layout::flex_wrap() const noexcept { + return flex_wrap_; + } + + inline layout& layout::flex_direction(flex_directions value) noexcept { + flex_direction_ = value; + return *this; + } + + inline layout::flex_directions layout::flex_direction() const noexcept { + return flex_direction_; } } @@ -176,13 +184,12 @@ namespace e2d::layouts gcomponent unmark_dirty(gcomponent self); bool is_dirty(const const_gcomponent& self) noexcept; - gcomponent change_halign(gcomponent self, layout::haligns value); - gcomponent change_valign(gcomponent self, layout::valigns value); gcomponent change_direction(gcomponent self, layout::directions value); - - gcomponent change_size(gcomponent self, const v2f& value); - gcomponent change_margin(gcomponent self, const v2f& value); - gcomponent change_padding(gcomponent self, const v2f& value); + gcomponent change_align_items(gcomponent self, layout::align_modes value); + gcomponent change_align_content(gcomponent self, layout::align_modes value); + gcomponent change_justify_content(gcomponent self, layout::justify_modes value); + gcomponent change_flex_wrap(gcomponent self, layout::flex_wraps value); + gcomponent change_flex_direction(gcomponent self, layout::flex_directions value); gcomponent find_parent_layout(const_gcomponent self) noexcept; } diff --git a/headers/enduro2d/high/components/widget.hpp b/headers/enduro2d/high/components/widget.hpp new file mode 100644 index 00000000..df69ffef --- /dev/null +++ b/headers/enduro2d/high/components/widget.hpp @@ -0,0 +1,118 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "_components.hpp" + +namespace e2d +{ + class widget final { + public: + class dirty final {}; + public: + widget() = default; + + widget& size(const v2f& value) noexcept; + [[nodiscard]] const v2f& size() const noexcept; + + widget& margin(const v2f& value) noexcept; + [[nodiscard]] const v2f& margin() const noexcept; + + widget& padding(const v2f& value) noexcept; + [[nodiscard]] const v2f& padding() const noexcept; + private: + v2f size_ = v2f::zero(); + v2f margin_ = v2f::zero(); + v2f padding_ = v2f::zero(); + }; +} + +namespace e2d +{ + template <> + class factory_loader final : factory_loader<> { + public: + static const char* schema_source; + + bool operator()( + widget& component, + const fill_context& ctx) const; + + bool operator()( + asset_dependencies& dependencies, + const collect_context& ctx) const; + }; + + template <> + class factory_loader final : factory_loader<> { + public: + static const char* schema_source; + + bool operator()( + widget::dirty& component, + const fill_context& ctx) const; + + bool operator()( + asset_dependencies& dependencies, + const collect_context& ctx) const; + }; +} + +namespace e2d +{ + template <> + class component_inspector final : component_inspector<> { + public: + static const char* title; + + void operator()(gcomponent& c) const; + void operator()(gcomponent& c, gizmos_context& ctx) const; + }; +} + +namespace e2d +{ + inline widget& widget::size(const v2f& value) noexcept { + size_ = value; + return *this; + } + + inline const v2f& widget::size() const noexcept { + return size_; + } + + inline widget& widget::margin(const v2f& value) noexcept { + margin_ = value; + return *this; + } + + inline const v2f& widget::margin() const noexcept { + return margin_; + } + + inline widget& widget::padding(const v2f& value) noexcept { + padding_ = value; + return *this; + } + + inline const v2f& widget::padding() const noexcept { + return padding_; + } +} + +namespace e2d::widgets +{ + gcomponent mark_dirty(gcomponent self); + gcomponent unmark_dirty(gcomponent self); + bool is_dirty(const const_gcomponent& self) noexcept; + + gcomponent change_size(gcomponent self, const v2f& value); + gcomponent change_margin(gcomponent self, const v2f& value); + gcomponent change_padding(gcomponent self, const v2f& value); + + gcomponent find_parent_layout(const_gcomponent self) noexcept; +} diff --git a/headers/enduro2d/high/gobject.hpp b/headers/enduro2d/high/gobject.hpp index 9c2f62d6..c68cfa01 100644 --- a/headers/enduro2d/high/gobject.hpp +++ b/headers/enduro2d/high/gobject.hpp @@ -94,6 +94,12 @@ namespace e2d gobject owner() const noexcept; explicit operator bool() const noexcept; + + template < typename U > + gcomponent component() noexcept; + + template < typename U > + const_gcomponent component() const noexcept; private: gobject owner_; }; @@ -116,6 +122,9 @@ namespace e2d gobject owner() const noexcept; explicit operator bool() const noexcept; + + template < typename U > + const_gcomponent component() const noexcept; private: gobject owner_; }; @@ -239,6 +248,18 @@ namespace e2d gcomponent::operator bool() const noexcept { return exists(); } + + template < typename T > + template < typename U > + gcomponent gcomponent::component() noexcept { + return owner_.component(); + } + + template < typename T > + template < typename U > + const_gcomponent gcomponent::component() const noexcept { + return owner_.component(); + } } namespace e2d @@ -294,4 +315,10 @@ namespace e2d const_gcomponent::operator bool() const noexcept { return exists(); } + + template < typename T > + template < typename U > + const_gcomponent const_gcomponent::component() const noexcept { + return owner_.component(); + } } diff --git a/headers/enduro2d/high/systems/widget_system.hpp b/headers/enduro2d/high/systems/widget_system.hpp new file mode 100644 index 00000000..8abcaa82 --- /dev/null +++ b/headers/enduro2d/high/systems/widget_system.hpp @@ -0,0 +1,26 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "_systems.hpp" + +namespace e2d +{ + class widget_system final + : public ecs::system> { + public: + widget_system(); + ~widget_system() noexcept final; + + void process( + ecs::registry& owner, + const ecs::after& trigger) override; + private: + class internal_state; + std::unique_ptr state_; + }; +} diff --git a/headers/enduro2d/high/world.hpp b/headers/enduro2d/high/world.hpp index 0a74b2f8..3276fbae 100644 --- a/headers/enduro2d/high/world.hpp +++ b/headers/enduro2d/high/world.hpp @@ -24,12 +24,15 @@ namespace e2d const ecs::registry& registry() const noexcept; gobject instantiate(); - gobject instantiate(const prefab& prefab); + gobject instantiate(const t2f& transform); gobject instantiate(const node_iptr& parent); - gobject instantiate(const prefab& prefab, const node_iptr& parent); - gobject instantiate(const node_iptr& parent, const t2f& transform); + + gobject instantiate(const prefab& prefab); + gobject instantiate(const prefab& prefab, const t2f& transform); + + gobject instantiate(const prefab& prefab, const node_iptr& parent); gobject instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform); void destroy_instance(gobject inst) noexcept; diff --git a/samples/bin/library/prefabs/layout_prefab.json b/samples/bin/library/prefabs/layout_prefab.json index 9a241d87..da2dab99 100644 --- a/samples/bin/library/prefabs/layout_prefab.json +++ b/samples/bin/library/prefabs/layout_prefab.json @@ -1,4 +1,5 @@ { + "prototype" : "widget_prefab.json", "components" : { "named" : { "name" : "layout" diff --git a/samples/bin/library/prefabs/widget_prefab.json b/samples/bin/library/prefabs/widget_prefab.json new file mode 100644 index 00000000..73fab3dc --- /dev/null +++ b/samples/bin/library/prefabs/widget_prefab.json @@ -0,0 +1,9 @@ +{ + "components" : { + "named" : { + "name" : "widget" + }, + "widget" : {}, + "widget.dirty" : {} + } +} diff --git a/samples/bin/library/scenes/sample_09.json b/samples/bin/library/scenes/sample_09.json index 256bf5c4..aefb3066 100644 --- a/samples/bin/library/scenes/sample_09.json +++ b/samples/bin/library/scenes/sample_09.json @@ -15,14 +15,16 @@ "prototype" : "../prefabs/layout_prefab.json", "components" : { "layout" : { - "size" : [400,200], - "halign" : "space_evenly" + "justify_content" : "space_evenly" + }, + "widget" : { + "size" : [400,200] } }, "children" : [{ - "prototype" : "../prefabs/layout_prefab.json", + "prototype" : "../prefabs/widget_prefab.json", "components" : { - "layout" : { + "widget" : { "size" : [66,113] } }, @@ -35,9 +37,9 @@ } }] },{ - "prototype" : "../prefabs/layout_prefab.json", + "prototype" : "../prefabs/widget_prefab.json", "components" : { - "layout" : { + "widget" : { "size" : [66,113] } }, @@ -50,9 +52,9 @@ } }] },{ - "prototype" : "../prefabs/layout_prefab.json", + "prototype" : "../prefabs/widget_prefab.json", "components" : { - "layout" : { + "widget" : { "size" : [66,113] } }, diff --git a/samples/bin/library/scripts/emmy/components/layout.lua b/samples/bin/library/scripts/emmy/components/layout.lua index 3dcc1b61..7750fd46 100644 --- a/samples/bin/library/scripts/emmy/components/layout.lua +++ b/samples/bin/library/scripts/emmy/components/layout.lua @@ -9,47 +9,59 @@ local layout = { ---@type boolean dirty = false, - ---@type layout_haligns - halign = layout.haligns.center, - - ---@type layout_valigns - valign = layout.valigns.center, - ---@type layout_directions - direction = layout.directions.row, + direction = layout.directions.ltr, - ---@type v2f - size = v2f.zero(), + ---@type layout_align_modes + align_items = layout.align_modes.flex_start, - ---@type v2f - margin = v2f.zero(), + ---@type layout_align_modes + align_conten = layout.align_modes.flex_start, - ---@type v2f - padding = v2f.zero() -} + ---@type layout_justify_modes + justify_content = layout.justify_modes.flex_start, ----@class layout_haligns -layout.haligns = { - left = "left", - center = "center", - right = "right", - space_around = "space_around", - space_evenly = "space_evenly", - space_between = "space_between" -} + ---@type layout_flex_wraps + flex_wrap = layout.flex_wraps.no_wrap, ----@class layout_valigns -layout.valigns = { - top = "top", - center = "center", - bottom = "bottom", - space_around = "space_around", - space_evenly = "space_evenly", - space_between = "space_between" + ---@type layout_flex_directions + flex_direction = layout.flex_directions.row } ---@class layout_directions layout.directions = { + ltr = "ltr", + rtl = "rtl" +} + +---@class layout_align_modes +layout.align_modes = { + flex_start = "flex_start", + center = "center", + flex_end = "flex_end", + space_between = "space_between", + space_around = "space_around" +} + +---@class layout_justify_modes +layout.justify_modes = { + flex_start = "flex_start", + center = "center", + flex_end = "flex_end", + space_between = "space_between", + space_around = "space_around", + space_evenly = "space_evenly" +} + +---@class layout_flex_wraps +layout.flex_wraps = { + no_wrap = "no_wrap", + wrap = "wrap", + wrap_reversed = "wrap_reversed" +} + +---@class layout_flex_directions +layout.flex_directions = { row = "row", row_reversed = "row_reversed", column = "column", diff --git a/samples/bin/library/scripts/emmy/components/widget.lua b/samples/bin/library/scripts/emmy/components/widget.lua new file mode 100644 index 00000000..508faed1 --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/widget.lua @@ -0,0 +1,31 @@ +---@class widget +local widget = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false, + + ---@type boolean + dirty = false, + + ---@type v2f + size = v2f.zero(), + + ---@type v2f + margin = v2f.zero(), + + ---@type v2f + padding = v2f.zero() +} + +---@overload fun(self: widget) +---@param self widget +function widget.enable(self) end + +---@overload fun(self: widget) +---@param self widget +function widget.disable(self) end + +---@type widget +_G.widget = _G.widget or widget diff --git a/samples/bin/library/scripts/emmy/high/gobject.lua b/samples/bin/library/scripts/emmy/high/gobject.lua index bfddd716..9b21314d 100644 --- a/samples/bin/library/scripts/emmy/high/gobject.lua +++ b/samples/bin/library/scripts/emmy/high/gobject.lua @@ -52,7 +52,10 @@ local gobject = { sprite_renderer = nil, ---@type touchable - touchable = nil + touchable = nil, + + ---@type widget + widget = nil } ---@param self gobject diff --git a/samples/bin/library/scripts/emmy/high/world.lua b/samples/bin/library/scripts/emmy/high/world.lua index 43cfd182..052c60ae 100644 --- a/samples/bin/library/scripts/emmy/high/world.lua +++ b/samples/bin/library/scripts/emmy/high/world.lua @@ -2,7 +2,12 @@ local world = { } +---@overload fun(): gobject +---@overload fun(transform: t2f): gobject +---@overload fun(parent: node): gobject +---@overload fun(parent: node, transform: t2f): gobject ---@overload fun(prefab: prefab): gobject +---@overload fun(prefab: prefab, transform: t2f): gobject ---@overload fun(prefab: prefab, parent: node): gobject ---@overload fun(prefab: prefab, parent: node, transform: t2f): gobject ---@return gobject diff --git a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp index e4dfeb30..73bb1638 100644 --- a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp +++ b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp @@ -32,6 +32,7 @@ namespace e2d::bindings::high void bind_spine_player(sol::state& l); void bind_sprite_renderer(sol::state& l); void bind_touchable(sol::state& l); + void bind_widget(sol::state& l); } namespace e2d::bindings @@ -59,5 +60,6 @@ namespace e2d::bindings high::bind_spine_player(l); high::bind_sprite_renderer(l); high::bind_touchable(l); + high::bind_widget(l); } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp index 6956fb3f..0e4df5a0 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/behaviour_binds.cpp @@ -17,35 +17,35 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), diff --git a/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp index 8e17908a..ad080e88 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/camera_binds.cpp @@ -17,61 +17,61 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), "input", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component().exists(); + return c.component().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component().ensure(); + c.component().ensure(); } else { - c.owner().component().remove(); + c.component().remove(); } } ), "gizmos", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component().exists(); + return c.component().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component().ensure(); + c.component().ensure(); } else { - c.owner().component().remove(); + c.component().remove(); } } ), diff --git a/sources/enduro2d/high/bindings/high_binds/components/colliders_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/colliders_binds.cpp index aa179c87..d5be5d4e 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/colliders_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/colliders_binds.cpp @@ -19,35 +19,35 @@ namespace sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), @@ -75,35 +75,35 @@ namespace sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), @@ -131,35 +131,35 @@ namespace sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), 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 028db8ca..feb447c0 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/layout_binds.cpp @@ -17,24 +17,24 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); layouts::mark_dirty(c); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); layouts::mark_dirty(c); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } layouts::mark_dirty(c); } @@ -42,13 +42,13 @@ namespace e2d::bindings::high "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } layouts::mark_dirty(c); } @@ -67,22 +67,6 @@ namespace e2d::bindings::high } ), - "halign", sol::property( - [](const gcomponent& c) -> layout::haligns { - return c->halign(); - }, - [](gcomponent& c, layout::haligns v){ - layouts::change_halign(c, v); - }), - - "valign", sol::property( - [](const gcomponent& c) -> layout::valigns { - return c->valign(); - }, - [](gcomponent& c, layout::valigns v){ - layouts::change_valign(c, v); - }), - "direction", sol::property( [](const gcomponent& c) -> layout::directions { return c->direction(); @@ -91,63 +75,95 @@ namespace e2d::bindings::high layouts::change_direction(c, v); }), - "size", sol::property( - [](const gcomponent& c) -> v2f { - return c->size(); + "align_items", sol::property( + [](const gcomponent& c) -> layout::align_modes { + return c->align_items(); }, - [](gcomponent& c, const v2f& v){ - layouts::change_size(c, v); + [](gcomponent& c, layout::align_modes v){ + layouts::change_align_items(c, v); }), - "margin", sol::property( - [](const gcomponent& c) -> v2f { - return c->margin(); + "align_content", sol::property( + [](const gcomponent& c) -> layout::align_modes { + return c->align_content(); }, - [](gcomponent& c, const v2f& v){ - layouts::change_margin(c, v); + [](gcomponent& c, layout::align_modes v){ + layouts::change_align_content(c, v); }), - "padding", sol::property( - [](const gcomponent& c) -> v2f { - return c->padding(); + "justify_content", sol::property( + [](const gcomponent& c) -> layout::justify_modes { + return c->justify_content(); }, - [](gcomponent& c, const v2f& v){ - layouts::change_padding(c, v); + [](gcomponent& c, layout::justify_modes v){ + layouts::change_justify_content(c, v); + }), + + "flex_wrap", sol::property( + [](const gcomponent& c) -> layout::flex_wraps { + return c->flex_wrap(); + }, + [](gcomponent& c, layout::flex_wraps v){ + layouts::change_flex_wrap(c, v); + }), + + "flex_direction", sol::property( + [](const gcomponent& c) -> layout::flex_directions { + return c->flex_direction(); + }, + [](gcomponent& c, layout::flex_directions v){ + layouts::change_flex_direction(c, v); }) ); - #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) - LAYOUT_HALIGN_PAIR(space_around) - LAYOUT_HALIGN_PAIR(space_evenly) - LAYOUT_HALIGN_PAIR(space_between) - }); - #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) - LAYOUT_VALIGN_PAIR(space_around) - LAYOUT_VALIGN_PAIR(space_evenly) - LAYOUT_VALIGN_PAIR(space_between) - }); - #undef LAYOUT_VALIGN_PAIR - #define LAYOUT_DIRECTION_PAIR(x) {#x, layout::directions::x}, l["layout"].get_or_create() .new_enum("directions", { - LAYOUT_DIRECTION_PAIR(row) - LAYOUT_DIRECTION_PAIR(row_reversed) - LAYOUT_DIRECTION_PAIR(column) - LAYOUT_DIRECTION_PAIR(column_reversed) + LAYOUT_DIRECTION_PAIR(ltr) + LAYOUT_DIRECTION_PAIR(rtl) }); #undef LAYOUT_DIRECTION_PAIR + + #define LAYOUT_ALIGN_MODE_PAIR(x) {#x, layout::align_modes::x}, + l["layout"].get_or_create() + .new_enum("align_modes", { + LAYOUT_ALIGN_MODE_PAIR(flex_start) + LAYOUT_ALIGN_MODE_PAIR(center) + LAYOUT_ALIGN_MODE_PAIR(flex_end) + LAYOUT_ALIGN_MODE_PAIR(space_between) + LAYOUT_ALIGN_MODE_PAIR(space_around) + }); + #undef LAYOUT_ALIGN_MODE_PAIR + + #define LAYOUT_JUSTIFY_MODE_PAIR(x) {#x, layout::justify_modes::x}, + l["layout"].get_or_create() + .new_enum("justify_modes", { + LAYOUT_JUSTIFY_MODE_PAIR(flex_start) + LAYOUT_JUSTIFY_MODE_PAIR(center) + LAYOUT_JUSTIFY_MODE_PAIR(flex_end) + LAYOUT_JUSTIFY_MODE_PAIR(space_between) + LAYOUT_JUSTIFY_MODE_PAIR(space_around) + LAYOUT_JUSTIFY_MODE_PAIR(space_evenly) + }); + #undef LAYOUT_JUSTIFY_MODE_PAIR + + #define LAYOUT_FLEX_WRAP_PAIR(x) {#x, layout::flex_wraps::x}, + l["layout"].get_or_create() + .new_enum("flex_wraps", { + LAYOUT_FLEX_WRAP_PAIR(no_wrap) + LAYOUT_FLEX_WRAP_PAIR(wrap) + LAYOUT_FLEX_WRAP_PAIR(wrap_reversed) + }); + #undef LAYOUT_FLEX_WRAP_PAIR + + #define LAYOUT_FLEX_DIRECTION_PAIR(x) {#x, layout::flex_directions::x}, + l["layout"].get_or_create() + .new_enum("flex_directions", { + LAYOUT_FLEX_DIRECTION_PAIR(row) + LAYOUT_FLEX_DIRECTION_PAIR(row_reversed) + LAYOUT_FLEX_DIRECTION_PAIR(column) + LAYOUT_FLEX_DIRECTION_PAIR(column_reversed) + }); + #undef LAYOUT_FLEX_DIRECTION_PAIR } } diff --git a/sources/enduro2d/high/bindings/high_binds/components/renderer_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/renderer_binds.cpp index 736a6a6e..b4ea242d 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/renderer_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/renderer_binds.cpp @@ -17,35 +17,35 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), diff --git a/sources/enduro2d/high/bindings/high_binds/components/scene_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/scene_binds.cpp index 0c9a80e5..3ab188a4 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/scene_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/scene_binds.cpp @@ -17,35 +17,35 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), diff --git a/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp index 26e2cd97..591aaf9f 100644 --- a/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/components/touchable_binds.cpp @@ -17,35 +17,35 @@ namespace e2d::bindings::high sol::no_constructor, "enable", [](gcomponent& c){ - c.owner().component>().remove(); + c.component>().remove(); }, "disable", [](gcomponent& c){ - c.owner().component>().ensure(); + c.component>().ensure(); }, "enabled", sol::property( [](const gcomponent& c) -> bool { - return !c.owner().component>().exists(); + return !c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().remove(); + c.component>().remove(); } else { - c.owner().component>().ensure(); + c.component>().ensure(); } } ), "disabled", sol::property( [](const gcomponent& c) -> bool { - return c.owner().component>().exists(); + return c.component>().exists(); }, [](gcomponent& c, bool yesno){ if ( yesno ) { - c.owner().component>().ensure(); + c.component>().ensure(); } else { - c.owner().component>().remove(); + c.component>().remove(); } } ), diff --git a/sources/enduro2d/high/bindings/high_binds/components/widget_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/widget_binds.cpp new file mode 100644 index 00000000..7991a8ec --- /dev/null +++ b/sources/enduro2d/high/bindings/high_binds/components/widget_binds.cpp @@ -0,0 +1,91 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include "../_high_binds.hpp" + +#include +#include +#include + +namespace e2d::bindings::high +{ + void bind_widget(sol::state& l) { + l.new_usertype>("widget", + sol::no_constructor, + + "enable", [](gcomponent& c){ + c.component>().remove(); + }, + + "disable", [](gcomponent& c){ + c.component>().ensure(); + }, + + "enabled", sol::property( + [](const gcomponent& c) -> bool { + return !c.component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.component>().remove(); + } else { + c.component>().ensure(); + } + } + ), + + "disabled", sol::property( + [](const gcomponent& c) -> bool { + return c.component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.component>().ensure(); + } else { + c.component>().remove(); + } + } + ), + + "dirty", sol::property( + [](const gcomponent& c) -> bool { + return widgets::is_dirty(c); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + widgets::mark_dirty(c); + } else { + widgets::unmark_dirty(c); + } + } + ), + + "size", sol::property( + [](const gcomponent& c) -> v2f { + return c->size(); + }, + [](gcomponent& c, const v2f& v){ + widgets::change_size(c, v); + }), + + "margin", sol::property( + [](const gcomponent& c) -> v2f { + return c->margin(); + }, + [](gcomponent& c, const v2f& v){ + widgets::change_margin(c, v); + }), + + "padding", sol::property( + [](const gcomponent& c) -> v2f { + return c->padding(); + }, + [](gcomponent& c, const v2f& v){ + widgets::change_padding(c, v); + }) + ); + } +} diff --git a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp index 3d6b7346..9335afc7 100644 --- a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace e2d::bindings::high { @@ -54,7 +55,8 @@ namespace e2d::bindings::high "scene", sol::property([](gobject& go){ return component_wrapper{go}; }), "spine_player", sol::property([](gobject& go){ return component_wrapper{go}; }), "sprite_renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), - "touchable", sol::property([](gobject& go){ return component_wrapper{go}; }) + "touchable", sol::property([](gobject& go){ return component_wrapper{go}; }), + "widget", sol::property([](gobject& go){ return component_wrapper{go}; }) ); } } diff --git a/sources/enduro2d/high/bindings/high_binds/world_binds.cpp b/sources/enduro2d/high/bindings/high_binds/world_binds.cpp index 71b74fc4..ae898564 100644 --- a/sources/enduro2d/high/bindings/high_binds/world_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/world_binds.cpp @@ -15,9 +15,24 @@ namespace e2d::bindings::high sol::no_constructor, "instantiate", sol::overload( + [](world& w) -> gobject { + return w.instantiate(); + }, + [](world& w, const t2f& transform) -> gobject { + return w.instantiate(transform); + }, + [](world& w, const node_iptr& parent) -> gobject { + return w.instantiate(parent); + }, + [](world& w, const node_iptr& parent, const t2f& transform) -> gobject { + return w.instantiate(parent, transform); + }, [](world& w, const prefab& prefab) -> gobject { return w.instantiate(prefab); }, + [](world& w, const prefab& prefab, const t2f& transform) -> gobject { + return w.instantiate(prefab, transform); + }, [](world& w, const prefab& prefab, const node_iptr& parent) -> gobject { return w.instantiate(prefab, parent); }, diff --git a/sources/enduro2d/high/components/camera.cpp b/sources/enduro2d/high/components/camera.cpp index 270a46d1..73dab1b7 100644 --- a/sources/enduro2d/high/components/camera.cpp +++ b/sources/enduro2d/high/components/camera.cpp @@ -185,25 +185,25 @@ namespace e2d const char* component_inspector::title = ICON_FA_VIDEO " camera"; void component_inspector::operator()(gcomponent& c) const { - if ( bool input = c.owner().component().exists(); + if ( bool input = c.component().exists(); ImGui::Checkbox("input", &input) ) { if ( input ) { - c.owner().component().ensure(); + c.component().ensure(); } else { - c.owner().component().remove(); + c.component().remove(); } } ImGui::SameLine(); - if ( bool gizmos = c.owner().component().exists(); + if ( bool gizmos = c.component().exists(); ImGui::Checkbox("gizmos", &gizmos) ) { if ( gizmos ) { - c.owner().component().ensure(); + c.component().ensure(); } else { - c.owner().component().remove(); + c.component().remove(); } } diff --git a/sources/enduro2d/high/components/label.cpp b/sources/enduro2d/high/components/label.cpp index a18bde02..9248deae 100644 --- a/sources/enduro2d/high/components/label.cpp +++ b/sources/enduro2d/high/components/label.cpp @@ -201,7 +201,7 @@ namespace e2d const char* component_inspector