Layout in a scrolled window Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Layout in a scrolled window

Post by ONEEYEMAN »

Hi, ALL,
I have a weird problem.
I just tried to test one of my dialogs on OSX.
I know it ws working fine on Windows (8.1).

The screenshot attached is from the OSX 10.13 and wx latest release.

This suppose to be a scrolled vertically window without the horizontal scrollbar.

The code I'm using is as follows:

Code: Select all

RetrievalArguments::RetrievalArguments()
{
   numArgs = 1;
    m_currentLine = 0;
    m_type = dbType;
    m_subType = subType;
    sizer = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *sizer_6 = new wxBoxSizer( wxVERTICAL );
    m_panel = new wxPanel( this, wxID_ANY );
    m_ok = new wxButton( m_panel, wxID_OK, _( "OK" ) );
    m_cancel = new wxButton( m_panel, wxID_CANCEL, _( "Cancel" ) );
    m_help = new wxButton( m_panel, wxID_HELP, _( "Help" ) );
    m_add = new wxButton( m_panel, wxID_ANY, _( "Add" ) );
    m_insert = new wxButton( m_panel, wxID_ANY, _( "Insert" ) );
    m_remove = new wxButton( m_panel, wxID_ANY, _( "Delete" ) );
    wxStaticBoxSizer *main_sizer = new wxStaticBoxSizer( wxVERTICAL, m_panel, _( "Arguments" ) );

    argPanel = new wxPanel( main_sizer->GetStaticBox(), wxID_ANY );
    m_labe11 = new wxStaticText( argPanel, wxID_ANY, "Position", wxPoint( 4,4)  );
    m_label2 = new wxStaticText( argPanel, wxID_ANY, "Name", wxPoint( 40,4 ) );
    m_label3 = new wxStaticText( argPanel, wxID_ANY, "Type", wxPoint( 48,4 ) );

    main_sizer->Add( argPanel, 0, wxEXPAND | wxBOTTOM, 4 );

    args = new wxScrolledWindow( main_sizer->GetStaticBox(), wxID_ANY );

    bmp = wxBitmap::NewFromPNGData( arguments_pointer_png, WXSIZEOF( arguments_pointer_png ) );

    fgs = new wxFlexGridSizer( 4, 0, 0 );
    dummy_1 = new wxPanel( args, wxID_ANY, wxDefaultPosition, wxSize( 1, 1 ) );
    dummy_2 = new wxPanel( args, wxID_ANY, wxDefaultPosition, wxSize( 1, 1 ) );
    dummy_3 = new wxPanel( args, wxID_ANY, wxDefaultPosition, wxSize( 1, 1 ) );
    dummy_4 = new wxPanel( args, wxID_ANY, wxDefaultPosition, wxSize( 1, 1 ) );
    fgs->Add( dummy_1 );
    fgs->Add( dummy_2 );
    fgs->Add( dummy_3 );
    fgs->Add( dummy_4 );

    wxString pos;
    for( std::vector<QueryArguments>::iterator it = arguments.begin(); it < arguments.end(); ++it )
    {
        pos.Printf("%d", (*it).m_pos );
        wxStaticBitmap *statBmp = new wxStaticBitmap( args, wxID_ANY, bmp );
        wxStaticText *number = new wxStaticText( args, wxID_ANY, pos, wxDefaultPosition, wxSize( 30, -1 ), wxALIGN_CENTRE_HORIZONTAL | wxBORDER_SUNKEN );
        wxTextCtrl *name = new wxTextCtrl( args, wxID_ANY, (*it).m_name );
        name->Bind( wxEVT_KEY_DOWN, &RetrievalArguments::OnKeyDown, this );
        name->Bind( wxEVT_LEFT_DOWN, &RetrievalArguments::OnMouse, this );
        name->Bind( wxEVT_RIGHT_DOWN, &RetrievalArguments::OnMouse, this );
        TypeComboBox *type = new TypeComboBox( args, dbType.ToStdWstring(), subType.ToStdWstring(), (*it).m_type.ToStdString() );
        type->Bind( wxEVT_LEFT_DOWN, &RetrievalArguments::OnMouse, this );
        type->Bind( wxEVT_RIGHT_DOWN, &RetrievalArguments::OnMouse, this );
        fgs->Add( statBmp, 0, wxEXPAND | wxRIGHT | wxLEFT, 8 );
        fgs->Add( number, 0, wxRIGHT, 8 );
        fgs->Add( name, 1, wxEXPAND | wxRIGHT, 8 );
        fgs->Add( type, 0, wxEXPAND | wxRIGHT, 8 );
        m_lines.push_back( QueryLines( statBmp, number, name, type ) );
        m_lines.back().m_name->SetFocus();
        m_currentLine++;
    }
    numArgs = arguments.size();
    fgs->AddGrowableCol( 2 );

    args->SetSizer( fgs );
    args->SetScrollRate( 15, 15 );

    wxSize minsize = fgs->CalcMin();
    minsize.x += wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y );
    minsize.y = -1;
    args->SetMinClientSize( minsize );;

    main_sizer->Add( args, 1, wxEXPAND, 0 );
    sizer->Add( main_sizer, 1, wxEXPAND, 0 );
    sizer->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_6->Add( m_ok, 0, wxEXPAND, 0 );
    sizer_6->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_6->Add( m_cancel, 0, wxEXPAND, 0 );
    sizer_6->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_6->Add( m_help, 0, wxEXPAND, 0 );
    sizer_6->Add( 20, 20, 0, wxEXPAND, 0 );
    sizer_6->Add( m_add, 0, wxEXPAND, 0 );
    sizer_6->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_6->Add( m_insert, 0, wxEXPAND, 0 );
    sizer_6->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_6->Add( m_remove, 0, wxEXPAND, 0 );
    sizer->Add( sizer_6, 0, wxEXPAND | wxRIGHT, 0 );
    m_panel->SetSizer( sizer );
    sizer->SetSizeHints( this );
    Layout();
    m_panel->Bind( wxEVT_SIZE, &RetrievalArguments::OnSize, this );
    CallAfter( &RetrievalArguments::UpdateHeader );
}

