The division of Windows into the work areas

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

The division of Windows into the work areas

Post by CnnC »

Good day!

Tried to do in one window (wxFrame) two zones: the first (upper) zone is the table grid (wxFlexGridSizer) with progressive filling of the elements (e.g., wxStaticText, wxTextCtrl), the second (bottom) is by push-button (wxButton). The difficulty lies in the fact that the first zone can be scrolled sideways, and the second would always be in place (not shifted).

Tried to implement this way:

Code: Select all

/*...block_1...*/
wxPanel *panel_main = new wxPanel(this, -1);
wxScrolledWindow *panel_1 = new wxScrolledWindow(panel, -1);
wxPanel *panel_2 = new wxPanel(panel, -1);
panel_1->FitInside();
panel_1->SetScrollRate(5, 5);
/*...block_2...*/
wxBoxSizer *vbox_main = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox_buttons = new wxBoxSizer(wxHORIZONTAL);
/*...block_3...*/
wxFlexGridSizer *gridsizer = new wxFlexGridSizer(1);
/*Next, the grid sizer cells are filled in line by line */
/*After being filled with xbox_buttons buttons*/
/*Now vertically group elements gridsizer and hbox_buttons*/
vbox_main ->Add(gridsizer);
vbox_main ->Add(hbox_buttons );
/*...block_4...*/
panel->SetSizer(vbox_main );
panel_1 ->SetSizer(gridsizer);
panel_2 ->SetSizer(hbox_buttons);
/*...block_X...*/
Ultimately, nothing worked. I so understood that wxPanel and wxScrolledWindow something like layers, bases where the first "statin", and in the second it is possible to add scrolling. Further, they are different elements, and it is here that wxBoxSizer and wxFlexGridSizer, which relate to each other. But wxPanel and wxScrolledWindow are superimposed on each other, as if devoid of a skeleton, not having bindings to the elements contained in them.

Perhaps, help to understand the situation.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The division of Windows into the work areas

Post by ONEEYEMAN »

Hi,
Could you attach a screenshot or a sketch of what you are after?

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The division of Windows into the work areas

Post by CnnC »

Thank you for the answer.

For example, in this example, the text and buttons are on the same scroll bar. How to make the buttons always remain at the bottom, but only the text scrolls?

Code: Select all

#include <wx/wx.h>

class MyApp : public wxApp
{
public:
	virtual bool OnInit();
};

class MyWindow : public wxFrame
{
public:
    MyWindow(
        wxWindow *parent, 
        wxWindowID id, 
        const wxString &title, 
        const wxPoint &pos, 
        const wxSize &size
    ) : wxFrame(
        parent,
        id,
        title,
        pos,
        size
    ) {
        wxScrolledWindow *scrolled_panel = new wxScrolledWindow(this, wxID_ANY);
        wxBoxSizer *vbox_main = new wxBoxSizer(wxVERTICAL);
        wxBoxSizer *hbox_buttons = new wxBoxSizer(wxHORIZONTAL);
        wxFlexGridSizer *grid_sizer = new wxFlexGridSizer(1);
        
        for (int j = 0; j < 100; j++)
        {
            wxStaticText *static_text = new wxStaticText(scrolled_panel, wxID_ANY, wxString::Format(wxT("Text %i"), j+1));
            grid_sizer->Add(static_text);
        }
        
        for (int j = 0; j < 6; j++)
        {
            wxButton *button = new wxButton(scrolled_panel, wxID_ANY, wxString::Format(wxT("Button %i"), j));
            hbox_buttons->Add(button);
        }
        
        vbox_main->Add(grid_sizer);
        vbox_main->Add(hbox_buttons);
        
        scrolled_panel->SetSizer(vbox_main);
        
        scrolled_panel->FitInside();
        scrolled_panel->SetScrollRate(5, 5);
    }
};

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyWindow *window = new MyWindow(NULL, wxID_ANY, wxT("Example 1"), 
        wxDefaultPosition, wxDefaultSize );
    window->Show(true);    
    return true;
}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: The division of Windows into the work areas

Post by PB »

CnnC wrote:How to make the buttons always remain at the bottom, but only the text scrolls?
I did not read the thread thoroughly, but if you do not with something to scroll, do not add it to the (same) wxScrolled.

