[Solved] In-game choice screen position and scrollbar viewport

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
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

[Solved] In-game choice screen position and scrollbar viewport

#1 Post by scorlight »

Hello all, this has driven me crazy these days, I have no idea how to fix it :cry: :cry: :cry:
I have a menu with lots of choices in my game and I want to add a scrollbar using https://www.renpy.org/dev-doc/html/scre ... l#viewport

Code: Select all

screen choice(items): 
    style_prefix "choice"
    
    viewport:
        area (240, 100, 843, 500)           # scrollable area
        if len(items) > 7:                       #only menus with more than 7 choices have the scrollbar
            scrollbars "vertical"
            mousewheel True
            draggable True
                
        vbox:
            spacing 20
            for i in items:
                textbutton i.caption action i.action
It works, but now ALL in-game menus follow the "240, 100, 843, 500" position, it looks good with long menus but some menus with only a few choices are like that too. How can I move the menus without scrollbar back to the middle of the screen???
Last edited by scorlight on Wed Apr 15, 2020 12:47 am, edited 1 time in total.
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: In-game choice screen position and scrollbar viewport

#2 Post by Alex »

Try to check the number of items not inside the viewport but before it, like

Code: Select all

screen choice(items):
    if len(items) > 7:
        style_prefix "choice"
    
        viewport:
            area (240, 100, 843, 500)           # scrollable area
            scrollbars "vertical"
            mousewheel True
            draggable True
                
            vbox:
                spacing 20
                for i in items:
                    textbutton i.caption action i.action
    else:
        window:
            style "menu_window"

            vbox:
                style "menu"

                for i in items:

                    if i.action:

                        button:
                            action i.action
                            style "menu_choice_button"

                            text i.caption style "menu_choice"

                    else:
                        text i.caption style "menu_caption"

User avatar
scorlight
Regular
Posts: 67
Joined: Fri Sep 13, 2013 7:02 am
Contact:

Re: In-game choice screen position and scrollbar viewport

#3 Post by scorlight »

Alex wrote: Thu Apr 09, 2020 3:26 pm

Code: Select all

screen choice(items):
    if len(items) > 7:
        style_prefix "choice"
    
        viewport:
            area (240, 100, 843, 500)           # scrollable area
            scrollbars "vertical"
            mousewheel True
            draggable True
                
            vbox:
                spacing 20
                for i in items:
                    textbutton i.caption action i.action
    else:
        window:
            style "menu_window"

            vbox:
                style "menu"

                for i in items:

                    if i.action:

                        button:
                            action i.action
                            style "menu_choice_button"

                            text i.caption style "menu_choice"

                    else:
                        text i.caption style "menu_caption"
Thanks for the reply, I really didn't think about this option :D The code has a bug but I managed to find the solution from your suggestion, thank you so much!! :D :D :D
Artist for rent, see my art here: http://scorlight.deviantart.com/gallery/

Post Reply

Who is online

Users browsing this forum: Bing [Bot]