Viewport smooth scrolling (for NVL text box)

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
komehara
Regular
Posts: 36
Joined: Fri Jan 31, 2020 10:08 pm
Projects: Spirit Link
Tumblr: hsandt
Deviantart: hsandt
Github: hsandt
itch: komehara
Contact:

Viewport smooth scrolling (for NVL text box)

#1 Post by komehara »

Coming from Automatic nvl-clear when block goes off the window I wanted to auto-scroll NVL text when there is too much text and it bleeds out to the bottom. I managed to do instant scroll by using yinitial 1.0:

Code: Select all

# screens.rpy

screen nvl(dialogue, items=None):
    frame:
        style "nvl_content_frame"

        viewport:
            yinitial 1.0

            # Disable for now to avoid input conflicts, YMMV
            # scrollbars "vertical"
            # mousewheel True
            # draggable True
            # pagekeys True

            vbox:
                window:
                    ...

                add SideImage() xalign 0.0 yalign 1.0
However, I could not manage to get the "smooth animated scrolling" that the OP suggested in the issue.

I tried using ATL:

Code: Select all

transform smooth_scroll(duration=1.0):
	linear duration yoffset 1.0
	
screen nvl(dialogue, items=None):
    frame:
        style "nvl_content_frame"

        viewport at smooth_scroll:
            ...
but it only moved text fixed amount of pixels even when passing a fraction, unlike yinitial. I tried yinitial too but it's not an animatable property (it makes sense, I want to change the current offset, not the initial one). I found no way to get the ysize of the viewport at a given time and pass it to smooth_scroll to set the proper yoffset as fixed pixel size either.

Do you know how to animate a viewport scroll toward its bottom (100% scroll) ?

For completion and people who just wants to know how to create an NVL viewport with instant scrolling, I put the rest of my code below (it handles placing the NVL box in the middle of the window with the right margin and padding, and a custom background texture):

Code: Select all

# screens.rpy

style nvl_content_frame:
    # Prepare custom texture asset here
    background "gui/nvl_text_box.png"

    left_margin gui.nvl_margin_side
    right_margin gui.nvl_margin_side
    top_margin gui.nvl_margin_top
    # we don't define bottom_margin here because BG position will be determined
    # by the 3 other margins, and gui.nvl_borders.pad_bottom will handle stopping
    # text at the right position (and auto-scrolling if needed)

    padding gui.nvl_borders.padding

# gui.rpy

# Customise this to place the text *inside* the NVL textbox frame properly
define gui.nvl_borders = Borders(0, 15, 0, 30, pad_left=70, pad_right=70, pad_top=40, pad_bottom=150)

# Custom properties to place a non-fullscreen NVL background precisely
# side = left and right to make sure centered text is balanced
define gui.nvl_margin_side = 300
define gui.nvl_margin_top = 35

# You can now store more than 6 paragraphs if you need to since scrolling works
define gui.nvl_list_length = 10

# You can use dynamic NVL paragraph height + spacing now that scrolling works well
define gui.nvl_height = None
define gui.nvl_spacing = 40

# You can adjust this to fit your needs but for centered text I just follow this:
define gui.nvl_thought_xpos = 0
define gui.nvl_thought_ypos = 0
# Value = Screen.width - 2 * gui.nvl_margin_side - (gui.nvl_borders.pad_left +  gui.nvl_borders.pad_right)
# Here Value = 1920 - 2 * 300 - (70 + 70) = 1180 (but any value above also works)
define gui.nvl_thought_width = 1180

Post Reply

Who is online

Users browsing this forum: Bing [Bot]