Show/Hide window in wxAuiManager 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
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 7:52 am

i have a window in wxAuiManager, when I hide it, and show it again - it changes size to minimal.
function to hide/show is this:

Code: Select all

void showPane(wxAuiManager& fman, wxWindow* fw, bool fshow){
	wxAuiPaneInfo &linfo =  fman.GetPane(fw); //get reference to panel info
	if (! linfo.IsOk()) return;
	if (fshow) linfo.Show();
	else linfo.Hide();
	fman.Update();
}
but I want to preserve size of the window during hide/show.
thanks, Alex.
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 12:26 pm

You will need to save size information and restore them
See Save and Load methods to save and load correct size et al
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 3:20 pm

strange, that it's not default behavior. what else could user prefer than show the window with last its size?

to use your advice in easy way, i need an ability to attach some user data to wxWindow, or wxAuiPaneInfo. then if i attached wxString to it I can easy restore the size of hidden window...but seems I cant do such an attachment.
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 3:54 pm

alys666 wrote:
Tue Jun 11, 2019 3:20 pm
strange, that it's not default behavior. what else could user prefer than show the window with last its size?
Not really if you understand what AUI thing was designed to do. Once you get used to it, its far accurate in restoring and you can have different "persectives" each with its own layout.
alys666 wrote:
Tue Jun 11, 2019 3:20 pm
to use your advice in easy way, i need an ability to attach some user data to wxWindow, or wxAuiPaneInfo. then if i attached wxString to it I can easy restore the size of hidden window...but seems I cant do such an attachment.
One thing I forgot to mention is you can save all panes with wxAuiManager save/load perspective. I linked for pane info assuming you are interested in saving single pane

Can you explain what you want to do? I don't see a need to save such info in wxWindow and as long time AUI user never had. Only time I needed to save such information is on app exit or when altering perspective to different layout
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 4:00 pm

BTW I have checked again your code and I see you are using wxWindow to get the pane. You can get pane by its name. Make sure you set name to pane info before adding towith AddPane. Then you can use that name to search it

Code: Select all

wxTextCtrl* text1 = new wxTextCtrl(this, -1);
wxTextCtrl* text2 = new wxTextCtrl(this, -1);
m_mgr.AddPane(text1, wxAuiPaneInfo().Left().Name("someName"));
m_mgr.AddPane(text2, wxBOTTOM, "Pane Caption");
m_mgr.Update();
//........
wxAuiPaneInfo pane = m_mgr.GetPane("someName");

//works with pane which holds text1 pointer
if(pane.IsShown())
{
	pane.Hide();
}

Last edited by evstevemd on Tue Jun 11, 2019 5:00 pm, edited 1 time in total.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 4:29 pm

my idea is very simple. face of my programm - it's wxAuiManager with different panes.
Sometime user wants to hide a pane, if he does not need it. he presses a cross sign, and hides. but to restore the window - there is a menu - show this panel, show that panel, etc. he presses menu item, and i call mentioned function. and panel restores an minimal size. thanks a lot!
ps... i know about name and savePerspective. i use it to save/load perspective of my programm. but i have direct pointers to my panes, so i just use them.:)
Alex.
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 4:35 pm

