styles and theme colors

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

styles and theme colors

#1 Post by korova » Sun Jul 05, 2015 12:18 pm

In the options.rpy file, the user defines several colors for the theme used by the game.

Let's imagine that I want to define new styles, using the same colors as the theme colors.

How can I access the variables where theme colors are stored ?

like, for example

Code: Select all

style my_style:
    color the_widget_text_color_of_the_theme

Where is the widget_text color stored, and how to access it ?

I don't want to copy paste the "#" string, so that if I change the theme colors, the colors of my new styles change too.

Thanks for your help.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: styles and theme colors

#2 Post by nyaatrap » Sun Jul 05, 2015 7:59 pm

Theme is a function that initializes styles, so it isn't stored.

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: styles and theme colors

#3 Post by korova » Mon Jul 06, 2015 2:50 am

Fine, but the values themselves must be stored "somewhere", because the writing and widget colors change according to theme...

I tried to use the styles values (I got them from the style inspector), but this doesn't work.

For example, I want my new style to have the same text color as the selected button text color.

Here is what I get from style inspector
styleInspector.jpg
Style inspector
So, style button_text has a "selected_color" attribute, according to style inspector

But if I try to use this attribute when defining my style like this

Code: Select all

style my_style:
    color style.button_text.selected_color
I get this error :

Code: Select all

While running game code:
  File "game/screens.rpy", line 256, in script
    style accueil_hover is button_text:
  File "game/screens.rpy", line 257, in <module>
    color style.button_text.selected_color #style.default.selected_color
AttributeError: 'renpy.styledata.styleclass.Style' object has no attribute 'selected_color'
Suggestions ?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: styles and theme colors

#4 Post by nyaatrap » Mon Jul 06, 2015 3:34 am

This works.

Code: Select all

style.selected_text_button.color
Though I don't recommend to access style itself to initialize styles. It's more safe to create a new variable for it.

Code: Select all

init -3 python:
    WIDGET_COLOR = "#fff"
style button_text:
     color WIDGET_COLOR

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: styles and theme colors

#5 Post by korova » Mon Jul 06, 2015 5:16 am

nyaatrap wrote:This works.

Code: Select all

style.selected_text_button.color
Nope.

No error, right, but it gives me pure white, and button_text.selected.color is supposed to be "#7a4229" (kind of marron)

I tried several syntax : style.selected_button_text.color / style.button_selected_text.color, etc.
At best I have no error, but either white or same color as style.button_text.color (dark orange) which is not what I want.
nyaatrap wrote: Though I don't recommend to access style itself to initialize styles. It's more safe to create a new variable for it.

Code: Select all

init -3 python:
    WIDGET_COLOR = "#fff"
style button_text:
     color WIDGET_COLOR
Mmmmm. I see what you mean, but I have no intention to re-define button_text style, less all my styles. I just want my new styles to be consistent with my pre-existing theme. I want to extract pre-existing values of my theme to use in my new custom styles.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: styles and theme colors

#6 Post by nyaatrap » Mon Jul 06, 2015 7:59 am

That's way I don't recommend it. Theme isn't pre-exisited before styles - It's a modifier of styles in init -1 order. When you access to styles, there are many thing you have to investigate (init order, style group, etc) which is more work than just copy & paste.

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: styles and theme colors

#7 Post by korova » Mon Jul 06, 2015 8:14 am

So, I know what I shouldn't do. (Which doesn't help me very much...)

Now, what SHOULD I do if I want to create new styles that uses the same colors as the theme colors ?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: styles and theme colors

#8 Post by nyaatrap » Mon Jul 06, 2015 8:48 am

Usually, is statement or take statement works enough.

Code: Select all

style new_button is button:
style new_button take button:
If it's not enough, create a new variable then copy & paste the theme color like the above.

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: styles and theme colors

#9 Post by korova » Mon Jul 06, 2015 9:16 am

Thanks for your help. I really appreciate your interest.
nyaatrap wrote:Usually, is statement or take statement works enough.

Code: Select all

style new_button is button:
style new_button take button:
Except I'm not trying to create a new button style.
I try to create a new text style, for example, that's gonna use same color set as the theme, but not same distribution of colors as the predefined button or predefined text style.
(Sorry, I'm a very complicated person)
nyaatrap wrote:If it's not enough, create a new variable then copy & paste the theme color like the above.
Which is precisely what I'm trying to avoid.

If I suddenly decide to change theme colors (with ren'py launcher for example, or directly in options.rpy) - and believe me, this might happen - , I'll have to remember to change that new variable too.
This is why I'm trying to access somehow, from code, to the theme color values.

User avatar
Enerccio
Miko-Class Veteran
Posts: 616
Joined: Thu Oct 26, 2006 4:23 pm
Projects: My Teacher; Songs of Araiah; Something new; Possible Cross Bomber?
Location: Slovakia, Kosice
Contact:

Re: styles and theme colors

#10 Post by Enerccio » Tue Jan 30, 2018 4:54 pm

Bumping this post with an answer, because frankly, I had similar issue and this was google hit for it.

So my solution to accessing

Code: Select all

style.stylename.property
is via this small function

Code: Select all

def search_style(s, f):
        for p in s.properties:
            if f in p:
                 return p[f]
and is used with

Code: Select all

search_style(style.stylename, "proprety")
Terribly inefficient but seems to work!
Image
http://www.bishojo.tk is technically ONLINE!
Songs of Araiah promo: http://www.youtube.com/watch?v=CalchucuoDU

Post Reply

Who is online

Users browsing this forum: No registered users