Page 1 of 1

remember YScrollValue

Posted: Mon Oct 12, 2020 6:06 am
by nananame
A very simple thing is turning into a problem...

I have a screen with a vpgrid. I have a vbar. The scroll works quite nicely with:

Code: Select all

vbar value YScrollValue("id of vpgrid")
All is great.
However, once I close this screen I want a variable to remember where I left off. So that next time I don't start from the top again.

Obviously I should add:

Code: Select all

yinitial y
where the default y = 0

And when closing the screen I should somehow set y = current YScrollValue. And that's where I hit the problem.
How do I get the current value? I tried playing around with ui.adjustment and renpy.get_widget(vpid).yadjustment and all sorts of stuff but somehow I can't piece it together. So, any simple and elegant solution where I can add to the action of a button something like:

action Function(make y=current yadjustment(vpgridid))

??

Re: remember YScrollValue

Posted: Fri Oct 23, 2020 4:17 am
by Vladya

Code: Select all

init python:

    _yinitial = .0

screen my_screen:

    hbox:
        align (.5, .5)
        xysize (1280, 720)
        vpgrid id "some_id":
            cols 3
            spacing 30
            yinitial _yinitial
            mousewheel True
            draggable True
            xfill True
            for i in xrange(1337):
                textbutton "{0}".format(i) action Return()
        vbar value YScrollValue("some_id")

    $ yadjustment = renpy.get_widget(None, "some_id").yadjustment
    on "hide" action SetVariable(
        "_yinitial",
        (float(yadjustment.value) / yadjustment.range)
    )

label start:
    while True:
        call screen my_screen
        "Current yinitial is [_yinitial:.2f]."
    return