[SOLVED] Centering text in textbox?

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
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

[SOLVED] Centering text in textbox?

#1 Post by Lumen_Astrum »

EDIT: Issue solved. Thanks so much to those who helped!

Okay, so. Firstly, this is a mock-up of the textbox I wanted:
123.jpg
I had actually thought of an idea for the name tag (making separate textboxes for each character mentioned), but I don't have any idea how to center the text in the textbox. I did try to search about it, without success. Does anyone know what part of the code do I have to tinker, or is there anything I should add in it?

Also: there's the quick menu in the bottom. I wanted something like that, but not specifically those buttons; just any quick menu will do. XD I always see a quick menu similar to that in the tutorial game, but I don't see it anywhere mine, even though I removed my quick menu. Even if I make it appear, I have no idea how to center it :\

Help is appreciated, thank you so much in advance! :3
Last edited by Lumen_Astrum on Fri Nov 02, 2012 2:11 am, edited 1 time in total.

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#2 Post by Lumen_Astrum »

Bumping. :)

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Centering text in textbox?

#3 Post by Levrex »

xalign 0.5 shall help thou, for ye seekin' truth.

You can also achieve great knowledge by looking there:
http://lemmasoft.renai.us/forums/viewto ... =51&t=9233

and properly asking The One You Verily Cannot Hide Anything From (not really):
http://www.google.ru/search?&q=site%3Al ... enter+text
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

User avatar
Aedin
Regular
Posts: 137
Joined: Fri Sep 07, 2012 11:53 pm
Contact:

Re: Centering text in textbox?

#4 Post by Aedin »

I'm not sure how to center all the things, but I'll still play around with it and try to figure it out. To change the placing of your Quick Menu, go to your screens.rpy and find the code for the Quick Menu. Should look like this:

Code: Select all

# Quick Menu
#
# A screen that's included by the default say screen, and adds quick access to
# several useful functions.
screen quick_menu:

    # Add an in-game quick menu.
    hbox:
        style_group "quick"
    
        xalign 1.0
        yalign 1.0
        textbutton _("Q.Save") action QuickSave()
        textbutton _("Q.Load") action QuickLoad()
        textbutton _("Save") action ShowMenu('save')
        textbutton _("Skip") action Skip()
        textbutton _("Auto") action Preference("auto-forward", "toggle")
        textbutton _("Prefs") action ShowMenu('preferences')
        
init -2 python:
    style.quick_button.set_parent('default')
    style.quick_button.background = None
    style.quick_button.xpadding = 5

    style.quick_button_text.set_parent('default')
    style.quick_button_text.size = 12
    style.quick_button_text.idle_color = "#8888"
    style.quick_button_text.hover_color = "#ccc"
    style.quick_button_text.selected_idle_color = "#cc08"
    style.quick_button_text.selected_hover_color = "#cc0"
    style.quick_button_text.insensitive_color = "#4448"
    
    # Set a default value for the auto-forward time, and note that AFM is
    # turned off by default.
    config.default_afm_time = 10
    config.default_afm_enable = False
Just change the align at the top to 0.5 and that will center it on the bottom. With the style.quick_button_text things you can change the size, colour, and padding of it to make it bigger.
"There’s no shame in pleasure, Mr. Gray. You see, man just wants to be happy, but society wants him to be good. And when he’s good, man is rarely happy, and when he’s happy he is always good."

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#5 Post by Lumen_Astrum »

Levrex wrote:xalign 0.5 shall help thou, for ye seekin' truth.

You can also achieve great knowledge by looking there:
http://lemmasoft.renai.us/forums/viewto ... =51&t=9233

and properly asking The One You Verily Cannot Hide Anything From (not really):
http://www.google.ru/search?&q=site%3Al ... enter+text
I tried that, but it also centers text in NVL scenes :\
Aedin wrote:I'm not sure how to center all the things, but I'll still play around with it and try to figure it out. To change the placing of your Quick Menu, go to your screens.rpy and find the code for the Quick Menu. Should look like this:

