Centering text in textbox [Solved!]

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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Centering text in textbox [Solved!]

#1 Post by yuucie »

I poked around and found an old thread asking the same question, but the answers didn't work for me (and I didn't want to necro) so here's the question again. Sometimes I want to center text in the textbox (not on the full screen, so centered "dialogue" is out of the question), and I don't want to assign it to a character only as I want to use it for various events (so defining Character is probably not what I'm looking for).
I also do not want to black out the screen and have it appear NVL style, so I don't think NVL is the kind I'm looking for.

So far, I tried to make:

Code: Select all

$ cen = what_text_align=0.5
so when I want to center text:

Code: Select all

"Centered Text in Textbox" with cen
the problem is, it's not working. I don't think what_text_align is the right code, but I can't seem to find the one I'm looking for. Help please?
Last edited by yuucie on Wed Jun 25, 2014 9:07 pm, edited 1 time in total.

User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: Centering text in textbox

#2 Post by ArachneJericho »


User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Centering text in textbox

#3 Post by yuucie »

ArachneJericho wrote:Does this help?

http://www.renpy.org/wiki/renpy/doc/FAQ ... _screen.3F
the centered tag isn't what i'm looking for, but the second part is! Thanks!

EDIT the code isn't working. Sigh... I have it written as:

Code: Select all

   $ cen = Character(None, what_xalign=0.5, what_text_align=0.5)
and when I write dialogue:

Code: Select all

"Centered Textbox dialogue" with cen

Code: Select all

cen "Centered Textbox dialogue"
neither of them work.

So I've tried defining it as a character:

Code: Select all

define cen = Character(None, what_xalign=0.5, what_text_align=0.5,  text_xpos=0.5)
which worked but not in the way I want it too ;__;

Image

I can't believe I'm having so much trouble with something that seems so simple, haha..

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Centering text in textbox

#4 Post by xavimat »

Maybe you need also: window_xalign=0.5, #Centers the window horizontally
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Centering text in textbox

#5 Post by yuucie »

xavimat wrote:Maybe you need also: window_xalign=0.5, #Centers the window horizontally
added it in, but didn't seem to do anything ;_; OTL (thanks for helping tho!)

User avatar
Chaotic
Regular
Posts: 30
Joined: Fri Feb 22, 2013 7:32 pm
Location: England, UK
Contact:

Re: Centering text in textbox

#6 Post by Chaotic »

I have centered text in my project too and what I did was I put this in the options.rpy under the text (font) section so I knew it was to do with the text/textbox:

Code: Select all

style.default.xalign = 0.5
It works perfectly for me and centers the text into the middle :)

EDIT: Answered the question wrong but still useful for those who want to center all text...OTL

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Centering text in textbox

#7 Post by yuucie »

Chaotic wrote:I have centered text in my project too and what I did was I put this in the options.rpy under the text (font) section so I knew it was to do with the text/textbox:

Code: Select all

style.default.xalign = 0.5
It works perfectly for me and centers the text into the middle :)

EDIT: Answered the question wrong but still useful for those who want to center all text...OTL
Ah yeah, the problem is I only want my text to be centered in specific events, not all the time. But thanks! I'll keep trying to center it properly @_@

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Centering text in textbox

#8 Post by Asceai »

The problem is the structure. You have a window (that's the transparent-black section of the screen where the text goes) and it is styled with window_... params by the Character function. Inside that is a vbox. Inside the vbox is the text, which is styled with the what_... params. Centering the window does nothing because the window fills the screen horizontally. Centering the 'what' text does nothing because the 'what' text is contained within the vbox which is exactly large enough for the 'what' text. You can't style the vbox by passing params to Character.

Code: Select all

+------------------------------------------------+
|Window                                          |
|+----------------+                              |
||Vbox            |                              |
||+--------------+|                              |
|||What          ||                              |
||+--------------+|                              |
|+----------------+                              |
+------------------------------------------------+
Even if 'what' is centered, it's only centered within vbox, so you can see why what_xalign = 0.5 does nothing.

Here's a solution:

Code: Select all

style say_vbox xfill True
This will expand the vbox out to fill the window.
Then

Code: Select all

define cen = Character(None, what_xalign=0.5, what_text_align=0.5)
should do the trick.

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Centering text in textbox

#9 Post by yuucie »

Asceai wrote:The problem is the structure. You have a window (that's the transparent-black section of the screen where the text goes) and it is styled with window_... params by the Character function. Inside that is a vbox. Inside the vbox is the text, which is styled with the what_... params. Centering the window does nothing because the window fills the screen horizontally. Centering the 'what' text does nothing because the 'what' text is contained within the vbox which is exactly large enough for the 'what' text. You can't style the vbox by passing params to Character.

Code: Select all

+------------------------------------------------+
|Window                                          |
|+----------------+                              |
||Vbox            |                              |
||+--------------+|                              |
|||What          ||                              |
||+--------------+|                              |
|+----------------+                              |
+------------------------------------------------+
Even if 'what' is centered, it's only centered within vbox, so you can see why what_xalign = 0.5 does nothing.

Here's a solution:

Code: Select all

style say_vbox xfill True
This will expand the vbox out to fill the window.
Then

Code: Select all

define cen = Character(None, what_xalign=0.5, what_text_align=0.5)
should do the trick.
oh my goodness, thank you so much for the explanation. I like knowing what each code is supposed to control, which is why I was so confused why some of them didn't work the way I thought they did, but with your diagram everything makes so much more sense.

Thank you!! Just for clarification to anyone else with the same problem, I wrote

Code: Select all

style.say_vbox_xfill = True
into my options.rpy script, and it works beautifully!

Image

Thank you so much Asceai (and everyone who tried to help too!)

User avatar
Laiska
Veteran
Posts: 323
Joined: Sat Jan 11, 2014 1:14 am
Completed: Queen At Arms, Cerulean, The Shadows That Run Alongside Our Car, Vicarwissen
Projects: Caramel Mokaccino
Tumblr: minesweeperaddict
Deviantart: koyoba
Contact:

Re: Centering text in textbox [Solved!]

#10 Post by Laiska »

I don't mean to necro, but how does one go about doing this but with vertical centering? i.e. centering the dialogue of a specific character along the y-axis, but inside the text box?

Defining a character like

Code: Select all

define cen = Character(None, what_xalign=0.5, what_text_align=0.5)
and then doing this

Code: Select all

style.say_vbox_xfill = True
produces the intended result, sort of, but then the text box expands to fill the whole screen!

Is there a way to achieve this without changing the size of the textbox?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Centering text in textbox [Solved!]

#11 Post by xavimat »

Have you tried style.say_vbox.xfill = True or style.say_vbox.yfill = True ?

I think style.say_vbox.yalign = .5 could work.

More options to try:
Something like style.window.ymaximum = 300 in options.rpy?
Or maybe, in the character definition:
define cen = Character(None, window_ymaximum=300)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], IrisColt