[SOLVED] Textbutton's text doesn't conform to Style

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
Lin Augustine
Newbie
Posts: 7
Joined: Fri Aug 12, 2016 7:05 pm
Completed: Who Stole the Snow Globe?
Projects: Who Stole the Snow Globe?, The First Sunset
Tumblr: linaugustineart
Location: Florida, U.S.
Contact:

[SOLVED] Textbutton's text doesn't conform to Style

#1 Post by Lin Augustine »

I'm trying to use a custom style for buttons. Right now, I'm testing it on the main menu buttons (which are textbuttons).

It isn't giving me an error and it displays the button's background and padding properly, but not the text. It also plays the sound on hover, as expected. The text should be size 36 in general, black on idle and red on hover:

Code: Select all

####################################
# Styles

style mbutton is button:
    background "gui/main button.png"
    size 36
    idle_color "#000"
    hover_color "#f00"
    hover_sound "sfx/click.wav"
    xpadding 20
    ypadding 20

####################################
# Main Menu
# Screen that's used to display the main menu, when Ren'Py first starts
# http://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu:
    tag menu
    add "images/bg.png"
    vbox:
        align(0.5,0.5)
        textbutton _("Start") action Start() style "mbutton"
        textbutton _("Load") action ShowMenu("load") style "mbutton"
        textbutton _("Preferences") action ShowMenu("preferences") style "mbutton"
        textbutton _("Help") action Help() style "mbutton"
        textbutton _("Quit") action Quit(confirm=False) style "mbutton"  
But instead, the text is white on both idle and hover, and the size is smaller than 36 but I'm not sure what size exactly (maybe 28):

Image

Why doesn't the text look how it should according to the style I defined, and how can I fix it?

Thanks in advance :)
Last edited by Lin Augustine on Sun Aug 21, 2016 5:45 pm, edited 1 time in total.

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Textbutton's text doesn't conform to Style

#2 Post by Iylae »

Textbuttons are actually two screen elements wrapped in one:

Code: Select all

style "mbutton" # styles the button itself
text_style "mbuttontext" # styles the button's text
So you need to make a second style which controls the text size, and apply that to the text_style parameter of the textbutton.

Alternatively you can just use mbutton_text as the style name, and RenPy pulls it implicitly from the _text suffix on the style name.
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

User avatar
Lin Augustine
Newbie
Posts: 7
Joined: Fri Aug 12, 2016 7:05 pm
Completed: Who Stole the Snow Globe?
Projects: Who Stole the Snow Globe?, The First Sunset
Tumblr: linaugustineart
Location: Florida, U.S.
Contact:

Re: Textbutton's text doesn't conform to Style

#3 Post by Lin Augustine »

Ah, thanks so much! It works perfectly. I didn't know that you needed to define a separate style specifically for text.

Here's the updated code, for anyone who's wondering:

Code: Select all

####################################
# Styles

style mbutton is button:
    background "gui/main button.png"
    hover_sound "sfx/click.wav"
    xpadding 20
    ypadding 20
    
style mbutton_text:
    size 36
    idle_color "#000000"
    hover_color "#f00"

####################################
# Main Menu
# Screen that's used to display the main menu, when Ren'Py first starts
# http://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu:
    tag menu
    add "images/bg.png"
    vbox:
        align(0.5,0.5)
        #spacing 20
        textbutton _("Start") action Start() style "mbutton"
        textbutton _("Load") action ShowMenu("load") style "mbutton"
        textbutton _("Preferences") action ShowMenu("preferences") style "mbutton"
        textbutton _("Help") action Help() style "mbutton"
        textbutton _("Quit") action Quit(confirm=False) style "mbutton"   

Post Reply

Who is online

Users browsing this forum: No registered users