Page 1 of 1

SetSizeAndFit() squishes widgets and ignores style flags

Posted: Fri May 13, 2016 9:07 am
by Schala
I'm trying to make a simple window that has a horizontal series of 32x32 buttons with icons in them but no text, and a status bar. It is not supposed to be maximised or resized.

This is an example of what I'm trying to accomplish:
Image

I used a horizontal box sizer to save on effort of explicitly setting the window size myself, but SetSizeAndFit() seems not only to squish the buttons into miniscule dots with the icons clipping, but the style flags for the window itself are suddenly ignored.

I'm currently using GCC 6.1.1 with my Linux distro's wxGTK 3.0.2 (Arch Linux x64). I'm also compiling in the C++14 dialect. I attempted to compile using MSVC 2015 and wxMSW 3.1 monolithic DLL, but I have compiling issues unrelated to this issue regarding that.

Code: Select all

enum
{
	ID_CONNECT = 1,
	ID_FILES,
	ID_USERLIST,
	ID_CHAT,
	ID_BROADCAST,
	ID_NEWS,
	ID_SERVERINFO,
	ID_TRANSFERS,
	ID_PROFILE,
	ID_TRACKERS,
	ID_BOOKMARKS,
	ID_PREFS,
	ID_BUGREPORT
};

CLToolbar::CLToolbar(): wxFrame(nullptr, wxID_ANY, "Chatline", wxDefaultPosition,
	wxDefaultSize, wxFRAME_TOOL_WINDOW | wxCAPTION | wxMINIMIZE_BOX | wxCLOSE_BOX | wxSTAY_ON_TOP)
{
	wxImage::AddHandler(new wxXPMHandler);
	auto sizer = new wxBoxSizer(wxHORIZONTAL);

	files_btn = new wxButton(this, ID_FILES, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	files_btn->SetBitmap(wxBitmap(wxT("../icons/files.xpm")));
	ulist_btn = new wxButton(this, ID_USERLIST, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	ulist_btn->SetBitmap(wxBitmap(wxT("../icons/users.xpm")));
	chat_btn = new wxButton(this, ID_CHAT, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	chat_btn->SetBitmap(wxBitmap(wxT("../icons/pchat.xpm")));
	bcast_btn = new wxButton(this, ID_BROADCAST, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	bcast_btn->SetBitmap(wxBitmap(wxT("../icons/pm.xpm")));
	news_btn = new wxButton(this, ID_NEWS, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	news_btn->SetBitmap(wxBitmap(wxT("../icons/news.xpm")));
	sinfo_btn = new wxButton(this, ID_SERVERINFO, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	sinfo_btn->SetBitmap(wxBitmap(wxT("../icons/info.xpm")));
	xfers_btn = new wxButton(this, ID_TRANSFERS, wxEmptyString, wxDefaultPosition, wxSize(32,32));
	xfers_btn->SetBitmap(wxBitmap(wxT("../icons/xfers.xpm")));
	sizer->Add(files_btn, 0, wxTOP, 5);
	sizer->Add(ulist_btn, 0, wxTOP, 5);
	sizer->Add(chat_btn, 0, wxTOP, 5);
	sizer->Add(bcast_btn, 0, wxTOP, 5);
	sizer->Add(news_btn, 0, wxTOP, 5);
	sizer->Add(sinfo_btn, 0, wxTOP, 5);
	sizer->Add(xfers_btn, 0, wxTOP, 5);

	SetSizerAndFit(sizer);
	CreateStatusBar();
	SetStatusText("Not connected");
}

Re: SetSizeAndFit() squishes widgets and ignores style flags

Posted: Fri May 13, 2016 9:46 am
by catalin
maybe you should create the status bar before asking the frame to fit only the button sizer
and make sure the bitmaps are valid

Re: SetSizeAndFit() squishes widgets and ignores style flags

Posted: Fri May 13, 2016 10:06 am
by Schala
I see. Valid as in not null, or valid as in the XPM file exists? I'm not sure I understand.

Edit: I seem to have fixed the problem by, after creating the status bar like you recommended, called SetSizer() and then sizer->Fit(this) as opposed to SetSizerAndFit(). The window's style flags remain undamaged this way.