Is it possible to draw a part of wxScrolledWindow unscrolled?

32 views
Skip to first unread message

PB

unread,
Apr 11, 2021, 8:27:17 AM4/11/21
to wx-users
Hi,

I'd like to know whether it is possible to draw a part of a wxScrolledWindow unscrolled (aside from using multiple windows as AFAIK e.g. wxGrid does). For example, having a bitmap background or a logo which always stays at the same position relative to the window position, regardless of how the window content is scrolled.

A simplified example code can be found here: https://gist.github.com/PBfordev/734fb2bc3cdedd5d8254bbb922cc985a, where a bitmap logo is supposed to be always drawn at the top left corner of a window.

At least on MS Windows (seems to work fine in Ubuntu under VirtualBox), the drawing is not correct. I think it is because how Windows optimizes scrolled drawing by reusing already drawn parts of the window and redrawing only the newly uncovered parts.

I tried calling wxScrolled::EnableScrolling(false, false) but this is obviously wrong, as the controls do not change their position when the window is scrolled; their position changes only after the window is resized.

Is there is a (simple) way to do that or not?

Regards,
PB

Vadim Zeitlin

unread,
Apr 11, 2021, 9:41:04 AM4/11/21
to wx-u...@googlegroups.com
On Sun, 11 Apr 2021 05:27:17 -0700 (PDT) PB wrote:

P> I'd like to know whether it is possible to draw a part of a wxScrolledWindow
P> unscrolled (aside from using multiple windows as AFAIK e.g. wxGrid does).

What's wrong with doing it like this? I think this is the only (and hence
also the best) way to do it with wxScrolledWindow.

With wxWindow itself you could do it differently, by using ScrollWindow()
with a smaller rectangle, I guess, but this would be significantly more
complicated.

P> Is there is a (simple) way to do that or not?

I think using the "target" window, as wxGrid does, is a pretty simple way
of doing this.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

PB

unread,
Apr 11, 2021, 10:04:54 AM4/11/21
to wx-users
Thanks for the quick reply Vadim.

TBH, I still do not understand how to do that, as in the case I outlined the "unscrollable" part of the window (i.e., the logo in the corner or bitmap window background) is inside the scrolled part, similarly to using HTML element with its position property set to fixed. Now reading this, I should probably have used a different word than "unscrollable", for example stickied or something similar.

This is different from wxGrid, where the row and column headers are separate from the actual scrollable rectangular part of the window.

But it is not that important, I asked more out of curiosity, based on a question in wxForum.

Regards,
PB

Vadim Zeitlin

unread,
Apr 11, 2021, 10:10:54 AM4/11/21
to wx-u...@googlegroups.com
On Sun, 11 Apr 2021 07:04:54 -0700 (PDT) PB wrote:

P> TBH, I still do not understand how to do that, as in the case I outlined
P> the "unscrollable" part of the window (i.e., the logo in the corner or
P> bitmap window background) is inside the scrolled part, similarly to using
P> HTML element with its position property set to fixed.

This can't be done at all using just ScrollWindow(), I'm afraid. To be
honest, I'm not sure how should scrolling be implemented efficiently
nowadays, i.e. whether it's actually still important to scroll the existing
window contents or if it's better to just refresh it entirely. I suspect it
could well be the latter and wx scrolling model (based on the APIs dating
from 40 years ago) is not appropriate at all any more...
Reply all
Reply to author
Forward
0 new messages