How adapt wxScrolledWindow in WxSmith?

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

How adapt wxScrolledWindow in WxSmith?

Post by mxoliveira73 »

Hello. I'm trying to adapt an example of wxScrolledWindow in a wxSmith application.

I need a WxPanel scrolled. And i studied in this forum, found this example: https://wiki.wxwidgets.org/Scrolling;

I understand the example. In my application WxSmith Wxwdigets i create one file.h, create a class ScrolledWidgetsPane : public wxScrolledWindow, include in my mainApp.h, and create a ScrolledWidgetsPane inside main Frame. It works. But, i need put the ScrolledWidgetsPane inside any wxPanel which occupies only part of the main Frame. I'm a little bit confused, i'm sorry. I'm a begginer in Wxwidgets... Finally, i don't know how to use the example in my Wxsmith application. How i link, put the class create inside a wxPanel?

How iI did:

//*********________1- create class:__________**********************/////

class ScrolledWidgetsPane : public wxScrolledWindow
{
public:
ScrolledWidgetsPane(wxWindow* parent, wxWindowID id) : wxScrolledWindow(parent, id)
{
// the sizer will take care of determining the needed scroll size
// (if you don't use sizers you will need to manually set the viewport size)
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);

// add a series of widgets
for (int w=1; w<=120; w++)
{
wxButton* b = new wxButton(this, wxID_ANY, wxString::Format(wxT("Button %i"), w));
sizer->Add(b, 0, wxALL, 3);
}

this->SetSizer(sizer);

// this part makes the scrollbars show up
this->FitInside(); // ask the sizer about the needed size
this->SetScrollRate(5, 5);

}

};

//*************************************************///////////////////////////////
//**************___ 2- insert the object inside a Frame:________/////////////


IMPLEMENT_APP(scroll_1App);

bool scroll_1App::OnInit()
{

//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{

scroll_1Frame* Frame = new scroll_1Frame(0);

// **********_______ create object and insert inside a frame____*****

ScrolledWidgetsPane* my_image = new ScrolledWidgetsPane(Frame, wxID_ANY);

Frame->Show();

SetTopWindow(Frame);
}
//*)


return wxsOK;

}
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How adapt wxScrolledWindow in WxSmith?

Post by ONEEYEMAN »

Hi,
Are you trying to modify wxSmith itself or you are using it as a RAD tool to create you GUI layout, etc?

If its the latter - you need to understand that the RAD tool can do only so much to help visualize the layout building and generate SOME code based on this layout.
It can also help with creating the event handler, based on your requirements that you put inside that tool.

However, it is always a good idea not to do that. Create you layout, generate the code, then create your own class as a child of the generated code and add all of your business logic there, i.e. event handlers and everything else. Unless you are proficient enough to modify the generated code on the fly later.

Keeping this in mind - you can't put the example inside the wxSmith application. You can create a layout inside wxSmith application based on the example your referenced and then generate the code as appropriate, but that's about it.

Now if you already created the scrolled window inside your application and satisfied with it - great. Now all you need to do is to re-use this class inside the main frame.
Now I don't know whether the main frame was created with the same wxSmith tool or not, and so can't help you there as the process may be different.

Good luck.

Thank you.
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: How adapt wxScrolledWindow in WxSmith?

Post by mxoliveira73 »

My original interest was just to create in wxSmith. So I tried to adapt the example. Than, forget the example...

How can I create a funcional Scrolled window in WxSmith?

1- drag a scrolledWindow to frame, set HSCROLL and add one button inside it, for example... ok, it seems so simple:

ScrolledWindow1 = new wxScrolledWindow(this, ID_SCROLLEDWINDOW1, wxPoint(104,136), wxSize(2000,400), wxVSCROLL|wxHSCROLL, _T("ID_SCROLLEDWINDOW1"));

Button3 = new wxButton(ScrolledWindow1, ID_BUTTON3, _("Label"), wxPoint(1000,12), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));

But, doesn't work... the scrollbar is not showed...

What is my wrong?
How i Enable scroll bars?

or

2- Simple drag a wxPanel to the frame, set wxHSCROLL;
result:

Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(64,56), wxSize(288,192), wxTAB_TRAVERSAL|wxHSCROLL, _T("ID_PANEL1"));
Button3 = new wxButton(Panel1, ID_BUTTON3, _("Label"), wxPoint(500,500), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));

It seems so simple...

But, scroll bar doesn't work....

What is my wrong?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How adapt wxScrolledWindow in WxSmith?

Post by ONEEYEMAN »

Hi,
Simply put - you can't.
The idea of the wxScrolled<> (or wxScrolledWindow) is to display a big picture (or control, or multiple controls) that doesn't fit inside the space allocated.
Since one button have enough space to be displayed, no scroll bar will be shown.

You need to either create a 100+ (or maybe 50+, or maybe 1000+ - depending on you resolution and font size) buttons or make the window that is parent of the scrolled window so small that it will make the scroll bar appear.

Thank you.
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: How adapt wxScrolledWindow in WxSmith?

Post by mxoliveira73 »

Big thanks, Oneeyeman... it's necessary....
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: How adapt wxScrolledWindow in WxSmith?

Post by mxoliveira73 »

I forget this:


int pixelsPerUnixX = 10;
int pixelsPerUnixY = 10;
int noUnitsX = 1000;
int noUnitsY = 1000;
scrolledWindow->SetScrollbars(pixelsPerUnitX, pixelsPerUnitY,
noUnitsX, noUnitsY);

..........................................
scrolledWindow->SetScrollbars(pixelsPerUnitX, pixelsPerUnitY,
noUnitsX, noUnitsY);

was the solution
..........................................
basic.. but i don't knew....

I hope that can help other beginners to....
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How adapt wxScrolledWindow in WxSmith?

Post by ONEEYEMAN »

Hi,
This sounds more like a hack.
Please re-read what I wrote above.

I think you just need a basic wxPanel(), especially if you plan to show just one button.

Thank you.
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: How adapt wxScrolledWindow in WxSmith?

Post by mxoliveira73 »

ONEEYEMAN, I'm sorry . The mistake was all mine. I really appreciate your help.
Post Reply