clickable list with different custom controls for each column

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

clickable list with different custom controls for each column

Post by mael15 » Mon May 06, 2019 11:08 am

A couple of years ago I created this custom list:
listClickable.jpg
listClickable.jpg (40.65 KiB) Viewed 944 times
Every entry is clickable and a wxControl appears to edit the value, these include wxSpinCtrl, wxChoice and wxButton to remove the row from the list. The clickable values are wxStaticText and unfortuately these take a lot of time to create. So each time this list is refreshed, it takes about 3 seconds on my powerful developer machine, more on a good laptop that runs my app.
Is there a better way to have such a clickable List?
Thank you!

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

Re: clickable list with different custom controls for each column

Post by doublemax » Mon May 06, 2019 12:59 pm

Except for a totally custom-drawn control, wxGrid is really the only option i can think of.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: clickable list with different custom controls for each column

Post by mael15 » Mon May 06, 2019 3:20 pm

doublemax wrote:
Mon May 06, 2019 12:59 pm
Except for a totally custom-drawn control, wxGrid is really the only option i can think of.
Thanx. looks promising. I remember having too many problems with it a couple of years ago. But maybe it is improved or I am better now or I can make some compromises this time around. =P~

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

Re: clickable list with different custom controls for each column

Post by doublemax » Mon May 06, 2019 5:42 pm

So each time this list is refreshed, it takes about 3 seconds on my powerful developer machine, more on a good laptop that runs my app.
Are you sure it's the creation of the controls that takes so long? Or could it be the sizer algorithm? In the latter case you could try to calculate the item positions yourself as it looks pretty simple in your case.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: clickable list with different custom controls for each column

Post by mael15 » Mon May 06, 2019 7:32 pm

doublemax wrote:
Mon May 06, 2019 5:42 pm
So each time this list is refreshed, it takes about 3 seconds on my powerful developer machine, more on a good laptop that runs my app.
Are you sure it's the creation of the controls that takes so long? Or could it be the sizer algorithm? In the latter case you could try to calculate the item positions yourself as it looks pretty simple in your case.
Quite sure, visual studio shows me that the wxStaticText ctor uses most of the time.

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

Re: clickable list with different custom controls for each column

Post by doublemax » Mon May 06, 2019 7:57 pm

visual studio shows me that the wxStaticText ctor uses most of the time.
I see, that's probably the size calculation using wxDC::GetMultiLineTextExtent. There's probably room for optimization knowing that all wxStaticText have the same font and similar texts. You could try subclassing wxStaticText and overriding DoGetBestClientSize(). I'm not sure if it's worth the effort though. But could still be less work than switching to wxGrid.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: clickable list with different custom controls for each column

Post by mael15 » Tue May 07, 2019 8:57 am

doublemax wrote:
Mon May 06, 2019 7:57 pm
visual studio shows me that the wxStaticText ctor uses most of the time.
I see, that's probably the size calculation using wxDC::GetMultiLineTextExtent. There's probably room for optimization knowing that all wxStaticText have the same font and similar texts. You could try subclassing wxStaticText and overriding DoGetBestClientSize(). I'm not sure if it's worth the effort though. But could still be less work than switching to wxGrid.
Thank you! I want to try and switch to wxGrid to massivly simplify my code. It grew to a monster over the years.
When playing around with wxGrid, these questions came up:
grid1.jpg
grid1.jpg (31.82 KiB) Viewed 878 times
- how can I get rid of these ugly borders in the colums label?
- can I make float value cells to use the language settings, i.e. comma in german, point in english?
- I would like to have a small button/bitmap in each row in the last column to indicate that clicking here removes the row. Something smaller than writing "delete". Can I add a button or a bitmap?

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

Re: clickable list with different custom controls for each column

Post by doublemax » Tue May 07, 2019 10:05 am

[I'm not a wxGrid expert.]
- how can I get rid of these ugly borders in the colums label?
Try overriding wxGrid::DrawColLabel
- can I make float value cells to use the language settings, i.e. comma in german, point in english?
I would guess this should happen automatically if you have a correct wxLocale active.
- I would like to have a small button/bitmap in each row in the last column to indicate that clicking here removes the row. Something smaller than writing "delete". Can I add a button or a bitmap?
You'll need a custom renderer, check the "grid" sample.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: clickable list with different custom controls for each column

Post by mael15 » Wed May 08, 2019 8:24 am

doublemax wrote:
Tue May 07, 2019 10:05 am
- can I make float value cells to use the language settings, i.e. comma in german, point in english?
I would guess this should happen automatically if you have a correct wxLocale active.
hmmm, I am surprised by this:

Code: Select all

int lg = wxLocale::GetSystemLanguage();
const wxLanguageInfo *inf = wxLocale::GetLanguageInfo(lg);	// german
wxString asdf = wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);	// "." but should be ","?!?
	

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

Re: clickable list with different custom controls for each column

Post by doublemax » Wed May 08, 2019 8:38 am

Try creating a wxLocale instance that exists during the lifetime of the app, e.g. as member variable of wxApp.

Code: Select all

m_locale.Init(wxLANGUAGE_DEFAULT);
Then run the code again.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 384
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: clickable list with different custom controls for each column

Post by mael15 » Fri May 10, 2019 4:22 pm

One more problem: Sometimes I use HideCol(int) and I want the containing wxSizer so shrink afterwards (and grow after ShowCol(int)). I am a little embarrassed but I have to admit I was always confused about FitInside(), Fit(), Layout() etc.
How can I make the wxSizer always have the minimal size?

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

Re: clickable list with different custom controls for each column

Post by doublemax » Fri May 10, 2019 9:03 pm

I am a little embarrassed but I have to admit I was always confused about FitInside(), Fit()
To be honest, me too. I always have to look into the source code to see what they actually do. And they don't do exactly what i need, so i never use them ;)
How can I make the wxSizer always have the minimal size?
That's not so easy to answer as it depends on the whole sizer structure. Normally, just Layout() on the topmost sizer in the sizer hierarchy should be enough. If not, try calling InvalidateBestSize() (on the grid) and then Layout().

The important methods that you can use e.g. for debug output are:

wxSizer::CalcMin(). It calculates the minimum size of the sizer so that its content is complete visible

wxWindow::GetBestSize() returns the window's preferred size. E.g. for custom controls it's important to implement wxWindow::DoGetBestSize() so that they behave correctly when put into a sizer.
Use the source, Luke!

Post Reply