I am currently rewriting some code so that I can have my application better handle high DPI settings. I am currently developing on ubuntu 14.04 and I am using wxWidgets 3.1.0. I was wondering if there are any good methods on allowing your application to scale based on the DPI settings.
Here is a code snippet from one of my dialogs:
Code: Select all
wxFont *font = new wxFont(8.5, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
// This seciton will create a new panel and apply 2 buttons on the panel.
// The 2 buttons are associated with the panel and when the panel is destoryed, so are the buttons.
initialStartPanel->Create(this, wxID_ANY, wxDefaultPosition);
wxButton *buttonNewFile = new wxButton(initialStartPanel, buttonID::ID_buttonNew, "New", wxDefaultPosition);
buttonNewFile->SetFont(*font);
buttonNewFile->SetMinSize(initialStartPanel->FromDIP(wxSize(75, 23)));
// buttonNewFile->SetInitialSize(FromDIP(wxSize(75, 23), this));
// buttonNewFile->SetSize(buttonNewFile->GetBestFittingSize());
// buttonNewFile->SetSize(wxSize(75, 23));
wxButton *buttonOpenFile = new wxButton(initialStartPanel, buttonID::ID_buttonOpen, "Open");
buttonOpenFile->SetFont(*font);
buttonOpenFile->SetInitialSize(FromDIP(wxSize(75, 23)));
buttonSizer->Add(buttonNewFile, 0, wxALL, 6);
buttonSizer->Add(buttonOpenFile, 0, wxTOP | wxBOTTOM | wxRIGHT, 6);
initialStartPanel->SetSizer(buttonSizer);
SetSizerAndFit(buttonSizer);
buttonSizer->Fit(initialStartPanel);
this->SetSize(initialStartPanel->GetSize());
this->SetMaxSize(this->GetSize());
// this->SetMinSize(initialStartPanel->GetSize());
// this->SetMaxSize(initialStartPanel->GetSize());
As you can see in my code, I have been trying some different methods. With 3.1.0, I have been trying to utilize the FromDIP function. My interpretation on this function is that it is able to take in a set wxSize() and return a scaled wxSize value based on the DPI settings. Please correct me if I am wrong.
I also have been looking at another post where the user would like to implement scaling based on DPI settings:
viewtopic.php?t=41603
However, when I implemented my method on using the wxDLG_unit, the button became too huge!
For those wondering, at a normal DPI setting, the size of the button needs to be wxSize(75, 23). If the DPI is increased, then the button should increase in proportion. If the DPI is decreased then there is no change in the size.