mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
touchable dummy bubbling and capturing flags
This commit is contained in:
@@ -16,6 +16,21 @@ namespace e2d
|
|||||||
class under_mouse final {};
|
class under_mouse final {};
|
||||||
public:
|
public:
|
||||||
touchable() = default;
|
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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,13 @@ local touchable = {
|
|||||||
touched = false,
|
touched = false,
|
||||||
|
|
||||||
---@type boolean
|
---@type boolean
|
||||||
under_mouse = false
|
under_mouse = false,
|
||||||
|
|
||||||
|
---@type boolean
|
||||||
|
bubbling = true,
|
||||||
|
|
||||||
|
---@type boolean
|
||||||
|
capturing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
---@overload fun(self: touchable)
|
---@overload fun(self: touchable)
|
||||||
|
|||||||
@@ -74,7 +74,23 @@ namespace e2d::bindings::high
|
|||||||
c.owner().component<touchable::under_mouse>().remove();
|
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);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace e2d
|
|||||||
"required" : [],
|
"required" : [],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {
|
"properties" : {
|
||||||
|
"bubbling" : { "type" : "boolean" },
|
||||||
|
"capturing" : { "type" : "boolean" }
|
||||||
}
|
}
|
||||||
})json";
|
})json";
|
||||||
|
|
||||||
@@ -20,7 +22,24 @@ namespace e2d
|
|||||||
touchable& component,
|
touchable& component,
|
||||||
const fill_context& ctx) const
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +119,8 @@ namespace e2d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
if ( bool under_mouse = c.owner().component<touchable::under_mouse>().exists();
|
if ( bool under_mouse = c.owner().component<touchable::under_mouse>().exists();
|
||||||
ImGui::Checkbox("under_mouse", &under_mouse) )
|
ImGui::Checkbox("under_mouse", &under_mouse) )
|
||||||
{
|
{
|
||||||
@@ -109,5 +130,19 @@ namespace e2d
|
|||||||
c.owner().component<touchable::under_mouse>().remove();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user