How to center main menu text-buttons and also remove sidebar

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
ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

How to center main menu text-buttons and also remove sidebar

#1 Post by ConerNSFW » Sun Oct 23, 2016 5:16 pm

I knew how to do this with the old gui, but the new one is really confusing me.

So this is how my main menu currently looks:

Image

and this is how I would like it to look:

Image

As you can see, I would like to centre the text buttons, which i tried to do with text align to no success.

I'd also like to get rid of the black bar on the left, which I haven't even attempted yet.

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

Re: How to center main menu text-buttons and also remove sid

#2 Post by Ocelot » Sun Oct 23, 2016 5:36 pm

Can you please show the code for corresponding screens?
< < insert Rick Cook quote here > >

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#3 Post by ConerNSFW » Sun Oct 23, 2016 5:45 pm

Code: Select all

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:
            
            ypos 0.6
            xpos 0.5
            

            textbutton _("Start") action Start()
            
        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Preferences") action ShowMenu("preferences")

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()

        textbutton _("About") action ShowMenu("about")

        if renpy.variant("pc"):

            ## Help isn't necessary or relevant to mobile devices.
            textbutton _("Help") action ShowMenu("help")

            ## The quit button is banned on iOS and unnecessary on Android.
            textbutton _("Quit") action Quit(confirm=not main_menu)

It's just the default code, except I moved the main menu buttons to the middle.

User avatar
MaxYablockin
Newbie
Posts: 3
Joined: Fri Oct 14, 2016 4:47 am
Contact:

Re: How to center main menu text-buttons and also remove sid

#4 Post by MaxYablockin » Sun Oct 23, 2016 5:52 pm

In screen navigation xpos 0.5
In style main_menu_frame delete background
And add xalign 0.5 in style navigation_button_text

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

Re: How to center main menu text-buttons and also remove sid

#5 Post by Ocelot » Sun Oct 23, 2016 5:59 pm

You have moved box containing buttons (almost) to the middle of the screen. You need to fix position of buttons inside that box.

One way is to add xalign 0.5 to each button definition.

Other way is to define your own style for main menu buttons:

Code: Select all

style main_menu_button is navigation_button:
    xalign 0.5

# inside screen:
vbox:
    if main_menu:
        style_prefix "main_menu"
    else:
        style_prefix "navigation"
This assumes that you want to keep default position of buttons in other menu screens.
< < insert Rick Cook quote here > >

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#6 Post by ConerNSFW » Sun Oct 23, 2016 6:08 pm

double post
Last edited by ConerNSFW on Sun Oct 23, 2016 6:13 pm, edited 1 time in total.

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#7 Post by ConerNSFW » Sun Oct 23, 2016 6:11 pm

Thanks MaxYablockin that helped a lot.

2 problems, the first is that it moves the game navigation menu (as in the one when you're not in the main menu). To fix this I moved the xpos 0.5 from the navigation section to the "if main_menu:" section and it worked fine.

The second problem is something I need a little help with, for some reason the text isn't centred.

Image

And changing the xpos makes it move larger amounts that would be expected, for example if I set it to xpos 0.4 then it just jumps really far to the left.

I think could do a half fix by working out the point closing to the centre with trial and error but I think that may cause some more problems down the line.

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

Re: How to center main menu text-buttons and also remove sid

#8 Post by Ocelot » Sun Oct 23, 2016 6:16 pm

xpos sets position of current anchor. By default it is the left edge. You want center of vbox to be at the center of the screen. To do that, you need to set both position and anchor to 0.5. Luckily there is property which sets both at the same time.

Replace xpos 0.5 with xalign 0.5
< < insert Rick Cook quote here > >

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#9 Post by ConerNSFW » Sun Oct 23, 2016 6:27 pm

Ok, so I changed xpos 0.5 to xalign 0.5 and it puts the test half off the screen on the left, it's as if it's stuck in frame that's on the left.

I also tried using a custom style and it wouldn't centre the text.

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

Re: How to center main menu text-buttons and also remove sid

#10 Post by Ocelot » Sun Oct 23, 2016 6:41 pm

Ok, I made a project from scratch and here are results:

Code: Select all

# screen:
screen navigation():

    vbox:
        if not main_menu:
            style_prefix "navigation"
        else:
            style_prefix "mainmenu"
        
        if main_menu:
            xalign 0.5
        else:
            xpos gui.navigation_xpos

        yalign 0.5

        spacing gui.navigation_spacing
        # rest of screen is the same

# styles:
style mainmenu_button is navigation_button:
    xalign 0.5
    
style mainmenu_button_text is navigation_button_text:
    xalign 0.5
Image
< < insert Rick Cook quote here > >

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#11 Post by ConerNSFW » Sun Oct 23, 2016 6:47 pm

I copy and pasted your code exactly, and mine is still off.

If you don't mind could you upload the project file?

From your advice I've managed to get it pretty close but it's still just off for some reason.

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

Re: How to center main menu text-buttons and also remove sid

#12 Post by Ocelot » Sun Oct 23, 2016 6:54 pm

Those are literally only changes I did. Here is the link to project:

https://dl.dropboxusercontent.com/u/110 ... 20Text.zip
< < insert Rick Cook quote here > >

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#13 Post by ConerNSFW » Sun Oct 23, 2016 6:55 pm

Alright, I've got your code to work, I had another thing with the same name and it was overriding your code, now I'm just going to try and replicate it in my game.

ConerNSFW
Regular
Posts: 40
Joined: Sun Oct 23, 2016 5:08 pm
Contact:

Re: How to center main menu text-buttons and also remove sid

#14 Post by ConerNSFW » Sun Oct 23, 2016 7:04 pm

Yay, it's done finally.

Thanks so much Ocelot and MaxYablockin, I've spent over an hour on this and I probably wouldn't have even got it done without you two.

Image

It's centred perfectly. (The brown rectangles were to test since they're both the same size.)

Again thanks.

Post Reply

Who is online

Users browsing this forum: Hojoo