void RetrievalArguments::OnSize(wxSizeEvent &event)
{
    UpdateHeader();
    event.Skip();
}

void RetrievalArguments::UpdateHeader()
{
    m_label2->SetPosition( wxPoint( dummy_3->GetPosition().x, -1 ) );
    m_label3->SetPosition( wxPoint( dummy_4->GetPosition().x, -1 ) );
}
It looks like on OSX the layout of the scrolled window is not done correctly.

Does anyone have an idea how to make it work?

I just want to get rid of the horizontal scrollbars and display all controls in that panel.

Thank you.
Attachments
Screen Shot 2021-07-10 at 9.38.31 PM.png
Screen Shot 2021-07-10 at 9.38.31 PM.png (12.2 KiB) Viewed 4459 times
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Layout in a scrolled window

Post by doublemax »

When i look at the control creation, i don't see anything after "type". What do you get when you scroll to the right, just empty space?

Code: Select all

    wxSize minsize = fgs->CalcMin();
    minsize.x += wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y );
    minsize.y = -1;
    args->SetMinClientSize( minsize );;
Do you get the correct width here?
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
Attached is a screenshot from scrolling to the right.
And I don't know how to check for the proper size.

But maybe I don't need this piece of code at all?

Thank you.
Attachments
Screen Shot 2021-07-11 at 11.43.25 AM.png
Screen Shot 2021-07-11 at 11.43.25 AM.png (15.03 KiB) Viewed 4422 times
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Layout in a scrolled window

Post by doublemax »

And I don't know how to check for the proper size.
Increase the window size manually until the scrollbar disappears. That's the width you *should* get from that calculation. This is to find out whether the min size calculation fails, or if the issue is caused by something else.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
I can't.
This piece is inside the wxPanel, which is inside wxDialog. And the dialogs do not support resizing...

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
I removed that piece of code, but nothing changed.

Any other idea to try?

Thank you.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Layout in a scrolled window

Post by doublemax@work »

I still suspect that fgs->CalcMin() returns a too small value. If you can't resize the dialog, maybe just compare the returned width to the dialog width.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
Attached is a GTK (3) version of that dialog.
This one looks good.

Thank you.
GTK version.png
GTK version.png (13.02 KiB) Viewed 3635 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
And this is MSW version, which looks a little long.
So only GTK version looks right apparently.

Thank you.
Attachments
Windows version.PNG
Windows version.PNG (7.79 KiB) Viewed 3635 times
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Layout in a scrolled window

Post by doublemax »

That seems to be a different issue though. Before we were talking about the width and the scrollbar. What did you do to fix that?
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
I didn't do anything.
I just tried to compare all 3 platforms.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Layout in a scrolled window

Post by doublemax »

As i can't test under OSX, i don't know how i can help to debug this for you.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
I understand.
But windows is also wrong. Maybe fixing it will help with OSX...
Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Layout in a scrolled window

Post by doublemax »

Can you try to extract that dialog code into a small, compilable sample?
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Layout in a scrolled window

Post by ONEEYEMAN »

doublemax,
Attached is the code for the dialog.

Should be building.
Attachments
retrievalarguments.h
(1.71 KiB) Downloaded 79 times
retrievalarguments.cpp
(12.83 KiB) Downloaded 81 times
Post Reply