See e.g. the code here viewtopic.php?f=19&t=44435#p183153
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The division of Windows into the work areas

Post by CnnC »

Thank you.
See e.g. the code here viewtopic.php?f=19&t=44435#p183153
Your example looks like what I need. Only it is based on wxDialog, for which there are only certain buttons (CreateStdDialogButtonSizer). I tried to make wxFrame, on top of which there is a section with scrolling, and at the bottom there are arbitrary buttons.

Tried to do so, but failed:

Code: Select all

#include <wx/wx.h>

class MyApp : public wxApp
{
public:
	virtual bool OnInit();
};

class MyWindow : public wxFrame
{
public:
    MyWindow(
        wxWindow *parent, 
        wxWindowID id, 
        const wxString &title, 
        const wxPoint &pos, 
        const wxSize &size
    ) : wxFrame(
        parent,
        id,
        title,
        pos,
        size
    ) {
        wxPanel *panel = new wxPanel(this, wxID_ANY);
        wxScrolledWindow *scrolled_panel = new wxScrolledWindow(panel, wxID_ANY);
        wxBoxSizer *vbox_main = new wxBoxSizer(wxVERTICAL);
        wxBoxSizer *hbox_buttons = new wxBoxSizer(wxHORIZONTAL);
        wxFlexGridSizer *grid_sizer = new wxFlexGridSizer(1);
        
        for (int j = 0; j < 100; j++)
        {
            wxStaticText *static_text = new wxStaticText(panel, wxID_ANY, wxString::Format(wxT("Text %i"), j+1));
            grid_sizer->Add(static_text);
        }
        
        for (int j = 0; j < 6; j++)
        {
            wxButton *button = new wxButton(panel, wxID_ANY, wxString::Format(wxT("Button %i"), j));
            hbox_buttons->Add(button);
        }
        
        
        scrolled_panel->SetSizer(grid_sizer);
        
        vbox_main->Add(scrolled_panel);
        vbox_main->Add(hbox_buttons);
        
        panel->SetSizer(vbox_main);
        
        scrolled_panel->FitInside();
        scrolled_panel->SetScrollRate(5, 5);
    }
};

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyWindow *window = new MyWindow(NULL, wxID_ANY, wxT("Example 1"), 
        wxDefaultPosition, wxDefaultSize );
    window->Show(true);    
    return true;
}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: The division of Windows into the work areas

Post by PB »

I think there are at least two issues with your code:
1. You need to create static texts with scrolled_panel as their parent.
2. You should add wxEXPAND parameter when adding scrolled_panel to the main sizer.

This code with those two changes from above seems to be basically working, aside from needing some polishing (adding borders around controls /sizers etc.):

Code: Select all

wxPanel *panel = new wxPanel(this, wxID_ANY);
        wxScrolledWindow *scrolled_panel = new wxScrolledWindow(panel, wxID_ANY);
        wxBoxSizer *vbox_main = new wxBoxSizer(wxVERTICAL);
        wxBoxSizer *hbox_buttons = new wxBoxSizer(wxHORIZONTAL);
        wxFlexGridSizer *grid_sizer = new wxFlexGridSizer(1);

        for (int j = 0; j < 100; j++)
        {
            wxStaticText *static_text = new wxStaticText(scrolled_panel, wxID_ANY, wxString::Format(wxT("Text %i"), j+1));
            grid_sizer->Add(static_text);
        }

        for (int j = 0; j < 6; j++)
        {
            wxButton *button = new wxButton(panel, wxID_ANY, wxString::Format(wxT("Button %i"), j));
            hbox_buttons->Add(button);
        }


        scrolled_panel->SetSizer(grid_sizer);

        vbox_main->Add(scrolled_panel, 1, wxEXPAND);
        vbox_main->Add(hbox_buttons);

        panel->SetSizer(vbox_main);

        scrolled_panel->FitInside();
        scrolled_panel->SetScrollRate(5, 5);
scrolledframe.png
scrolledframe.png (21.41 KiB) Viewed 1062 times
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The division of Windows into the work areas

Post by CnnC »

Thank you very much! Amazingly, that's what was needed. Once again thank you for helping to understand!
Post Reply