Hi. I have a fairly large area inside a wxscrolledwindow. I need to be
able to accurately scroll to a specific location so that the view in
the wxscrolledwindow displays a specific location as close to center
as possible, no matter what size the user has the main window set at.
I can do this with the scroll command by working from 0,0, however I
am unable to accurately work out the positions when the main window
(and therefore the wxscrolledwindow clientsize has changed.
Is there some formula that I can use to work out the positions and
relate them via the scroll command?
If you want to scroll to y on the virtual window, then
wnd.Scroll(0, y)
puts y at the top of the client area. To put it in the middle,
scroll to "y - clientHeight / 2 / ppuY" where ppuY is pixels per unit
in the Y-direction, as set up in SetScrollbars. You'll need a
"y not less than 0" check as well, for which I use
y = max(0, y)
Phil
···
On Jul 9, 6:21 am, MaxVK <maximv...@gmail.com> wrote:
Hi. I have a fairly large area inside a wxscrolledwindow. I need to be
able to accurately scroll to a specific location so that the view in
the wxscrolledwindow displays a specific location as close to center
as possible, no matter what size the user has the main window set at.
I can do this with the scroll command by working from 0,0, however I
am unable to accurately work out the positions when the main window
(and therefore the wxscrolledwindow clientsize has changed.
Is there some formula that I can use to work out the positions and
relate them via the scroll command?
Hi. I have a fairly large area inside a wxscrolledwindow. I need to be
able to accurately scroll to a specific location so that the view in
the wxscrolledwindow displays a specific location as close to center
as possible, no matter what size the user has the main window set at.
I can do this with the scroll command by working from 0,0, however I
am unable to accurately work out the positions when the main window
(and therefore the wxscrolledwindow clientsize has changed.
Is there some formula that I can use to work out the positions and
relate them via the scroll command?
Scrolling is done in increments of "scroll units" where scroll units are some number of pixels in the scrolling direction (horizontal or vertical.) The possible range of the scroll is the virtual size in pixels divided by the size of the scroll units, and unless the virtual size is an exact multiple of the scroll units there will be one extra unit to take care of the extra pixels. Each time you click on the up or down buttons in the scroll bar you get one unit's worth of scrolling. A page is however many scroll units will fit in the current client size of the window.
Aha! Thanks very much, thats exactly what I needed to see. Excellent!
regards
Max
···
On Jul 9, 10:22 pm, Phil Mayes <listo...@listomax.com> wrote:
On Jul 9, 6:21 am, MaxVK <maximv...@gmail.com> wrote:
> Hi. I have a fairly large area inside a wxscrolledwindow. I need to be
> able to accurately scroll to a specific location so that the view in
> the wxscrolledwindow displays a specific location as close to center
> as possible, no matter what size the user has the main window set at.
> I can do this with the scroll command by working from 0,0, however I
> am unable to accurately work out the positions when the main window
> (and therefore the wxscrolledwindow clientsize has changed.
> Is there some formula that I can use to work out the positions and
> relate them via the scroll command?
If you want to scroll to y on the virtual window, then
wnd.Scroll(0, y)
puts y at the top of the client area. To put it in the middle,
scroll to "y - clientHeight / 2 / ppuY" where ppuY is pixels per unit
in the Y-direction, as set up in SetScrollbars. You'll need a
"y not less than 0" check as well, for which I use
y = max(0, y)
Thanks Robin. Phil's post showed me the formula I needed to get the
job done, but your post has helped me to understand far more clearly
how the scrolling actually works, particularly the bit about the
relationship between the virtual size and the scroll units.
Cheers
Max
···
On Jul 10, 3:12 am, Robin Dunn <ro...@alldunn.com> wrote:
MaxVK wrote:
> Hi. I have a fairly large area inside a wxscrolledwindow. I need to be
> able to accurately scroll to a specific location so that the view in
> the wxscrolledwindow displays a specific location as close to center
> as possible, no matter what size the user has the main window set at.
> I can do this with the scroll command by working from 0,0, however I
> am unable to accurately work out the positions when the main window
> (and therefore the wxscrolledwindow clientsize has changed.
> Is there some formula that I can use to work out the positions and
> relate them via the scroll command?
Scrolling is done in increments of "scroll units" where scroll units are
some number of pixels in the scrolling direction (horizontal or
vertical.) The possible range of the scroll is the virtual size in
pixels divided by the size of the scroll units, and unless the virtual
size is an exact multiple of the scroll units there will be one extra
unit to take care of the extra pixels. Each time you click on the up or
down buttons in the scroll bar you get one unit's worth of scrolling. A
page is however many scroll units will fit in the current client size of
the window.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org