Page 1 of 1

How to change aui tab color ?

Posted: Wed Sep 23, 2020 5:05 pm
by AndrzejB
Aui has attached component wxAuiTabArt which draws.
How to change background or font color of title?

Re: How to change aui tab color ?

Posted: Wed Sep 23, 2020 6:17 pm
by ONEEYEMAN
Hi,
Create wxAuiArtProvider-derived class and do what you want there?

Thank you.

Re: How to change aui tab color ?

Posted: Wed Sep 23, 2020 7:39 pm
by AndrzejB
Color should be not constants. For example: all tabs would have usual colors except tabs with modified files.

Re: How to change aui tab color ?

Posted: Wed Sep 23, 2020 8:35 pm
by ONEEYEMAN
Hi,
Like I said - create a new TabArt class and do whatever you want there.

Thank you.

Re: How to change aui tab color ?

Posted: Thu Sep 24, 2020 6:42 am
by AndrzejB
I have problem with virtual methods of tabArt.
I rewrite MyBaseTabArt = whole wxAuiGenericTabArt, except :
in DrawTab:

Code: Select all

wxColor font_color = GetFontColour(page.active, back_color);
where

Code: Select all

virtual wxColour GetFontColour(bool pageActive, const wxColour& back_color);

wxColour MyBaseTabArt::GetFontColour(bool pageActive, const wxColour& back_color) {
    wxColor sys_color = wxSystemSettings::GetColour(
            pageActive ? wxSYS_COLOUR_CAPTIONTEXT : wxSYS_COLOUR_INACTIVECAPTIONTEXT);
    wxColor font_color = wxAuiHasSufficientContrast(back_color, sys_color) ? sys_color
            : wxAuiGetBetterContrastColour(back_color, *wxWHITE, *wxBLACK);
    return font_color;
}
and

Code: Select all

class MyTabArt: public MyBaseTabArt {
public:
    virtual wxColour GetFontColour(bool pageActive, const wxColour& back_color) wxOVERRIDE;
};

wxColour MyTabArt::GetFontColour(bool pageActive, const wxColour& back_color) {
    return wxColour(255,50,50);
}
I use:

Code: Select all

    wxAuiTabArt *art = new MyTabArt;
    auiNotebook->SetArtProvider(art);
But GetFontColour was called as non-virtual, disassembly show that is jump to constant address.

Re: How to change aui tab color ?

Posted: Thu Sep 24, 2020 8:29 am
by doublemax
There is no method called GetFontColour() in wxAuiTabArt.

Re: How to change aui tab color ?

Posted: Thu Sep 24, 2020 10:41 am
by AndrzejB
This method is in my art class: MyBaseTabArt

Re: How to change aui tab color ?

Posted: Thu Sep 24, 2020 11:19 am
by doublemax
AndrzejB wrote:
Thu Sep 24, 2020 10:41 am
This method is in my art class: MyBaseTabArt
How is that supposed to work? AUIs internal drawing routines only know about and use the methods from wxAuiTabArt. By subclassing wxAuiTabArt and overwriting one or more of its virtual methods, you can change what is drawn. Adding a new, unknown method will not change anything. How is the present code about to know that it needs to call your method to get the font color?

Anyway, after looking into the implementation of wxAuiGenericTabArt::DrawTab, i don't think it's possible to change the font color easily.

Code: Select all

    wxColor sys_color = wxSystemSettings::GetColour(
        page.active ? wxSYS_COLOUR_CAPTIONTEXT : wxSYS_COLOUR_INACTIVECAPTIONTEXT);
    wxColor font_color = wxAuiHasSufficientContrast(back_color, sys_color) ? sys_color
        : wxAuiGetBetterContrastColour(back_color, *wxWHITE, *wxBLACK);
    dc.SetTextForeground(font_color);
    dc.DrawText(draw_text,
                text_offset,
                drawn_tab_yoff + (drawn_tab_height)/2 - (texty/2) - 1);
The text color is more or less hard coded through the system colors.

Your only option would be to re-implement the whole method. (You could of course copy the whole code into MyBaseTabArt and just make changes to the font color in the above code part).

Re: How to change aui tab color ?

Posted: Thu Sep 24, 2020 1:15 pm
by AndrzejB
I copy whole wxAuiGenericTabArt to my class and change my class.
Was problem with polymorphic.
Problem is solved:
was

Code: Select all

wxAuiTabArt* MyBaseTabArt::Clone() {
    return new MyBaseTabArt(*this);
}
Must be added necessary Clone in subclass!

Code: Select all

wxAuiTabArt *MyTabArt::Clone() {
    return new MyTabArt(*this);
}
Notabene: for good clone handling is needed metaclasses.