Gtkmm3 : wait for css transition to finish

137 views Asked by At

My question does not concern JavaScript, but C++ :

In gtkmm3, application appearance is managed by CSS, so transitions can be set like that :

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")

With this code, the user sees only the "yellow" state of the button, and not the previous ones, because transitions are skipped. How to display all the color changes one after the other?

EDIT :

My application is a game, where buttons are colored accordingly to their label. This label can change multiple times very closely, and I want the user to see these changes, so, to see the transitions between each state. So, it is not just a flash (my example was not perfect, if you want the whole code of the application, you can get it here).

EDIT 2:

I modified the code above and the following sentences to explain my problem better.

1

There are 1 answers

4
ptomato On BEST ANSWER

Are you trying to make the button flash purple briefly? If so, you can set a timeout with GLib::SignalTimeout for the correct amount of time that you want the button to flash for.