Gtkmm3:等待 css 转换完成

Gtkmm3 : wait for css transition to finish

我的问题不涉及 JavaScript,而是 C++ :

在 gtkmm3 中,应用程序外观由 CSS 管理,因此可以这样设置转换:

theme.css :

.purple {
transition: 500ms linear;
background-image: -gtk-gradient (radial,
    center center, 0,
    center center, 1,
    from (#FFB2E8),
    to (#80005A));
 }

main.cc :

   // Create and define the StyleContext
   CssProvider = Gtk::CssProvider::create();
   CssProvider->load_from_path (Glib::build_filename (UI_DIR, "theme.css"));
   Glib::RefPtr<Gtk::StyleContext> ButtonContext = button->get_style_context ();
   ButtonContext->add_provider (CssProvider,
                                GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
   // Assign new color
   ButtonContext->add_class ("purple");
   // Assign an intermediate color
   ButtonContext->remove_class ("purple");
   ButtonContexy->add_class ("green");
   // To something
   // ... ...
   // Change the color again
   ButtonContext->remove_class ("green");
   ButtonContext->add_class ("yellow")

使用此代码,用户只会看到按钮的 "yellow" 状态,而不会看到之前的状态,因为转换已被跳过。 如何依次显示所有颜色变化?

编辑:

我的应用程序是一个游戏,其中按钮的颜色根据其标签而定。这个标签可以非常接近地改变多次,我希望用户看到这些变化,所以,看到每个状态之间的转换。所以,它不仅仅是一个flash(我的例子并不完美,如果你想要应用程序的整个代码,你可以得到它here)。

编辑 2:

我修改了上面的代码和下面的句子以更好地解释我的问题。

您想让按钮短暂闪烁紫色吗?如果是这样,您可以使用 GLib::SignalTimeout 为您希望按钮闪烁的正确时间设置超时。