StatusBar in Windows-Linux systems 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.
Post Reply
User avatar
Dawix
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Jul 26, 2017 3:28 pm
Location: Lombardy, Italy
Contact:

StatusBar in Windows-Linux systems

Post by Dawix »

Dear all,
I wrote this "Hello-world" code in order to study the wxWidgets under cross-compilation (Windows/Linux):

Code: Select all

bool GuiCtrl::OnInit()
{
	m_controlwindow = new wxFrame(NULL, wxID_ANY, "Driver Control Panel", wxDefaultPosition, wxSize(600, 600));
	m_controlwindow->CreateStatusBar(2);
	m_controlwindow->SetStatusText("Welcome to wxWidgets!");
	m_controlwindow->SetBackgroundColour(wxColour(*wxBLUE));
	m_controlwindow->Show();

	m_controlpanel = new wxPanel(m_controlwindow, wxID_ANY, wxDefaultPosition, wxSize(200, 200));
	m_controlpanel->SetBackgroundColour(wxColour(*wxRED));
	m_controlpanel->CenterOnParent(wxBOTH);

	m_controlwindow->Update();
	m_quitbutton = new wxButton(m_controlpanel, wxID_EXIT,"", wxDefaultPosition);
	m_quitbutton->Bind(wxEVT_BUTTON, &GuiCtrl::onQuit, this);
	m_quitbutton->CenterOnParent(wxBOTH);
	m_quitbutton->Show();
	m_controlwindow->Update();

	return true;
}
Unfortunately I obtain different behaviors when I run it under MS Windows 10 and CentOS 7 + MWM (both @64bit):
MS Windows 10
win_statusbar.jpg
win_statusbar.jpg (22.71 KiB) Viewed 1266 times
CentOS 7 + MWM (Gtk 3.14.13)
linux_statusbar.jpg
linux_statusbar.jpg (28.98 KiB) Viewed 1266 times
I have no problem in compilation. The only way to solve the problem in MS Windows 10 is not use the status bar. As a matter of fact, if I remove the two lines:

Code: Select all

	m_controlwindow->CreateStatusBar(2);
	m_controlwindow->SetStatusText("Welcome to wxWidgets!");
I obtain this:
win_statusbar2.jpg
win_statusbar2.jpg (21.24 KiB) Viewed 1266 times
Thank you in advance!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: StatusBar in Windows-Linux systems

Post by doublemax »

Actually the image with the "full red" background is the only correct one. If a wxFrame has exactly one child, this child should automatically fill the whole client size.

Additionally, using CenterOnParent() is not really a good choice, as it relies on the current size of the windows and will not adjust the layout when the outer frame is resized. The proper way to center a window inside another one would be to use sizers.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: StatusBar in Windows-Linux systems

Post by ONEEYEMAN »

Hi,
Just to add to doublemax' response:

The size of the window on *nix is not known prior to the window being completely rendered. In Windows this is not correct - the size of the window is known when the window type is registered and the object is created.

Therefore you need to use sizers to achieve the same screenshots on both platforms.

Thank you.
User avatar
Dawix
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Jul 26, 2017 3:28 pm
Location: Lombardy, Italy
Contact:

Re: StatusBar in Windows-Linux systems

Post by Dawix »

Thank you doublemax and ONEEYEMAN for the useful infos! I modified my code as follows:

Code: Select all

bool GuiCtrl::OnInit()
{
	m_controlwindow = new wxFrame(NULL, wxID_ANY, "Driver Control Panel", wxDefaultPosition, wxSize(600, 600));
	m_controlwindow->CreateStatusBar(2);
	m_controlwindow->SetStatusText("Welcome to wxWidgets!");

	m_controlpanel = new wxPanel(m_controlwindow, wxID_ANY, wxDefaultPosition);
	m_controlpanel->SetBackgroundColour(wxColour(*wxBLUE));

	m_mainpanel = new wxPanel(m_controlpanel, wxID_ANY, wxDefaultPosition, wxSize(200, 200));
	m_mainpanel->SetBackgroundColour(wxColour(*wxRED));

	m_mainpanelsizerv = new wxBoxSizer(wxVERTICAL);
	m_mainpanelsizerh = new wxBoxSizer(wxHORIZONTAL);
	m_mainpanelsizerv->Add(m_mainpanelsizerh, 1, wxALIGN_CENTER_HORIZONTAL);
	m_mainpanelsizerh->Add(m_mainpanel, 0, wxALIGN_CENTER_VERTICAL);
	m_controlpanel->SetSizer(m_mainpanelsizerv);

	m_quitbutton = new wxButton(m_mainpanel, wxID_EXIT, "", wxDefaultPosition);
	m_quitbutton->Bind(wxEVT_BUTTON, &GuiCtrl::onQuit, this);
	m_quitbutton->CenterOnParent(wxBOTH);

	m_controlwindow->Show();

	return true;
}
solved.jpg
and now the results is perfect in both platforms. I will training myself with sizers... a powerful tool (!) also if in my case, probably, the GUI will be full-screen and with fixed resolution. I'm I'm enjoying wxWidgets and the forum support is great! Thanks 4 all guys!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: StatusBar in Windows-Linux systems

Post by ONEEYEMAN »

Hi,
Sizers are very powerful.
In addition to the official documentation there are multiple tutorial written for newcomers and some other people to better understand the idea.
I don't have the links at hand but you can easily google it.

Thank you.
Post Reply