css - GtkStyleProvider - providing own implementation -


i trying provide own implementation of gtkstyleprovider, since "normal" css provider lot of work , processing use in case.

i want able provide widget styling based on internal state, , in css, i'd have write out huge string of css (translating things pango.fontdescriptions css-style declarations) based on change in state, , feed gktcssprovider process back gtk-land. compare custom provider, signal (somehow) client widgets should ask style , hand out new styling based directly on state.

it seems gtkstyleprovider way achieve - can make provider returns styling based on state, , add style provider relevant gtkstylecontext. (c) interface is

// deprecated - return null in new code gtkiconfactory *      gtk_style_provider_get_icon_factory (                                    gtkstyleprovider *provider,                                    gtkwidgetpath *path);)   // deprecated - return null in new code gtkstyleproperties *  gtk_style_provider_get_style (                                    gtkstyleprovider *provider,                                    gtkwidgetpath *path)) // return true if property found , has value, else false gboolean              gtk_style_provider_get_style_property (                                    gtkstyleprovider *provider,                                    gtkwidgetpath *path,                                    gtkstateflags state,                                    gparamspec *pspec,                                    gvalue *value); 

to end, wrote this, expected work, nothing, should report property not set:

# compile with: valac styleprov.vala --pkg gtk+-3.0 --pkg gdk-3.0 using gtk; using gdk;  public class derivedstyleprovider : object, gtk.styleprovider {     public unowned gtk.iconfactory get_icon_factory (gtk.widgetpath path)     {         return (gtk.iconfactory) null; // evil cast work around buggy declaration in vapi file     }      public gtk.styleproperties get_style (gtk.widgetpath path)     {         return (gtk.styleproperties) null; // evil cast work around buggy declaration in vapi file     }      public bool get_style_property (gtk.widgetpath path,                 gtk.stateflags state,                 glib.paramspec pspec,                 out glib.value value)     {         stdout.printf("get_style_property");         // compiler happiness testing         value = value (typeof (string));         return false; //todo     } }  public class styleprov.mainwindow : gtk.window {     construct {         derivedstyleprovider styleprovider = new derivedstyleprovider();          // work         //gtk.cssprovider styleprovider = new gtk.cssprovider();         //styleprovider.load_from_data("*{ background-color: #ff0000; }");          stylecontext.add_provider_for_screen(this.get_screen(),                                              styleprovider,                                              gtk.style_provider_priority_user);     } }  class styleprov.main : glib.object {         public void run() {             styleprov.mainwindow mainwindow = new styleprov.mainwindow();             mainwindow.show_all();         }          public static int main (string[] args) {             gtk.init (ref args);              main app = new main();             app.run();             gtk.main ();             return 0;         } } 

this compiles ok, , runs up, spews warnings:

(styleprov:32365): glib-gobject-warning **: gsignal.c:2523: signal '-gtk-private-changed' invalid instance '0x1154ac0' of type 'derivedstyleprovider' (styleprov:32365): gtk-warning **: (gtkstylecascade.c:256):gtk_style_cascade_lookup: code should not reached (styleprov:32365): gtk-warning **: (gtkstylecascade.c:256):gtk_style_cascade_lookup: code should not reached ...several of these.... 

warnings notwithstanding, get_style_property() method never appears called, , no custom styling can provided.

replacing derivedstyleprovider "normal" css provider works fine.

what right way implement custom gtkstyleprovider (in language)?

looking @ implementation of gtkcssprovider, appears use not gtkstyleproviderinterface gtkstyleproviderprivateinterface, , lot of complex custom bypassing (apparently efficiency reasons, according friendly folks on gtk+ irc channel), decided use normal css method , deal constructing css hand string.

the mechanism is:

  • a gtkcssprovider created
  • provider attached relevant style context gtk_style_context_add_provider() (or global gtk_style_context_add_provider_for_screen())
  • data manager sends signal data has changed
  • this caught data->css translator generates new css string relevant gtkcssprovider
  • this string fed in existing provider gtk_css_provider_load_from_data().
  • any ui changes resulting update happen automatically

i suppose problem don't understand how gtk+ works underneath. if treat css the canonical style "oracle" ui, suppose updating css is correct approach, , i'm expecting low-level access perhaps technically possible, not "correct" in gtk+ way.

this low-level access have grown expect other frameworks (only) have direct control on styling of things "background colour" of widgets, , there's no css layer abstract it, not how works in gtk+ (any more).

at least, that's how understand it!


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -