So, I have a "ResultCanvas" derived from wxScrolledWindow, and I'm trying to get it to scroll when the output is too large for the given frame size.
But I really have no idea how to do it! And my code is too large to paste into the forum.
Also, I'm using wxAutoBufferedPaintDC to do the drawing (which solved my flickering issue).
Any tips? Thanks!
How to implement scrolling?
Re: How to implement scrolling?
It's unclear where you're stuck. The most important part is to call SetScrollbars() to define the virtual size and the scrollsteps.
https://docs.wxwidgets.org/trunk/classw ... 4a8e1210bb
That should already give you the scrollbars and the option to scroll the window.
https://docs.wxwidgets.org/trunk/classw ... 4a8e1210bb
That should already give you the scrollbars and the option to scroll the window.
Use the source, Luke!
Re: How to implement scrolling?
Wow! Thanks!! This has been on my to-do list for ages now, and you solved it with one line of code:
which I put in my constructor for ResultCanvas.
In quick testing it seems to work perfectly.
Edit: OK. I tested it on a larger example, and it is not 100% correct. It scrolls enough to display like a page and 3/4, but after that it just chomps the file. In fact, in total, even when scrolled all the way down, it is only showing half what it should be.
Code: Select all
SetScrollbars(20, 20, 50, 50);
In quick testing it seems to work perfectly.
Edit: OK. I tested it on a larger example, and it is not 100% correct. It scrolls enough to display like a page and 3/4, but after that it just chomps the file. In fact, in total, even when scrolled all the way down, it is only showing half what it should be.
Re: How to implement scrolling?
What exactly are you displaying and how do you calculate the virtual size of the content?
Use the source, Luke!
Re: How to implement scrolling?
I'm basically displaying clickable text at this point, but later plan to add in images and such.
Anyway, your post was enough for me to solve it. With a little googling, I found my way to:
I added this to the end of my Draw() method, and now it works correctly, even for the larger example.
Though I suspect my choice for width might not be quite correct, and I might need to use std::max() of all the widths used in the Draw() method.
Anyway, your post was enough for me to solve it. With a little googling, I found my way to:
Code: Select all
void wxWindow::SetVirtualSize(int width, int height)
Though I suspect my choice for width might not be quite correct, and I might need to use std::max() of all the widths used in the Draw() method.
Re: How to implement scrolling?
Doing that in the Draw() method doesn't seem right, as it could lead to permanent redraws. You should only call it when the virtual size changes.
Use the source, Luke!
Re: How to implement scrolling?
Thanks for the tip!
So I shifted it from the end of Draw() to InsertNewLine() and InsertLine() (the first is a line feed, the second is a horizontal line).
Also, I did have to use
to handle long lines correctly.
And then in InsertNewLine() and InsertLine()
Anyway, it is now all working. Thanks for the help!
So I shifted it from the end of Draw() to InsertNewLine() and InsertLine() (the first is a line feed, the second is a horizontal line).
Also, I did have to use
Code: Select all
m_max_x = std::max(m_max_x, m_x)
And then in InsertNewLine() and InsertLine()
Code: Select all
SetVirtualSize(m_max_x, m_y)