wxAuiToolBar - delete separator Topic is solved

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
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

wxAuiToolBar - delete separator

Post by alys666 »

Question - how to delete not a tool from this wxAuiToolBar.
for example - separator or spacer.
ubuntu 20.04, wxWidgets 3.2.1
rando
Knows some wx things
Knows some wx things
Posts: 35
Joined: Fri Nov 09, 2018 9:11 pm

Re: wxAuiToolBar - delete separator

Post by rando »

There are DeleteTool() and DeleteByIndex() functions.
Read the docs: https://docs.wxwidgets.org/3.1.2/classw ... 7ddca4517d
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: wxAuiToolBar - delete separator

Post by alys666 »

rando wrote: Wed Jun 19, 2019 4:13 pm There are DeleteTool() and DeleteByIndex() functions.
Read the docs: https://docs.wxwidgets.org/3.1.2/classw ... 7ddca4517d
what is separator id?

Code: Select all

wxAuiToolBarItem* wxAuiToolBar::AddTool(int tool_id,
		const wxString &  	label,
		const wxBitmap &  	bitmap,
		const wxString &  	short_help_string = wxEmptyString,
		wxItemKind  	kind = wxITEM_NORMAL 
	) 		
it's tool has id, separator has not, it's just a pointer

Code: Select all

wxAuiToolBarItem* wxAuiToolBar::AddSeparator()
added: i just checked - returned by AddSeparator pointer to structure has id(if use GetId()) = -2. for all added separators. So i cannot delete separator "by id".
Last edited by alys666 on Wed Jun 19, 2019 7:43 pm, edited 1 time in total.
ubuntu 20.04, wxWidgets 3.2.1
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxAuiToolBar - delete separator

Post by doublemax »

Looking into the aui source code, it seems like you could use the returned pointer to set an id and then later use that id to delete it. Might be worth a try.
Use the source, Luke!
rando
Knows some wx things
Knows some wx things
Posts: 35
Joined: Fri Nov 09, 2018 9:11 pm

Re: wxAuiToolBar - delete separator

Post by rando »

I usually clear the complete toolbar then rebuild it with the needed tools and layout as required. You can have a function to do that with an enum argument that lists your various layouts. Doing it that way produces easier to read and modify code down the road.
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: wxAuiToolBar - delete separator

Post by alys666 »

rando wrote: Wed Jun 19, 2019 5:34 pm I usually clear the complete toolbar then rebuild it with the needed tools and layout as required. You can have a function to do that with an enum argument that lists your various layouts. Doing it that way produces easier to read and modify code down the road.
in my case, I have a "stack like looking" tool bar.
from the beginning there are basic tools, but when some subsystem gets activated, it added its tools at start, and removes at finish. subsystem knows nothing about parent tool set, and won't do it.
to solve I would add a pseudoseparator, kinda void tool with vertical bar, as a label.
but, i think, wxWIdgets needs a ticket about it.
wxAuiToolbar definitely suffers from lack of method DeleteItem(wxAuiToolBarItem*)
ubuntu 20.04, wxWidgets 3.2.1
rando
Knows some wx things
Knows some wx things
Posts: 35
Joined: Fri Nov 09, 2018 9:11 pm

Re: wxAuiToolBar - delete separator

Post by rando »

I wonder if GetToolCount() would work for you, store the highest index before you add anything then DeleteByIndex() all of the items after that one when you are ready to remove the added tools. That is assuming you always add/remove from the end.
DeleteByIndex(int tool_id) I think is actually DeleteByIndex(int idx) but you would need to check the source to know for sure. I am on my way home so no time for that right now, sorry.
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: wxAuiToolBar - delete separator

Post by alys666 »

yes, rando. your idea works well.
ps. i discovered just now that actually it's an instance of wxToolBar, not wxAuiToolBar... :) but there is a the same problem.
My old code uses wxToolbar, but since some time i switched to wxAuiToolbar... but can't understand serious difference for now, except of mentioning that wxToolbar is dockable only under GTK.
ubuntu 20.04, wxWidgets 3.2.1
Post Reply