mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
layout was_moved flag
This commit is contained in:
@@ -13,6 +13,7 @@ namespace e2d
|
||||
class layout final {
|
||||
public:
|
||||
class dirty final {};
|
||||
class was_moved final {};
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(modes, u8,
|
||||
(horizontal)
|
||||
@@ -95,6 +96,20 @@ namespace e2d
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
class factory_loader<layout::was_moved> final : factory_loader<> {
|
||||
public:
|
||||
static const char* schema_source;
|
||||
|
||||
bool operator()(
|
||||
layout::was_moved& component,
|
||||
const fill_context& ctx) const;
|
||||
|
||||
bool operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
@@ -172,6 +187,10 @@ namespace e2d::layouts
|
||||
gcomponent<layout> unmark_dirty(gcomponent<layout> self);
|
||||
bool is_dirty(const const_gcomponent<layout>& self) noexcept;
|
||||
|
||||
gcomponent<layout> mark_was_moved(gcomponent<layout> self);
|
||||
gcomponent<layout> unmark_was_moved(gcomponent<layout> self);
|
||||
bool is_was_moved(const const_gcomponent<layout>& self) noexcept;
|
||||
|
||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value);
|
||||
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value);
|
||||
gcomponent<layout> change_valign(gcomponent<layout> self, layout::valigns value);
|
||||
|
||||
@@ -9,6 +9,9 @@ local layout = {
|
||||
---@type boolean
|
||||
dirty = false,
|
||||
|
||||
---@type boolean
|
||||
was_moved = false,
|
||||
|
||||
---@type layout_modes
|
||||
mode = layout.modes.horizontal,
|
||||
|
||||
|
||||
@@ -67,6 +67,19 @@ namespace e2d::bindings::high
|
||||
}
|
||||
),
|
||||
|
||||
"was_moved", sol::property(
|
||||
[](const gcomponent<layout>& c) -> bool {
|
||||
return layouts::is_was_moved(c);
|
||||
},
|
||||
[](gcomponent<layout>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
layouts::mark_was_moved(c);
|
||||
} else {
|
||||
layouts::unmark_was_moved(c);
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"mode", sol::property(
|
||||
[](const gcomponent<layout>& c) -> layout::modes {
|
||||
return c->mode();
|
||||
|
||||
@@ -201,6 +201,18 @@ namespace e2d
|
||||
const char* component_inspector<label>::title = ICON_FA_PARAGRAPH " label";
|
||||
|
||||
void component_inspector<label>::operator()(gcomponent<label>& c) const {
|
||||
if ( bool dirty = c.owner().component<label::dirty>().exists();
|
||||
ImGui::Checkbox("dirty", &dirty) )
|
||||
{
|
||||
if ( dirty ) {
|
||||
labels::mark_dirty(c);
|
||||
} else {
|
||||
labels::unmark_dirty(c);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if ( str text = c->text();
|
||||
ImGui::InputTextMultiline("text", &text) )
|
||||
{
|
||||
|
||||
@@ -149,6 +149,32 @@ namespace e2d
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<layout::was_moved>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<layout::was_moved>::operator()(
|
||||
layout::was_moved& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<layout::was_moved>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* component_inspector<layout>::title = ICON_FA_BARS " layout";
|
||||
@@ -164,6 +190,20 @@ namespace e2d
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if ( bool was_moved = c.owner().component<layout::was_moved>().exists();
|
||||
ImGui::Checkbox("was_moved", &was_moved) )
|
||||
{
|
||||
if ( was_moved ) {
|
||||
layouts::mark_was_moved(c);
|
||||
} else {
|
||||
layouts::unmark_was_moved(c);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if ( layout::modes mode = c->mode();
|
||||
imgui_utils::show_enum_combo_box("mode", &mode) )
|
||||
{
|
||||
@@ -233,9 +273,6 @@ namespace e2d::layouts
|
||||
gcomponent<layout> mark_dirty(gcomponent<layout> self) {
|
||||
if ( self ) {
|
||||
self.owner().component<layout::dirty>().ensure();
|
||||
if ( gcomponent<layout> parent = find_parent_layout(self) ) {
|
||||
parent.owner().component<layout::dirty>().ensure();
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -251,6 +288,24 @@ namespace e2d::layouts
|
||||
return self.owner().component<layout::dirty>().exists();
|
||||
}
|
||||
|
||||
gcomponent<layout> mark_was_moved(gcomponent<layout> self) {
|
||||
if ( self ) {
|
||||
self.owner().component<layout::was_moved>().ensure();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
gcomponent<layout> unmark_was_moved(gcomponent<layout> self) {
|
||||
if ( self ) {
|
||||
self.owner().component<layout::was_moved>().remove();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
bool is_was_moved(const const_gcomponent<layout>& self) noexcept {
|
||||
return self.owner().component<layout::was_moved>().exists();
|
||||
}
|
||||
|
||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value) {
|
||||
if ( self ) {
|
||||
self->mode(value);
|
||||
@@ -276,6 +331,7 @@ namespace e2d::layouts
|
||||
if ( self ) {
|
||||
self->size(value);
|
||||
}
|
||||
mark_dirty(find_parent_layout(self));
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
@@ -283,6 +339,7 @@ namespace e2d::layouts
|
||||
if ( self ) {
|
||||
self->margin(value);
|
||||
}
|
||||
mark_dirty(find_parent_layout(self));
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
@@ -290,6 +347,7 @@ namespace e2d::layouts
|
||||
if ( self ) {
|
||||
self->padding(value);
|
||||
}
|
||||
mark_dirty(find_parent_layout(self));
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ namespace e2d
|
||||
.register_component<label::dirty>("label.dirty")
|
||||
.register_component<layout>("layout")
|
||||
.register_component<layout::dirty>("layout.dirty")
|
||||
.register_component<layout::was_moved>("layout.was_moved")
|
||||
.register_component<model_renderer>("model_renderer")
|
||||
.register_component<named>("named")
|
||||
.register_component<renderer>("renderer")
|
||||
@@ -225,6 +226,7 @@ namespace e2d
|
||||
//.register_component<label::dirty>("label.dirty")
|
||||
.register_component<layout>("layout")
|
||||
//.register_component<layout::dirty>("layout.dirty")
|
||||
//.register_component<layout::was_moved>("layout.was_moved")
|
||||
.register_component<model_renderer>("model_renderer")
|
||||
.register_component<named>("named")
|
||||
.register_component<renderer>("renderer")
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace
|
||||
{
|
||||
using namespace e2d;
|
||||
|
||||
void update_yogo_node(const layout& l, const actor& a, const yogo_node& yn) {
|
||||
void update_yogo_node(const yogo_node& yn, const layout& l, const actor& a) {
|
||||
switch ( l.mode() ) {
|
||||
case layout::modes::horizontal:
|
||||
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionRow);
|
||||
@@ -144,8 +144,17 @@ namespace
|
||||
using namespace e2d;
|
||||
|
||||
void process_yogo_nodes(ecs::registry& owner) {
|
||||
ecsex::remove_all_components<yogo_node>(
|
||||
ecsex::remove_all_components_with_disposer<yogo_node>(
|
||||
owner,
|
||||
[](ecs::entity e, const yogo_node&){
|
||||
if ( const actor* a = e.find_component<actor>();
|
||||
a && a->node() && a->node()->owner() )
|
||||
{
|
||||
gcomponent<layout> l{a->node()->owner()};
|
||||
layouts::mark_dirty(l);
|
||||
layouts::mark_dirty(layouts::find_parent_layout(l));
|
||||
}
|
||||
},
|
||||
!ecs::exists_all<
|
||||
actor,
|
||||
layout>() ||
|
||||
@@ -159,20 +168,29 @@ namespace
|
||||
const actor& a)
|
||||
{
|
||||
e.ensure_component<yogo_node>();
|
||||
}, !ecs::exists_any<
|
||||
if ( a.node() && a.node()->owner() ) {
|
||||
gcomponent<layout> l{a.node()->owner()};
|
||||
layouts::mark_dirty(l);
|
||||
layouts::mark_dirty(layouts::find_parent_layout(l));
|
||||
}
|
||||
},
|
||||
!ecs::exists_any<
|
||||
yogo_node,
|
||||
disabled<actor>,
|
||||
disabled<layout>>());
|
||||
}
|
||||
|
||||
void process_dirty_layouts(ecs::registry& owner) {
|
||||
owner.for_joined_components<layout::dirty, layout, actor, yogo_node>([](
|
||||
owner.remove_all_components<layout::was_moved>();
|
||||
|
||||
owner.for_joined_components<layout::dirty, yogo_node, layout, actor>([](
|
||||
const ecs::const_entity&,
|
||||
const layout::dirty&,
|
||||
const layout& l,
|
||||
const actor& a,
|
||||
const yogo_node& yn)
|
||||
const yogo_node& root_yn,
|
||||
const layout& root_l,
|
||||
const actor& root_a)
|
||||
{
|
||||
update_yogo_node(l, a, yn);
|
||||
update_yogo_node(root_yn, root_l, root_a);
|
||||
});
|
||||
|
||||
owner.for_joined_components<layout::dirty, yogo_node, actor>([](
|
||||
@@ -214,6 +232,8 @@ namespace
|
||||
item_a->node()->translation(v2f(
|
||||
YGNodeLayoutGetLeft(item_yn->as_item.get()),
|
||||
YGNodeLayoutGetTop(item_yn->as_item.get())));
|
||||
layouts::mark_was_moved(
|
||||
item.owner().component<layout>());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user