Creating a Slider for Text Size in Preferences

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
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Creating a Slider for Text Size in Preferences

#1 Post by lsf22 »

Renpy version 8.1.3

I've been trying to get a working slider option for text size. So far it's set for dialogue of the game but I'm having trouble making it work. The current state of it is that it does not select any other size nor does the slider appear correctly.

Screens.rpy:

Code: Select all

	hbox:
	    style_prefix "slider"
	    box_wrap True
	    vbox:
	    	label _("Text Size")
		bar value gui.preference("size")
		#bar value Preference("size")
		null height (4 * gui.pref_spacing)
GUI.rpy:

Code: Select all

## The size of normal dialogue text.
define gui.text_size = gui.preference("size", 50)
#define gui.text_size = 44
Attachments
Pref. Text Size Slider 1.png
Preferences Menu Text Size Slider not working.
(110.92 KiB) Not downloaded yet

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1030
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Creating a Slider for Text Size in Preferences

#2 Post by m_from_space »

lsf22 wrote: Sat Nov 25, 2023 9:34 pmSo far it's set for dialogue of the game but I'm having trouble making it work. The current state of it is that it does not select any other size nor does the slider appear correctly.
I don't know why you think your preference called "text size" or "size" does anything at all. Where did you read that? Here is the official documentation for preferences: https://www.renpy.org/doc/html/screen_a ... Preference

So to change font size, you have to use:

Code: Select all

bar value Preference("font size")

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1030
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Creating a Slider for Text Size in Preferences

#3 Post by m_from_space »

m_from_space wrote: Tue Nov 28, 2023 9:58 am
lsf22 wrote: Sat Nov 25, 2023 9:34 pmSo far it's set for dialogue of the game but I'm having trouble making it work. The current state of it is that it does not select any other size nor does the slider appear correctly.
I don't know why you think your preference called "text size" or "size" does anything at all. Where did you read that? Here is the official documentation for preferences: https://www.renpy.org/doc/html/screen_a ... Preference

So to change font size, you have to use:

Code: Select all

bar value Preference("font size")
/edit

The above is actually for scaling all fonts. If you want to change default sizes for certain gui elements, use gui.SetPreference and give the user some prebaked sizes to choose from instead. You cannot use this with bars, but buttons and fixed values. Now of course the user could use a bar to change a variable and then you use that variable to set the preference after he clicks or with a timer.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Dark79