Set CSS properties programmatically

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Set CSS properties programmatically

Felipe Borges
Hi,

I have been looking for a clean way of updating my widget's css
properties programmatically at runtime.

Basically I have a css animation which gets its properties from
variables in my C code.

The current (working) approach I came up with is to benefit from the
cascade and generate a whole new css definition for the animation
every time my variable changes and use GtkStyleProvider.load_from_css
(my_new_animation_css_spec). For this to work I need to set the
"animation-name" to have a new and unique value, overwriting the
previous one. This doesn't sound efficient at all.

My desire is to get the "animation" property of my class, and be able
to update only what changes in it. It can already be done for some
properties via GtkStyleContext.get_property.

All in all, is there a better way of doing this? Will there ever be?

Thanks,
Felipe.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Set CSS properties programmatically

Emmanuele Bassi
Hi Felipe;

You probably wanted to send this email to gtk-devel-list, not
gtk-app-devel-list.

On Sat, 25 Nov 2017 at 12:41, Felipe Borges <[hidden email]>
wrote:

> Hi,
>
> I have been looking for a clean way of updating my widget's css
> properties programmatically at runtime.
>
> Basically I have a css animation which gets its properties from
> variables in my C code.
>
> The current (working) approach I came up with is to benefit from the
> cascade and generate a whole new css definition for the animation
> every time my variable changes and use GtkStyleProvider.load_from_css
> (my_new_animation_css_spec). For this to work I need to set the
> "animation-name" to have a new and unique value, overwriting the
> previous one. This doesn't sound efficient at all.
>
> My desire is to get the "animation" property of my class, and be able
> to update only what changes in it. It can already be done for some
> properties via GtkStyleContext.get_property.
>

How would you even do this? You would need to read the current style state
and then resubmit it as a whole, because you cannot know how changing your
style for your animation will end up in your computed style.

All in all, is there a better way of doing this? Will there ever be?
>

Not for gtk3, and I’m pretty sure even for gtk4 it would be kind of weird.

Ciao,
 Emmanuele.
--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
'-'
Reply | Threaded
Open this post in threaded view
|

Re: Set CSS properties programmatically

'-'
In reply to this post by Felipe Borges
Hello,

Can you please share a link to your current approach? Doesn't sound
efficient but makes sense. I'd like to run the code and see the
animation in action.

On 2017-11-25 14:41, Felipe Borges wrote:

> Hi,
>
> I have been looking for a clean way of updating my widget's css
> properties programmatically at runtime.
>
> Basically I have a css animation which gets its properties from
> variables in my C code.
>
> The current (working) approach I came up with is to benefit from the
> cascade and generate a whole new css definition for the animation
> every time my variable changes and use GtkStyleProvider.load_from_css
> (my_new_animation_css_spec). For this to work I need to set the
> "animation-name" to have a new and unique value, overwriting the
> previous one. This doesn't sound efficient at all.
>
> My desire is to get the "animation" property of my class, and be able
> to update only what changes in it. It can already be done for some
> properties via GtkStyleContext.get_property.
>
> All in all, is there a better way of doing this? Will there ever be?
>
> Thanks,
> Felipe.
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Set CSS properties programmatically

Felipe Borges
In reply to this post by Emmanuele Bassi
Hi,

On Sat, Nov 25, 2017 at 2:38 PM, Emmanuele Bassi <[hidden email]> wrote:
> Hi Felipe;
>
> You probably wanted to send this email to gtk-devel-list, not
> gtk-app-devel-list.

urgh, sorry!

> How would you even do this? You would need to read the current style state
> and then resubmit it as a whole, because you cannot know how changing your
> style for your animation will end up in your computed style.
>
>> All in all, is there a better way of doing this? Will there ever be?
>
>
> Not for gtk3, and I’m pretty sure even for gtk4 it would be kind of weird.

Sure. My understanding is that this would be out of the scope of the
toolkit. But maybe there was an API for that. Thanks for clarifying
it!

>
> Ciao,
>  Emmanuele.
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Set CSS properties programmatically

Felipe Borges
In reply to this post by '-'
Hello,

On Sat, Nov 25, 2017 at 5:03 PM, - <[hidden email]> wrote:
> Hello,
>
> Can you please share a link to your current approach? Doesn't sound
> efficient but makes sense. I'd like to run the code and see the animation in
> action.

Yes. It is being used in GNOME Usage performance panel
https://gitlab.gnome.org/GNOME/gnome-usage
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list