Code: Select all

# Quick Menu
#
# A screen that's included by the default say screen, and adds quick access to
# several useful functions.
screen quick_menu:

    # Add an in-game quick menu.
    hbox:
        style_group "quick"
    
        xalign 1.0
        yalign 1.0
        textbutton _("Q.Save") action QuickSave()
        textbutton _("Q.Load") action QuickLoad()
        textbutton _("Save") action ShowMenu('save')
        textbutton _("Skip") action Skip()
        textbutton _("Auto") action Preference("auto-forward", "toggle")
        textbutton _("Prefs") action ShowMenu('preferences')
        
init -2 python:
    style.quick_button.set_parent('default')
    style.quick_button.background = None
    style.quick_button.xpadding = 5

    style.quick_button_text.set_parent('default')
    style.quick_button_text.size = 12
    style.quick_button_text.idle_color = "#8888"
    style.quick_button_text.hover_color = "#ccc"
    style.quick_button_text.selected_idle_color = "#cc08"
    style.quick_button_text.selected_hover_color = "#cc0"
    style.quick_button_text.insensitive_color = "#4448"
    
    # Set a default value for the auto-forward time, and note that AFM is
    # turned off by default.
    config.default_afm_time = 10
    config.default_afm_enable = False
Just change the align at the top to 0.5 and that will center it on the bottom. With the style.quick_button_text things you can change the size, colour, and padding of it to make it bigger.
Thank you so much! It worked wonders~

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Centering text in textbox?

#6 Post by OokamiKasumi »

Lumen_Astrum wrote:... I don't have any idea how to center the text in the textbox.
What you're looking for is here --> http://lemmasoft.renai.us/forums/viewto ... 765#p78222
You will have to doctor this code to suit your needs, maybe like this...?

Code: Select all

    define c = Character(Charles,  
        color="#ffffff",
        outlines = [(1, "#333333", 0, 0)], 
        show_two_window = True,
        what_xalign=0.5,
        what_text_align=0.5,)
However, this is for ONE specific character only!

To do ALL your text-boxes centered, go to your options.rpy page and look for this:

Code: Select all

## These let you customize the default FONTs used for text in Ren'Py.
Somewhere under that, add this:

Code: Select all

    ## Centers the Text in your textbox.
    style.default.xalign = 0.5 
To center the text in your Name box, add this:

Code: Select all

    style.say_label.xalign = 0.5
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#7 Post by Lumen_Astrum »

It also centers NVL text :\ I only wanted ADV-mode text centered... I tried the method by using the Style Inspector to specifically center ADV text, but somehow it went weird.

User avatar
Arowana
Miko-Class Veteran
Posts: 531
Joined: Thu May 31, 2012 11:17 pm
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Tumblr: navigame-media
itch: navigame
Contact:

Re: Centering text in textbox?

#8 Post by Arowana »

Do you want the centered textbox for the entire game? If the Styles aren't working out, you could try modifying your "say" screen directly. Something like this seems to work for me (might not need all the xaligns and text_aligns I put in, but just in case):

Code: Select all

### snippet from the "say" screen ###
        # The one window variant.        
        window:
            id "window"

            has vbox:
                style "say_vbox"
                xalign 0.5 ### centers textbox

            if who:
                text who id "who" xalign 0.5 ### centers name

            text what id "what" text_align 0.5 ### centers long text 

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    xalign 0.5 ### centers namebox

                    text who:
                        id "who" xalign 0.5 ### centers name
                        
            window:
                id "window"

                has vbox:
                    style "say_vbox"
                    xalign 0.5 ### centers textbox

                text what id "what" text_align 0.5 ### centers long text
If you only want to center the textbox for certain characters, you could probably switch to a modified "say" screen for them using "show_" similar to this example (let me know if you're interested in that - I won't bore you with it if not, lol).
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#9 Post by Lumen_Astrum »

