Page 1 of 1

wxToolBar and wxTB_BOTTOM - dead space?

Posted: Tue May 05, 2020 1:37 pm
by USB3pt0
Hi,

I'm trying to make a toolbar and put it at the bottom of the frame. The code was generated with wxFormBuilder which shows the toolbar directly under the menu bar, however when compiled and ran in VS2012, it's at the bottom of the window as it should be.

However, it still leaves a blank space the size of the toolbar immediately below the menu bar. On maximizing the window, the space grabs some of the MainMenu text as well as leaving blank space on the left and right of it, the color of the window. A picture is attached.
wxWidgets toolbar error.PNG
The code that generates the toolbar is as follows:

Code: Select all

m_scanSelectToolbar = this->CreateToolBar( wxTB_BOTTOM|wxTB_HORIZONTAL|wxBORDER_RAISED, wxID_SCANSELECTTOOLBAR );
	m_scanSelectToolbar->SetToolSeparation( 0 );
	m_scanSelectToolbar->SetToolPacking( 0 );
	m_scanSelectToolbar->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
I'm not sure what to do regarding getting rid of that empty space. The general layout of the window is Menu Bar, Sizer, panels in sizer, then Toolbar. I've tried having it recalculate the layout but nothing seemed to make a difference.

Re: wxToolBar and wxTB_BOTTOM - dead space?

Posted: Tue May 05, 2020 2:39 pm
by PB
I can confirm the bug on Win10 with wxWidgets master. I was sure I already saw it reported and fixed long time ago but could not find that.

It seems that at least on my setup, it can be worked around: setting the wxTB_BOTTOM style flag again after the toolbar was created:

Code: Select all

#include <wx/wx.h>
#include <wx/artprov.h>

// define to 1 to work around the empty space bug
#define TB_AT_BOTTOM_HACK 1

class MainFrame2 : public wxFrame
{
public:
    MainFrame2(wxWindow* parent) : wxFrame(parent, wxID_ANY, "Test")
    {
        wxMenuBar* menuBar = new wxMenuBar();
        menuBar->Append(new wxMenu(), "File");
        SetMenuBar(menuBar);

        (new wxPanel(this))->SetBackgroundColour(*wxRED);

        wxToolBar* toolBar = CreateToolBar(wxTB_BOTTOM | wxTB_HORIZONTAL);
        toolBar->AddTool(wxID_ANY, "", wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_TOOLBAR));
        toolBar->Realize();
#if TB_AT_BOTTOM_HACK
        toolBar->SetWindowStyleFlag(wxTB_BOTTOM);
        toolBar->Realize();
#endif
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MainFrame2(nullptr))->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
EDIT
I noticed that the issue goes away when CreateToolBar() is called without wxTB_HORIZONTAL flag set. This flag is default so there is no difference in toolbar appeareance. I will investigate further or at least create a ticket.

Re: wxToolBar and wxTB_BOTTOM - dead space?

Posted: Tue May 05, 2020 3:12 pm
by USB3pt0
Yeah, that fixed it and it looks the same. Thanks, hope it's an easy fix for the coders.

Re: wxToolBar and wxTB_BOTTOM - dead space?

Posted: Tue May 05, 2020 3:55 pm
by PB
I have created the ticket, so...
https://trac.wxwidgets.org/ticket/18760

EDIT
The issue is fixed in the development branch:
https://github.com/wxWidgets/wxWidgets/ ... 9306f329bd