[Solved] ymaximum not working

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
Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

[Solved] ymaximum not working

#1 Post by Adrian_DVL »

Hi friends!

I have some trouble about positioning. I have some sort of messaging app, so I have my chats with people and, on the main screen of the app, a list with all chats. The thing is that I want to show a small preview of the last message of each chat below the name of each character, next to their picture, and I have something like this so far:

Code: Select all

for i in glist.chtd:
        text i.name xpos 617 ypos cypos font "BRLNSR.TTF" size 20 color "#000000" at tpapp
        if ".jpg" in i.chat[0]:
            text "Photo" font "Lato-Regular.ttf" size 12 color "#1a2840" xpos 617 ypos cypos+25 at tpapp
        else:
            text i.chat[0] font "Lato-Regular.ttf" size 12 color "#545454" xpos 617 ypos cypos+25 xmaximum 200 ymaximum 20 at tpapp
        imagebutton:
            at tpapp
            xpos 557
            ypos cypos
            idle i.picm
            hover i.picmh
            action Show("pmesc", girl=i)

        $ cypos = cypos+60
My problem is that, while xmaximum works perfectly fine and prevents the text to go beyond those 200 pixels, ymaximum don't, and the result is showing the whole message, invading the space of the next chats, while what I want is to show just the first few words of the message.

How can I do that guys?

Also, how can I put this inside a viewport the easiest way? I'm having a hard time due to the particularities of the positions being variables and all...
Last edited by Adrian_DVL on Fri Sep 08, 2023 8:49 am, edited 1 time in total.

User avatar
m_from_space
Miko-Class Veteran
Posts: 984
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: ymaximum not working

#2 Post by m_from_space »

If you don't want text to bleed over the borders of a displayable, put each message inside a viewport with those parameters. Children of a viewport will only be rendered inside the viewport. Here is how you use them:

https://www.renpy.org/dev-doc/html/scre ... l#viewport

On the other hand, if your text is too long, you can check for its length within a function and then just show a part of it (let's say up to 128 characters per message) and add "..." or whatever.

Example for viewport:

Code: Select all

screen test:
    viewport:
        xalign 0.5 yalign 0.5
        xsize 200 ysize 45
        frame:
            background Solid("#f00")
            xfill True yfill True
            text "This is a text that will probably bleed through the frame, but not the viewport." color "#fff"
Example for text cutting:

Code: Select all

init python:
    def cutText(what):
        if len(what) > 32:
            return what[0:32] + " (...)"
        return what

screen test():
    text cutText("A long text that will be cut by the function and then returned so it will not bleed.")

Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: ymaximum not working

#3 Post by Adrian_DVL »

m_from_space wrote: Fri Sep 08, 2023 7:22 am On the other hand, if your text is too long, you can check for its length within a function and then just show a part of it (let's say up to 128 characters per message) and add "..." or whatever.

Example for text cutting:

Code: Select all

init python:
    def cutText(what):
        if len(what) > 32:
            return what[0:32] + " (...)"
        return what

screen test():
    text cutText("A long text that will be cut by the function and then returned so it will not bleed.")
Thanks a lot! Actually, that's what I ended up doing, but splitting words before, so that if the last word of that preview is left uncompleted, it's not shown. Something like this:

Code: Select all

...
        tempch = girl.chat[0][0:30]
        tempch = tempch.split(" ")
        tempch = tempch[0:-1]
        girl.chpr = " ".join(tempch)
        ...
That's not a perfect solution though, since there may be words with wider characters and make the preview to differ in width. Any way to show monospace text, for instance?

User avatar
m_from_space
Miko-Class Veteran
Posts: 984
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: ymaximum not working

#4 Post by m_from_space »

Adrian_DVL wrote: Fri Sep 08, 2023 7:44 amAny way to show monospace text, for instance?
Yes, just use a monospace font. xD

Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: ymaximum not working

#5 Post by Adrian_DVL »

m_from_space wrote: Fri Sep 08, 2023 7:48 am
Adrian_DVL wrote: Fri Sep 08, 2023 7:44 amAny way to show monospace text, for instance?
Yes, just use a monospace font. xD
Good point xD
Anyone, I can take this thread as solved. Thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]