Ah, it works perfectly! Thank you!

I know this may be another question to ask, but... I tried formatting the name label like how it was said so in Aleema's tutorial, but it also formatted the name label in NVL mode :| Is there anyway to format just the name label in ADV, like doing it specifically in the "say" screen directly? I know nothing about screen language :|

User avatar
Arowana
Miko-Class Veteran
Posts: 531
Joined: Thu May 31, 2012 11:17 pm
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Tumblr: navigame-media
itch: navigame
Contact:

Re: Centering text in textbox?

#10 Post by Arowana »

Yay, glad it worked! :) Yeah, you can modify the name label in the "say" screen directly if you'd like.

Here's where the name/name labels are on the "say" screen:

Code: Select all

### snippet from the "say" screen ###
        # The one window variant.       
        window:
            id "window"

            has vbox:
                style "say_vbox"
                xalign 0.5 ### centers textbox

            if who:
                text who id "who" xalign 0.5 ### centers name #<---------------name label text

            text what id "what" text_align 0.5 ### centers long text

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:           
                window: #<-----------------------------------------------------namebox 
                    style "say_who_window"
                    xalign 0.5 ### centers namebox

                    text who: #<------------------------------------------------name label text
                        id "who" xalign 0.5 ### centers name
                       
            window:
                id "window"

                has vbox:
                    style "say_vbox"
                    xalign 0.5 ### centers textbox

                text what id "what" text_align 0.5 ### centers long text
What things in particular are you looking to format? If you want to change the name text, for instance, here's all the screen language properties for text. Lots of things you can do! For instance, if you wanted to set the size, font, and color, you could write something like:

Code: Select all

text who:
    xalign 0.5 #centers name
    size 40 
    color "#000000"
    font "myfont.ttf"
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#11 Post by Lumen_Astrum »

I got an error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 28: Expected screen language statement.
    font "B.ttf"
        ^

Ren'Py Version: Ren'Py 6.13.7.1646
Block of code in issue:

Code: Select all

            if who:
                text who id "who" xalign 0.5 ### centers name
                font "B.ttf"
                size 30
                outlines (1, "#000000", 0, 0)
I was pretty sure I followed your format, and that I executed the format well in the outlines too, but I don't know how to fix it :|

User avatar
Arowana
Miko-Class Veteran
Posts: 531
Joined: Thu May 31, 2012 11:17 pm
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Tumblr: navigame-media
itch: navigame
Contact:

Re: Centering text in textbox?

#12 Post by Arowana »

I think it's complaining about the indentation. All the properties of the text element "text who" have to be lined up and indented underneath it. (Alternatively, you can put them all on the same line, but that gets long and hard to read).

Try:

Code: Select all

            if who:
                text who:
                    id "who" 
                    xalign 0.5 ### centers name
                    font "B.ttf"
                    size 30
                    outlines [(1, "#000000", 0, 0)]
(also note that you need the square brackets around the "outlines" tuple)
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image

User avatar
Lumen_Astrum
Dystopian Princess
Posts: 1662
Joined: Mon Nov 08, 2010 8:01 am
Completed: Soul and Heart, Twin Faces
Projects: Soul and Heart Replay; The Court of the Two Sides (tentative title)
Organization: Lion Box Studios
Tumblr: lumenizampel
Location: Philippines
Contact:

Re: Centering text in textbox?

#13 Post by Lumen_Astrum »

Ah, there! It works perfectly now~ Thank you so much for your help!

User avatar
iRayala
Newbie
Posts: 10
Joined: Fri Jul 08, 2022 3:08 pm
Discord: Rayala#0223
Contact:

Re: Centering text in textbox?

#14 Post by iRayala »

This was just what I needed for my current project, thanks

Post Reply

Who is online

Users browsing this forum: Google [Bot], Milkymalk