clickable list with different custom controls for each column
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
clickable list with different custom controls for each column
A couple of years ago I created this custom list:
Is there a better way to have such a clickable List?
Thank you!
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!
Re: clickable list with different custom controls for each column
Except for a totally custom-drawn control, wxGrid is really the only option i can think of.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: clickable list with different custom controls for each column
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.
Re: clickable list with different custom controls for each column
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.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.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: clickable list with different custom controls for each column
Quite sure, visual studio shows me that the wxStaticText ctor uses most of the time.doublemax wrote: ↑Mon May 06, 2019 5:42 pmAre 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.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.
Re: clickable list with different custom controls for each column
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.visual studio shows me that the wxStaticText ctor uses most of the time.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: clickable list with different custom controls for each column
Thank you! I want to try and switch to wxGrid to massivly simplify my code. It grew to a monster over the years.doublemax wrote: ↑Mon May 06, 2019 7:57 pmI 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.visual studio shows me that the wxStaticText ctor uses most of the time.
When playing around with wxGrid, these questions came up: - 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?
Re: clickable list with different custom controls for each column
[I'm not a wxGrid expert.]
Try overriding wxGrid::DrawColLabel- how can I get rid of these ugly borders in the colums label?
I would guess this should happen automatically if you have a correct wxLocale active.- can I make float value cells to use the language settings, i.e. comma in german, point in english?
You'll need a custom renderer, check the "grid" sample.- 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?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: clickable list with different custom controls for each column
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 ","?!?
Re: clickable list with different custom controls for each column
Try creating a wxLocale instance that exists during the lifetime of the app, e.g. as member variable of wxApp.
Then run the code again.
Code: Select all
m_locale.Init(wxLANGUAGE_DEFAULT);
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 539
- Joined: Fri May 22, 2009 8:52 am
- Location: Bremen, Germany
Re: clickable list with different custom controls for each column
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?
How can I make the wxSizer always have the minimal size?
Re: clickable list with different custom controls for each column
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 themI am a little embarrassed but I have to admit I was always confused about FitInside(), Fit()
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().How can I make the wxSizer always have the minimal size?
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!