Buttons on a Button

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
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Buttons on a Button

#1 Post by Braydxne » Thu Nov 26, 2020 10:09 pm

I'm trying to put two text buttons on top of a button, so the background button will change colour when hovered. This works but then when you hover over one of the text buttons the background button loses focus and then goes back to the idle image. Is there a way to make it so the text buttons won't revert the hover status on the background button?

Code: Select all

	button:
                    xysize(1804, 106)

                    idle_background("gui/pause/settings_button_idle.png")
                    hover_background("gui/pause/settings_button_hover.png")

                    text "Display Mode":
                        font "Abel.ttf"
                        size 78
                        xoffset 50
                        yalign 0.5
                        outlines [ (absolute(1), "#ffffff", absolute(0), absolute(0)) ]

                    hbox:
                        xalign 0.6
                        yalign 0.5

                        textbutton "WINDOWED":
                            action Preference("display", "window")
                            text_size 74
                            text_font "Abel.ttf"

                        textbutton "FULLSCREEN":
                            action Preference("display", "fullscreen")
                            text_size 74
                            text_font "Abel.ttf"

                    action NullAction()

User avatar
_ticlock_
Veteran
Posts: 393
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Buttons on a Button

#2 Post by _ticlock_ » Thu Nov 26, 2020 11:20 pm

Hi, Braydxne,

I am not sure if that is an optimal solution, but you can try to use a variable to additionally control background when other elements gain/lose focus:

Code: Select all

screen test_screen():
    default hov = False
    
    button:
        xysize(1804, 106)
        if hov:
            background "gui/pause/settings_button_hover.png"
        else:
            background "gui/pause/settings_button_idle.png"
        hover_background "gui/pause/settings_button_hover.png"
        
        vbox:
            textbutton "WINDOWED":
                action Preference("display", "window")
                hovered SetScreenVariable('hov', True)
                unhovered SetScreenVariable('hov', False)
            textbutton "FULLSCREEN":
                action Preference("display", "fullscreen")
                hovered SetScreenVariable('hov', True)
                unhovered SetScreenVariable('hov', False)
                
	action NullAction()

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: Buttons on a Button

#3 Post by Braydxne » Fri Nov 27, 2020 12:46 am

_ticlock_ wrote:
Thu Nov 26, 2020 11:20 pm
Hi, Braydxne,

I am not sure if that is an optimal solution, but you can try to use a variable to additionally control background when other elements gain/lose focus:

Code: Select all

screen test_screen():
    default hov = False
    
    button:
        xysize(1804, 106)
        if hov:
            background "gui/pause/settings_button_hover.png"
        else:
            background "gui/pause/settings_button_idle.png"
        hover_background "gui/pause/settings_button_hover.png"
        
        vbox:
            textbutton "WINDOWED":
                action Preference("display", "window")
                hovered SetScreenVariable('hov', True)
                unhovered SetScreenVariable('hov', False)
            textbutton "FULLSCREEN":
                action Preference("display", "fullscreen")
                hovered SetScreenVariable('hov', True)
                unhovered SetScreenVariable('hov', False)
                
	action NullAction()
That's so smart! That fits what I need perfectly, thank you so much!

Post Reply

Who is online

Users browsing this forum: No registered users