1 #include "info.hpp" 2 Info()3Info::Info() { 4 set_hexpand(false); 5 set_halign(Gtk::Align::ALIGN_END); 6 7 auto content_area = dynamic_cast<Gtk::Container *>(get_content_area()); 8 label.set_max_width_chars(40); 9 label.set_line_wrap(true); 10 content_area->add(label); 11 12 get_style_context()->add_class("juci_info"); 13 14 //Workaround from https://bugzilla.gnome.org/show_bug.cgi?id=710888 15 //Issue described at the same issue report 16 //TODO: remove later 17 auto revealer = gtk_widget_get_template_child(GTK_WIDGET(gobj()), GTK_TYPE_INFO_BAR, "revealer"); 18 if(revealer) { 19 gtk_revealer_set_transition_type(GTK_REVEALER(revealer), GTK_REVEALER_TRANSITION_TYPE_NONE); 20 gtk_revealer_set_transition_duration(GTK_REVEALER(revealer), 0); 21 } 22 } 23 print(const std::string & text)24void Info::print(const std::string &text) { 25 timeout_connection.disconnect(); 26 //Timeout based on https://en.wikipedia.org/wiki/Words_per_minute 27 //(average_words_per_minute*average_letters_per_word)/60 => (228*4.5)/60 = 17.1 28 double timeout = 1000.0 * std::max(3.0, 1.0 + text.size() / 17.1); 29 timeout_connection = Glib::signal_timeout().connect( 30 [this]() { 31 hide(); 32 return false; 33 }, 34 timeout); 35 36 label.set_text(text); 37 show(); 38 } 39