简体   繁体   English

具有嵌套actor的cluttermm鼠标事件

[英]cluttermm mouse events with nested actors

I have the following code snippet using cluttermm 1.24: 我有以下使用cluttermm 1.24的代码片段:

#include <cluttermm.h>

int main(int argc, char *argv[]){
    Clutter::init(argc, argv);

    auto stage = Clutter::Stage::create();
    stage->set_size(1280, 720);

    //create a parent actor
    auto parent = Clutter::Actor::create();
    parent->set_size(1240, 720);
    parent->set_margins(20, 20, 20, 20);

    //create children
    for(unsigned i=0; i<84; i++){
        auto child = Clutter::Actor::create();
        child->set_name(std::to_string(i).c_str());
        child->set_size(80, 80);
        child->set_background_color(Clutter::Color(80));
        child->set_reactive(true);
        child->signal_button_press_event().connect([child](Clutter::ButtonEvent* evt){
            g_print("Child: %s", child->get_name().c_str());
            return true;
        });

        parent->add_child(child);
    }

    auto layout = Clutter::FlowLayout::create(Clutter::FlowOrientation::FLOW_HORIZONTAL);
    layout->set_column_spacing(20);
    layout->set_row_spacing(20);
    parent->set_layout_manager(layout);
    stage->add_child(parent);

    stage->show();

    Clutter::main();
}

Child actors should print "Child:XX" when clicked on. 子演员点击时应打印“ Child:XX”。 But they do not react at all. 但是他们根本没有反应。 When changing the parent type to the (deprecated) Clutter::Group then the click behaviour is as expected but the FlowLayout does not work anymore. 将父类型更改为(不建议使用)Clutter :: Group时,单击行为符合预期,但FlowLayout不再起作用。 What am I missing here? 我在这里想念什么? Do I need to enable something on the parent actor to enable container functionality? 我需要在父角色上启用某些功能以启用容器功能吗?

EDIT: Replacing the parent actor with c code behaves as expected: 编辑:用C代码替换父actor的行为符合预期:

auto parent = clutter_actor_new ();
clutter_actor_set_layout_manager (parent, CLUTTER_LAYOUT_MANAGER(layout->gobj()));
clutter_actor_set_size (parent, 1240, 720);
clutter_actor_add_child (CLUTTER_ACTOR(stage->gobj()), parent);
...
clutter_actor_add_child (parent, child->gobj());

I found the problem. 我发现了问题。 Cluttermm wrapped the deprecated "pick" signal. Cluttermm包装了已弃用的“拾取”信号。 Apparently this prevented the button press signal from propagating. 显然,这阻止了按钮按下信号的传播。 So I've forked cluttermm and changed the bindings. 因此,我分叉了cluttermm并更改了绑定。

See this commit: https://github.com/underdoeg/cluttermm/commit/0e40c9c673c2415ab1b4eb90dd1ebcd95a515810 看到这个提交: https : //github.com/underdoeg/cluttermm/commit/0e40c9c673c2415ab1b4eb90dd1ebcd95a515810

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM