Re: wxAuiNotebook, changing the close button bitmap?
Tony Kennedy <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
PS. I tried a few things like modifying the out_tab_rect, out_button_rect
and x_extent in DrawTab, but nothing seemed to do what I needed.
Tony.
On Thursday, 23 November 2023 at 09:33:59 UTC Tony Kennedy wrote:
> Thanks again for this, it is almost perfect for my needs.
>
> Do you know how to make the tabs slightly wider? When I activate a tab,
> the font is bold (which is good), but then the text is truncated slightly.
> What I mean is, if the tab has the label "company,product", when I select
> it, I get "company,prod...". I'd prefer to keep all the text.
>
> Tony.
>
>
>
> On Thursday, 23 November 2023 at 07:55:11 UTC Tony Kennedy wrote:
>
>> Thank you for this. I tried something similar, but only had code
>> for DrawButton which never got called.
>>
>> All the best,
>>
>> Tony.
>>
>> On Wednesday, 22 November 2023 at 18:59:40 UTC PB wrote:
>>
>>> Hi,
>>>
>>> *Disclaimer: I know little about wxAUI, just took a look at the sources,
>>> and I am Windows only.*
>>>
>>> Replacing close button bitmaps in wxAuiSimpleTabArt is very simple but
>>> more complicated with wxAuiDefaultTabArt. wxAuiDefaultTabArt differs
>>> between platforms
>>> <https://github.com/wxWidgets/wxWidgets/blob/14f6f82e46641ef226b23143c1f44570c769176b/include/wx/aui/tabart.h#L320>,
>>> e.g., it actually is wxAuiMSWTabArt on Windows which uses native theme API
>>> to draw the button.
>>>
>>> Anyway, I tried if using a custom art for the tab works, writing a
>>> proof-of-concept code using a help bitmap as the close button (same for
>>> active and disabled), borrowing the draw methods from the generic tab art
>>> when needed, not caring about how it looks:
>>> [image: wx-auintb-art.png]
>>>
>>> #include <wx/wx.h>
>>> #include <wx/artprov.h>
>>> #include <wx/aui/auibook.h>
>>>
>>> class MyAuiSimpleTabArt : public wxAuiSimpleTabArt
>>> {
>>> public:
>>> MyAuiSimpleTabArt(const wxBitmapBundle& activeCloseBmp, const
>>> wxBitmapBundle& disabledCloseBmp)
>>> {
>>> m_activeCloseBmp = activeCloseBmp;
>>> m_disabledCloseBmp = disabledCloseBmp;
>>> }
>>>
>>> wxAuiTabArt* Clone()
>>> {
>>> return new MyAuiSimpleTabArt(*this);
>>> }
>>> };
>>>
>>> class MyAuiDefaultTabArt : public wxAuiDefaultTabArt
>>> {
>>> public:
>>> MyAuiDefaultTabArt(const wxBitmapBundle& activeCloseBmp, const
>>> wxBitmapBundle& disabledCloseBmp)
>>> {
>>> m_activeCloseBmp = activeCloseBmp;
>>> m_disabledCloseBmp = disabledCloseBmp;
>>> }
>>>
>>> // This draws the "Close active tab" button on the far right
>>> void DrawButton(wxDC& dc, wxWindow* wnd, const wxRect& in_rect, int
>>> bitmap_id, int button_state, int orientation, wxRect* out_rect) override
>>> {
>>> // for testing, use generic version
>>> wxAuiGenericTabArt::DrawButton(dc, wnd, in_rect, bitmap_id,
>>> button_state, orientation, out_rect);
>>> }
>>>
>>> void DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page,
>>> const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect,
>>> wxRect* out_button_rect, int* x_extent) override
>>> {
>>> // for testing, use generic version
>>> wxAuiGenericTabArt::DrawTab(dc, wnd, page, in_rect,
>>> close_button_state, out_tab_rect, out_button_rect, x_extent);
>>> }
>>>
>>> wxAuiTabArt* Clone()
>>> {
>>> return new MyAuiDefaultTabArt(*this);
>>> }
>>> };
>>>
>>> class MyFrame : public wxFrame
>>> {
>>> public:
>>> MyFrame(wxWindow* parent = nullptr) : wxFrame(parent, wxID_ANY,
>>> "Test")
>>> {
>>> const wxBitmapBundle activeClose =
>>> wxArtProvider::GetBitmapBundle(wxART_HELP, wxART_OTHER, wxSize(16,16));
>>> const wxBitmapBundle disabledClose = activeClose;
>>>
>>> wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
>>>
>>> mainSizer->Add(AddNotebook(new MyAuiSimpleTabArt(activeClose,
>>> disabledClose)), wxSizerFlags(1).Expand());
>>> mainSizer->Add(AddNotebook(new MyAuiDefaultTabArt(activeClose,
>>> disabledClose)), wxSizerFlags(1).Expand());
>>> SetSizer(mainSizer);
>>> }
>>> private:
>>> wxAuiNotebook* AddNotebook(wxAuiTabArt* tabArt)
>>> {
>>> wxAuiNotebook* notebook = new wxAuiNotebook(this, wxID_ANY,
>>> wxDefaultPosition, wxDefaultSize, wxAUI_NB_CLOSE_BUTTON |
>>> wxAUI_NB_CLOSE_ON_ALL_TABS | wxAUI_NB_DEFAULT_STYLE);
>>>
>>> notebook->SetArtProvider(tabArt);
>>> for ( size_t i = 0; i < 10; ++i )
>>> notebook->AddPage(new wxPanel(notebook),
>>> wxString::Format("Page %zu", i), false);
>>> return notebook;
>>> }
>>> };
>>>
>>> class MyApp : public wxApp
>>> {
>>> bool OnInit() override
>>> {
>>> (new MyFrame())->Show();
>>> return true;
>>> }
>>> }; wxIMPLEMENT_APP(MyApp);
>>>
>>> To conclude, customizing the tab art seems possible but may require some
>>> effort to look good and work properly on all the platforms.
>>>
>>> Regards,
>>> PB
>>>
>>
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/64a84ee7-f64f-4308-a3f1-444bc2069791n%40googlegroups.com.