mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-13 15:48:11 +07:00
additional dirty flag helper function for layouts
This commit is contained in:
@@ -182,6 +182,9 @@ namespace e2d
|
||||
namespace e2d::layouts
|
||||
{
|
||||
gcomponent<layout> mark_dirty(gcomponent<layout> self);
|
||||
gcomponent<layout> unmark_dirty(gcomponent<layout> self);
|
||||
bool is_dirty(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);
|
||||
@@ -191,5 +194,10 @@ namespace e2d::layouts
|
||||
namespace e2d::layout_items
|
||||
{
|
||||
gcomponent<layout_item> mark_dirty(gcomponent<layout_item> self);
|
||||
gcomponent<layout_item> unmark_dirty(gcomponent<layout_item> self);
|
||||
bool is_dirty(const const_gcomponent<layout_item>& self) noexcept;
|
||||
|
||||
gcomponent<layout_item> change_size(gcomponent<layout_item> self, const v2f& value);
|
||||
|
||||
gcomponent<layout> find_parent_layout(const_gcomponent<layout_item> self) noexcept;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,9 @@ local layout_item = {
|
||||
---@type boolean
|
||||
disabled = false,
|
||||
|
||||
---@type boolean
|
||||
dirty = false,
|
||||
|
||||
---@type v2f
|
||||
size = v2f.unit()
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ namespace e2d::bindings::high
|
||||
|
||||
"dirty", sol::property(
|
||||
[](const gcomponent<layout>& c) -> bool {
|
||||
return c.owner().component<layout::dirty>().exists();
|
||||
return layouts::is_dirty(c);
|
||||
},
|
||||
[](gcomponent<layout>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.owner().component<layout::dirty>().ensure();
|
||||
layouts::mark_dirty(c);
|
||||
} else {
|
||||
c.owner().component<layout::dirty>().remove();
|
||||
layouts::unmark_dirty(c);
|
||||
}
|
||||
}
|
||||
),
|
||||
@@ -167,6 +167,19 @@ namespace e2d::bindings::high
|
||||
}
|
||||
),
|
||||
|
||||
"dirty", sol::property(
|
||||
[](const gcomponent<layout_item>& c) -> bool {
|
||||
return layout_items::is_dirty(c);
|
||||
},
|
||||
[](gcomponent<layout_item>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
layout_items::mark_dirty(c);
|
||||
} else {
|
||||
layout_items::unmark_dirty(c);
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"size", sol::property(
|
||||
[](const gcomponent<layout_item>& c) -> v2f {
|
||||
return c->size();
|
||||
|
||||
@@ -224,6 +224,17 @@ namespace e2d::layouts
|
||||
return self;
|
||||
}
|
||||
|
||||
gcomponent<layout> unmark_dirty(gcomponent<layout> self) {
|
||||
if ( self ) {
|
||||
self.owner().component<layout::dirty>().remove();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
bool is_dirty(const const_gcomponent<layout>& self) noexcept {
|
||||
return self.owner().component<layout::dirty>().exists();
|
||||
}
|
||||
|
||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value) {
|
||||
if ( self ) {
|
||||
self->mode(value);
|
||||
@@ -256,24 +267,30 @@ namespace e2d::layouts
|
||||
namespace e2d::layout_items
|
||||
{
|
||||
gcomponent<layout_item> mark_dirty(gcomponent<layout_item> self) {
|
||||
gcomponent<actor> self_actor = self.owner().component<actor>();
|
||||
if ( !self_actor ) {
|
||||
return self;
|
||||
}
|
||||
|
||||
gcomponent<layout> parent_layout = nodes::find_component_from_parents<layout>(self_actor->node());
|
||||
if ( !parent_layout ) {
|
||||
return self;
|
||||
}
|
||||
|
||||
layouts::mark_dirty(parent_layout);
|
||||
layouts::mark_dirty(find_parent_layout(self));
|
||||
return self;
|
||||
}
|
||||
|
||||
gcomponent<layout_item> unmark_dirty(gcomponent<layout_item> self) {
|
||||
layouts::unmark_dirty(find_parent_layout(self));
|
||||
return self;
|
||||
}
|
||||
|
||||
bool is_dirty(const const_gcomponent<layout_item>& self) noexcept {
|
||||
return layouts::is_dirty(find_parent_layout(self));
|
||||
}
|
||||
|
||||
gcomponent<layout_item> change_size(gcomponent<layout_item> self, const v2f& value) {
|
||||
if ( self ) {
|
||||
self->size(value);
|
||||
}
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
gcomponent<layout> find_parent_layout(const_gcomponent<layout_item> self) noexcept {
|
||||
const_gcomponent<actor> self_actor = self.owner().component<actor>();
|
||||
return self_actor
|
||||
? nodes::find_component_from_parents<layout>(self_actor->node())
|
||||
: gcomponent<layout>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user