How to change aui tab color ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
AndrzejB
Experienced Solver
Experienced Solver
Posts: 76
Joined: Sun Nov 29, 2015 12:46 pm

How to change aui tab color ?

Post by AndrzejB » Wed Sep 23, 2020 5:05 pm

Aui has attached component wxAuiTabArt which draws.
How to change background or font color of title?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4423
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to change aui tab color ?

Post by ONEEYEMAN » Wed Sep 23, 2020 6:17 pm

Hi,
Create wxAuiArtProvider-derived class and do what you want there?

Thank you.

AndrzejB
Experienced Solver
Experienced Solver
Posts: 76
Joined: Sun Nov 29, 2015 12:46 pm

Re: How to change aui tab color ?

Post by AndrzejB » Wed Sep 23, 2020 7:39 pm

Color should be not constants. For example: all tabs would have usual colors except tabs with modified files.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4423
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to change aui tab color ?

Post by ONEEYEMAN » Wed Sep 23, 2020 8:35 pm

Hi,
Like I said - create a new TabArt class and do whatever you want there.

Thank you.

AndrzejB
Experienced Solver
Experienced Solver
Posts: 76
Joined: Sun Nov 29, 2015 12:46 pm

Re: How to change aui tab color ?

Post by AndrzejB » Thu Sep 24, 2020 6:42 am

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.

User avatar
doublemax
Moderator
Moderator
Posts: 15173
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change aui tab color ?

Post by doublemax » Thu Sep 24, 2020 8:29 am

There is no method called GetFontColour() in wxAuiTabArt.
Use the source, Luke!

AndrzejB
Experienced Solver
Experienced Solver
Posts: 76
Joined: Sun Nov 29, 2015 12:46 pm

Re: How to change aui tab color ?

Post by AndrzejB » Thu Sep 24, 2020 10:41 am

This method is in my art class: MyBaseTabArt

User avatar
doublemax
Moderator
Moderator
Posts: 15173
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change aui tab color ?

Post by doublemax » Thu Sep 24, 2020 11:19 am

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).
Use the source, Luke!

AndrzejB
Experienced Solver
Experienced Solver
Posts: 76
Joined: Sun Nov 29, 2015 12:46 pm

Re: How to change aui tab color ?

Post by AndrzejB » Thu Sep 24, 2020 1:15 pm

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.

Post Reply