PDA

View Full Version : getScrollState not working



Foen
September 13th, 2009, 08:08
I'm trying to use getScrollState within a windowlist to scroll automatically to a saved position when the list is first shown. I am therefore calling getScrollState from the windowlist onInit handler, but it returns only zero values (six of them).

At the point it is called, the windowlist has been set to show only four items, but contains many more.

Help!

Stuart

Foen
September 13th, 2009, 08:24
Ignoring the first issue, calling setScrollPosition from within the windowlist onInit handler seems to do nothing. I am passing zero as the first parameter and a number of pixels as the second parameter, where the pixel count is the row I want displayed at the top, multiplied by the expected row height of each list item.

Stuart

Foen
September 13th, 2009, 08:26
Is this perhaps to do with the fact that other windowcontrol size properties aren't available to windowlists? getSize has always returned zero for me during windowlist onInit handlers, for example.

Goblin-King
September 13th, 2009, 18:36
I will investigate, but I am almost certain this is due to a feature of the engine that makes it also hard to fire subwindow instantiation events by the time the window onInit is called. Basically, the content initialization is not entirely complete at that point. For now, this is probably working as intended

As a workaround, I would suggest you monitor the scoll update event, and respond to that by scrolling, either after it is non-zero, or persistently, depending on the usage. Let me know if you can't get it to work.

Bidmaron
September 14th, 2009, 09:24
Boy, I have wished subwindow instantiation happened before onInit so many times. Is it too much to ask for a new event, say AfterInit, that you could use after the initialization of subobjects has been completed?

Foen
September 14th, 2009, 23:07
Does the scroll update event fire after instantiation, even if the scroller isn't moved? If so, that would work. If not, then I won't be able to display the last selected item on window initialisation.

By way of context, I'm trying to recreate something like a selection list, where you click on an item in the list to select the field value (see attached picture). In the example there are about a dozen elements in the list, and the user can click on any one of them. Next time the window is opened, it would be great to display the last selected item. I can make it selected, but just can't make the windowlist scroll to the correct position to make it visible.

Stuart

Foen
September 15th, 2009, 21:31
OK, an update on this issue, which may also help Bidmaron and others.

It seems a windowlist fires onScroll during its initialisation a number of times after onInit (I can see three events in my test ruleset) and that these occur at different stages of instantiation.

By setting an event handler during onInit to catch onScroll, it is possible to trigger code *after* the instantiation is complete. For me, that means I can use the getScrollState etc methods to pre-position the list. For Bidmaron and others, it means that general code can be invoked after initialisation.

To prevent future onScroll events re-triggering this activity, the onScroll handler must be reset. Clearly you wouldn't do this if you wanted to continue handling onScroll (such as the scrollbar template), just if you are trying to achieve something else.

Here is some sample code:


Within a windowlist script block:
function onInit()
...
self.onScroll = checkinit;
...
end

function checkinit()
local sx,px,vx,sy,py,vy = getScrollState();
if sx==0 and sy==0 then
return; --[[ not instantiated yet ]]
end
--[[ disable the handler ]]
self.onScroll = function () end;
--[[ call any code ]]
if self.afterInit then
self.afterInit();
end
end

function afterInit()
...
do whatever
...
end

Hope that helps

Stuart