Hi,
alys666 wrote:
Tue Jun 11, 2019 4:29 pm
my idea is very simple. face of my programm - it's wxAuiManager with different panes.
Sometime user wants to hide a pane, if he does not need it. he presses a cross sign, and hides. but to restore the window - there is a menu - show this panel, show that panel, etc. he presses menu item, and i call mentioned function. and panel restores an minimal size. thanks a lot!
Alex.
Let say you have Panes A, B, and C
I would store 4 configurations persistently ( you can even use wxFileConfig or another mechanism if your app indeed have any

CONF_A - store pane info for pane A
CONF_B - store pane info for pane B
CONF_C - store pane info for pane C
CONF_A LL- store wxAui last window

on response to Hide/Show, just load data from config the Update wxAuiManager
When app exits store whole perspective on CONF_ALL so that next time App starts it will load exit state

That makes layout very flexible. Of course with flexibility comes more responsibilities
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 4:54 pm

evstevemd wrote:
Tue Jun 11, 2019 4:35 pm
on response to Hide/Show, just load data from config the Update wxAuiManager
When app exits store whole perspective on CONF_ALL so that next time App starts it will load exit state
it's not "just load". In generic way i need a map (panel names/panel pointers) -> saved data.
then if i want to show hidden panel, i need to find saved data by panel pointer, and restore it's size.
it's ideologically wrong imho.
would you a like a windows-looking interface, if hidden window restores to its minimal size?
here is exactly the same case.
Alex
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 4:58 pm

alys666 wrote:
Tue Jun 11, 2019 4:54 pm
it's not "just load". In generic way i need a map (panel names/panel pointers) -> saved data.
then if i want to show hidden panel, i need to find saved data by panel pointer, and restore it's size.
it's ideologically wrong imho.
would you a like a windows-looking interface, if hidden window restores to its minimal size?
here is exactly the same case.
Alex
That is true only if you added without pane name. I gave an example above, one showing how to add a pane as pointer and another is how to add Pane with info including name. Then search/Loading becomes easier. No searching for pointers whatsoever. Let me know if the example is not clear.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 5:08 pm

it's how i generically add panes to all my managers...disliking heaps of writings

Code: Select all

static void addWatchedPane(
	wxAuiManager &fm,
	wxWindow *fw,
	int fdir,
	const wxString &fname
		//,const wxString &fcapt=wxEmptyString
)
{
	wxAuiPaneInfo lpi;
	lpi.Name(fname);
	lpi.Caption(fname);
		//lpi.CaptionVisible(false);
	lpi.dock_direction = fdir;
	lpi.PaneBorder(false);
		//lpi.Gripper(false);
	fm.AddPane(fw,lpi);
}
so I do not store any panel info...and everything works good, except of hiding/showing.
imho it's some flaw of this manager implementaion.
ps. how matter - how i search this panelinfo? by name or by pointer? it's exactly the same internally stored panel info... and manager must use to restore a panel size on show.
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 5:29 pm

after line

Code: Select all

fm.AddPane(fw,lpi);
Save the settings. It's not hard. Here is a simple non-working code for just explaining what am saying

in your app let say OnInit you add

Code: Select all

wxFileConfig *conf = new wxFileConfig("", "", "/path/to/config/config.ini");
wxConfigBase::Set(conf);
then you can use it, for example in your code

Code: Select all

static void addWatchedPane(
	wxAuiManager &fm,
	wxWindow *fw,
	int fdir,
	const wxString &fname
		//,const wxString &fcapt=wxEmptyString
)
{
	wxAuiPaneInfo lpi;
	lpi.Name(fname);
	lpi.Caption(fname);
		//lpi.CaptionVisible(false);
	lpi.dock_direction = fdir;
	lpi.PaneBorder(false);
		//lpi.Gripper(false);
	fm.AddPane(fw,lpi);
	
	//save it
	wxConfigBase::Get()->Write("/config/panes/"+fname, fm.SavePaneInfo(lpi));
}

then where you are restoring/showing the pane

Code: Select all

wxString storedData;
wxString paneName = "whateverNameItWas";
wxAuiPaneInfo pane = m_auiMgr->GetPane(paneName); 
if(!pane.IsShown())
{
	wxConfigBase::Get()->Read("/config/panes/"+paneName, &storedData);
	pane.Show();
	
	m_auiMgr->LoadPaneInfo(storedData, pane)
	m_auiMgr->Update();
}
It is not tested (obviously) but it will give you an idea. As you can see it is not that complex.
Only remember to delete wxConfig object when your app exits
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 7:16 pm

you're wrong in idea.
because there are troubles ONLY if window was hidden in manager by user during session, ...so hiding function must save the window's panel info in a map - "pointer->string". and showing function must find the saved value in the map, and restore the panel size.
that's how i will do. But i'm sure some people will ask me - bro! what the shitty code is here?

it's have no sense to save panel info at creation.
1. all the manager will load its current perspective after adding them to him, and will set sizes and positions of panes...
look, we are writing all this crutches just because developers forgot to restore pane to it's previous size and position.
or they had some idea about it?

ps: advice: do not store intermediate data on disk, if you can. you device could have flash memory only and it decreases its lifetime.
ubuntu 16.04, wxWidgets 3.0.4

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2171
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Show/Hide window in wxAuiManager

Post by evstevemd » Tue Jun 11, 2019 8:13 pm

alys666 wrote:
Tue Jun 11, 2019 7:16 pm
you're wrong in idea.
because there are troubles ONLY if window was hidden in manager by user during session, ...so hiding function must save the window's panel info in a map - "pointer->string". and showing function must find the saved value in the map, and restore the panel size.
that's how i will do. But i'm sure some people will ask me - bro! what the shitty code is here?

it's have no sense to save panel info at creation.
1. all the manager will load its current perspective after adding them to him, and will set sizes and positions of panes...
look, we are writing all this crutches just because developers forgot to restore pane to it's previous size and position.
or they had some idea about it?

ps: advice: do not store intermediate data on disk, if you can. you device could have flash memory only and it decreases its lifetime.
Well that was an example to demo what I was saying and it was explicitly said so. It wasn't a drop in replacement. So put it where it makes sense on your project. Also saving in the file is a choice, you can put it in any storage you wish. I hope you've got what I was trying to explain!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Tue Oct 18, 2016 2:31 pm

Re: Show/Hide window in wxAuiManager

Post by alys666 » Tue Jun 11, 2019 9:27 pm

a have found an easy hack.
would be useful for people:

Code: Select all

void showManagerPane(wxAuiManager& fman, wxWindow* fw, bool fshow){
	wxAuiPaneInfo &linfo =  fman.GetPane(fw); //get reference to panel info
	if (!linfo.IsOk()) return; //something wrong - return
	if(!fshow){
		//if we are hiding - set MINIMAL panel info size == current size!!!
		//so manager at opening, could not make panel smaller, than at hide
		linfo.MinSize(linfo.rect.width,linfo.rect.height);
	}
	linfo.Show(fshow); //do show/hide
	fman.Update();

	//if are showing - restore minimal size to some reasonable values - 
	//else the window can't be done smaller than was at hiding
	if(fshow) linfo.MinSize(100,40); 
}
ubuntu 16.04, wxWidgets 3.0.4

Post Reply