Kirix Support Forums

Setting fonts for wxAuiNotebook

Please post all general questions, comments, bug reports, and any other wxAUI feedback here.

Setting fonts for wxAuiNotebook

Postby Julian Smart on Tue Jun 12, 2007 2:41 pm

Hi,

Anyone had any success setting fonts for the wxAuiNotebook tabs? I tried:

wxFont normalFont(6, wxSWISS, wxNORMAL, wxNORMAL);

wxFont selectedFont(normalFont);
selectedFont.SetWeight(wxBOLD);

paletteNotebook->GetArtProvider()->SetNormalFont(normalFont);
paletteNotebook->GetArtProvider()->SetSelectedFont(selectedFont);
paletteNotebook->GetArtProvider()->SetMeasuringFont(selectedFont);

which didn't change the drawn text size, but did change the tab heights. Then I tried deriving from wxAuiNotebook in order to set the protected font members:

wbAuiPaletteNotebook(wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxAUI_NB_DEFAULT_STYLE):
wxAuiNotebook(parent, id, pos, size, style)
{
wxFont normalFont(6, wxSWISS, wxNORMAL, wxNORMAL);
m_normal_font = normalFont;
m_selected_font = normalFont;
m_selected_font.SetWeight(wxBOLD);
}

but this only changed the font for the selected tab. Plus it doesn't seem right to have to derive a class just to change the tab font.

Any ideas gratefully received!

Thanks,

Julian
Julian Smart
Registered User
 
Posts: 17
Joined: Sun Nov 05, 2006 4:45 pm

Postby Ben on Thu Jun 14, 2007 7:56 am

Hi Julian,

Did you try calling UpdateTabCtrlHeight() from your derived class> If my memory serves me correctly, it might work.

But this does raise the point that we need a better way to do this.

Thanks,
Ben
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Re: Setting fonts for wxAuiNotebook

Postby Ken on Fri Jun 22, 2007 8:09 pm

[Edit: Forum Transition Issue, Ken re-posted for Julian Smart]

Hi Ben,

I tried calling UpdateTabCtrlHeight, but only the selected tab gets the set font - the other tabs are drawn with the regular font.

One problem is that wxAuiNotebook::SetSelection overrides the dock art with:

if (tabctrl != ctrl)
tabctrl->SetSelectedFont(m_normal_font);
else
tabctrl->SetSelectedFont(m_selected_font);

which would make it harder to implement different behaviour, combined with the fact that m_normal_font and m_selected_font don't have public accessors.

Anyway I've now got font settings working with this change in auibook.cpp:

wxAuiTabArt* wxAuiDefaultTabArt::Clone()
{
wxAuiDefaultTabArt* art = new wxAuiDefaultTabArt;
art->SetNormalFont(m_normal_font);
art->SetSelectedFont(m_selected_font);
art->SetMeasuringFont(m_measuring_font);

return art;
}

so that creation of new tab controls uses the fonts as set in the initial art provider. It still requires derivation of the notebook. So if I may suggest these 3 changes:

- copy fonts (and probably other attributes) in clone, so it really is a clone;
- add accessors for SetNormal/Selected/MeasuringFont in wxAuiNotebook whch also call the art accessors to maintain consistency. (SetMeasuringFont will _only_ call the art accessor);
- as a convenience, wxAuiNotebook::SetFont will call all 3 of these functions with suitable fonts (bold for SetSelected/MeasuringFont).

I can add this to CVS head (and the Clone change to 2.8 ) if this sounds OK. Actually I could add the further accessors to 2.8 enclosed in suitable ABI guards.

Regards,

Julian
Last edited by Ken on Fri Jun 22, 2007 8:12 pm, edited 1 time in total.
Ken Kaczmarek
Kirix Support Team
User avatar
Ken
Kirix Support Team
 
Posts: 147
Joined: Mon Dec 19, 2005 10:36 am

Re: Setting fonts for wxAuiNotebook

Postby Ken on Fri Jun 22, 2007 8:11 pm

[Edit: Forum Transition Issue: Ken re-posted for Julian Smart]

Just to say I've added the font setters and font copying in the art object so calling SetFont should work OK now. I've also added GetHeightForPageHeight which allows you to determine how big the notebook should be for a given page height.

Julian
Ken Kaczmarek
Kirix Support Team
User avatar
Ken
Kirix Support Team
 
Posts: 147
Joined: Mon Dec 19, 2005 10:36 am

Return to wxAUI Questions, Thoughts & Feedback