touchable dummy bubbling and capturing flags

This commit is contained in:
2020-02-02 08:55:44 +07:00
parent 2282ef6477
commit 50eb779685
4 changed files with 100 additions and 3 deletions

View File

@@ -16,6 +16,21 @@ namespace e2d
class under_mouse final {};
public:
touchable() = default;
touchable& bubbling(bool value) noexcept;
touchable& capturing(bool value) noexcept;
[[nodiscard]] bool bubbling() const noexcept;
[[nodiscard]] bool capturing() const noexcept;
private:
enum flag_masks : u32 {
fm_bubbling = 1u << 0,
fm_capturing = 1u << 1,
};
private:
u32 flags_{
fm_bubbling |
fm_capturing};
};
}
@@ -74,3 +89,28 @@ namespace e2d
void operator()(gcomponent<touchable>& c) const;
};
}
namespace e2d
{
inline touchable& touchable::bubbling(bool value) noexcept {
if ( value != bubbling() ) {
math::flip_flags_inplace(flags_, fm_bubbling);
}
return *this;
}
inline touchable& touchable::capturing(bool value) noexcept {
if ( value != capturing() ) {
math::flip_flags_inplace(flags_, fm_capturing);
}
return *this;
}
inline bool touchable::bubbling() const noexcept {
return math::check_any_flags(flags_, fm_bubbling);
}
inline bool touchable::capturing() const noexcept {
return math::check_any_flags(flags_, fm_capturing);
}
}

View File

@@ -10,7 +10,13 @@ local touchable = {
touched = false,
---@type boolean
under_mouse = false
under_mouse = false,
---@type boolean
bubbling = true,
---@type boolean
capturing = true
}
---@overload fun(self: touchable)

View File

@@ -74,7 +74,23 @@ namespace e2d::bindings::high
c.owner().component<touchable::under_mouse>().remove();
}
}
)
),
"bubbling", sol::property(
[](const gcomponent<touchable>& c) -> bool {
return c->bubbling();
},
[](gcomponent<touchable>& c, bool v){
c->bubbling(v);
}),
"capturing", sol::property(
[](const gcomponent<touchable>& c) -> bool {
return c->capturing();
},
[](gcomponent<touchable>& c, bool v){
c->capturing(v);
})
);
}
}

View File

@@ -13,6 +13,8 @@ namespace e2d
"required" : [],
"additionalProperties" : false,
"properties" : {
"bubbling" : { "type" : "boolean" },
"capturing" : { "type" : "boolean" }
}
})json";
@@ -20,7 +22,24 @@ namespace e2d
touchable& component,
const fill_context& ctx) const
{
E2D_UNUSED(component, ctx);
if ( ctx.root.HasMember("bubbling") ) {
bool bubbling = component.bubbling();
if ( !json_utils::try_parse_value(ctx.root["bubbling"], bubbling) ) {
the<debug>().error("TOUCHABLE: Incorrect formatting of 'bubbling' property");
return false;
}
component.bubbling(bubbling);
}
if ( ctx.root.HasMember("capturing") ) {
bool capturing = component.capturing();
if ( !json_utils::try_parse_value(ctx.root["capturing"], capturing) ) {
the<debug>().error("TOUCHABLE: Incorrect formatting of 'capturing' property");
return false;
}
component.capturing(capturing);
}
return true;
}
@@ -100,6 +119,8 @@ namespace e2d
}
}
ImGui::SameLine();
if ( bool under_mouse = c.owner().component<touchable::under_mouse>().exists();
ImGui::Checkbox("under_mouse", &under_mouse) )
{
@@ -109,5 +130,19 @@ namespace e2d
c.owner().component<touchable::under_mouse>().remove();
}
}
if ( bool bubbling = c->bubbling();
ImGui::Checkbox("bubbling", &bubbling) )
{
c->bubbling(bubbling);
}
ImGui::SameLine();
if ( bool capturing = c->capturing();
ImGui::Checkbox("capturing", &capturing) )
{
c->capturing(capturing);
}
}
}