scrollbars

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
vlint
Regular
Posts: 115
Joined: Tue Oct 09, 2007 7:44 pm
Contact:

scrollbars

#1 Post by vlint »

How do I get scrollbars for text through Python code? I'm using ui.text(). I suspect it's done with styles, somehow, but I don't really know how to implement styles properly.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: scrollbars

#2 Post by PyTom »

Scrolled text is a bit complicated, requiring a ui.viewport and one or more ui.bars. Generally, you also want a ui.side to lay them out properly.

Your best bet is to start with the example at ui.viewport, and change the ui.image call to ui.text. You may also want to replace the horizontal scrollbar with a call to ui.null(), as text shouldn't overflow the screen.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

vlint
Regular
Posts: 115
Joined: Tue Oct 09, 2007 7:44 pm
Contact:

Re: scrollbars

#3 Post by vlint »

Thanks! Haven't tried it out yet, but it looks doable, or like something else can be worked out if it turns to be troublesome.

vlint
Regular
Posts: 115
Joined: Tue Oct 09, 2007 7:44 pm
Contact:

Re: scrollbars

#4 Post by vlint »

vlint wrote:Thanks! Haven't tried it out yet, but it looks doable, or like something else can be worked out if it turns to be troublesome.
All right, I've tried it and it works. Now, I have another problem:

Is there a way to determine if the scrollbars are needed? If not, is there a way to return an integer of how many lines of text there are in the viewport? Or, is there already a way to make them only show up when needed?

I wouldn't mind them being there all the time so much if there wasn't a slight flash on them every time I put new text in the viewport (i.e. the scrollbars being called again or something, I guess).

If not, I'll have to come up with an algorithm for determining the right amount of text. I've tried this once before trying the scrollbars, for another method of spanning text, but it was pretty wild and I'd rather not go that route if possible.

Actually, a character count of the string at hand might not be so bad for this, but I'd still rather have something more dynamic, as the font won't always be the same.

vlint
Regular
Posts: 115
Joined: Tue Oct 09, 2007 7:44 pm
Contact:

Re: scrollbars

#5 Post by vlint »

vlint wrote:I wouldn't mind them being there all the time so much if there wasn't a slight flash on them every time I put new text in the viewport (i.e. the scrollbars being called again or something, I guess).
I found a way to get rid of the flashing thing—I just set the spacing to 0 and now it's fine.

Post Reply

Who is online

Users browsing this forum: recreation, Sugar_and_rice, voluorem