How can you change specific style text size at runtime?

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
henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

How can you change specific style text size at runtime?

#1 Post by henvu50 » Fri Aug 20, 2021 5:16 pm

How can you change specific style text size at runtime?

I tried this code, but it doesn't actually make the text bigger.

Code: Select all

    def func_text_size_adjust():
        print gui.text_size
        #style.default.size = 99
        style.default.size = 99
        style.radio_button_text.size = 99
        #style.rebuild()
        gui.rebuild()
(I know about the accessibility menu, but that kind of text scaling affects everything in an uncontrolled manner, so text looks out of place and broken.)

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How can you change specific style text size at runtime?

#2 Post by Ocelot » Fri Aug 20, 2021 6:09 pm

The proper way would probably be to register alternatives for selected styles and then changing it with set_style_preference
https://www.renpy.org/doc/html/style.ht ... references

Or use GUI preferences:
https://www.renpy.org/doc/html/gui_adva ... references
< < insert Rick Cook quote here > >

henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How can you change specific style text size at runtime?

#3 Post by henvu50 » Fri Aug 20, 2021 6:14 pm

Ocelot wrote:
Fri Aug 20, 2021 6:09 pm
The proper way would probably be to register alternatives for selected styles and then changing it with set_style_preference
https://www.renpy.org/doc/html/style.ht ... references

Or use GUI preferences:
https://www.renpy.org/doc/html/gui_adva ... references
Thanks! I'm trying the StylePreference route now, but what's odd is that when I register a style preference, the change takes place immediately after the registering.

As soon as the game runs this line on startup, it immediately changes the text size, instead of waiting until I set it via textbutton action StylePreference....

Code: Select all

init python:
     #this instantly changes the text size.
     renpy.register_style_preference("text", "id83", style.radio_button_text, "size", 75)
     #this immediately changes the text size, is it supposed to do that?
     renpy.register_style_preference("size", "20", style.default, "size", 20)

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How can you change specific style text size at runtime?

#4 Post by Ocelot » Fri Aug 20, 2021 6:22 pm

If you have only one alternative, it would be selected and applied by default. If you want to switch between them, you need to have at least two.
< < insert Rick Cook quote here > >

henvu50
Veteran
Posts: 322
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How can you change specific style text size at runtime?

#5 Post by henvu50 » Sat Aug 21, 2021 4:25 am

I assumed the default would be whatever is in the screens.rpy. So, if you set a default size of 33 in the screens.rpy file, then that should be the default. Then when you register an alternative style, it doesn't kick in until you set it. If you have to register your own default stylepreference, then that means the default values in the screens.rpy have no use and just take up space?

Still, not a big deal, just speculating. This is still very useful though and I plan to implement it! Thanks again.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How can you change specific style text size at runtime?

#6 Post by Ocelot » Sat Aug 21, 2021 4:36 am

henvu50 wrote:
Sat Aug 21, 2021 4:25 am
So, if you set a default size of 33 in the screens.rpy file, then that should be the default. Then when you register an alternative style, it doesn't kick in until you set it.
If you request the name of the current alternative, what should it return? How to change back when you have switched to alternative already?
henvu50 wrote:
Sat Aug 21, 2021 4:25 am
If you have to register your own default stylepreference, then that means the default values in the screens.rpy have no use and just take up space?
You could just not define them in the first place. There are many ways to write code which will not do anything and just take up space.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot], span4ev