wxBitmap not centered in wxButton on Mac

143 views Asked by At

i am building a desktop GUI using wxWidgets-3.1.3 on 3 platforms: Windows, Mac and Linux.

The home page is as attached, which just shows 3 tile buttons. Each button has a statictext description below and a bitmap in the button.

However, when I build on Windows and Linux, bitmap pictures are able to show in the middle of the button. When i tried to build using XCode on mac, the position of the bitmaps get distorted as shown. I know the root cause is because the bitmap Direction is wxLEFT by default.

I have tried:

adding wxBU_NOTEXT style to each button, but it doesn't work.

I need this UI by next week. So any help will be much appreciated !

wxImage::AddHandler(new wxPNGHandler);
    wxBitmap DataValidationIcon = wxBITMAP_PNG_FROM_DATA(Data_Validation);
    wxBitmap ActiveIdleIcon = wxBITMAP_PNG_FROM_DATA(Active_Idle);
    wxBitmap SDKDemoIcon = wxBITMAP_PNG_FROM_DATA(SDK_Demo);

    DataValidationBtn->SetBitmap(DataValidationIcon);
    ActiveIdleBtn->SetBitmap(ActiveIdleIcon);
    SDKDemoBtn->SetBitmap(SDKDemoIcon);

MacOS distorted the positioning of bitmap

2

There are 2 answers

0
VZ. On

You don't show the code creating SDKDemoBtn, so I am not sure how do you create it and whether you use any alignment styles. But in any/the worst case, you can always dynamically generate a bitmap of your button size containing the real bitmap centred inside it using wxImage::Paste().

0
Daynee On

I managed to get it solved by SetMinSize() for MacOS specifically. Apparently, for Mac, there are stringent UI guidelines to follow. Bitmaps will be auto-fit to the button size if you set default button size. If you set minimum button size larger than the bitmap, the layout will be distorted.