FreeOrion

Forums for the FreeOrion project
It is currently Thu Jun 20, 2013 9:29 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Sortable ListBox
PostPosted: Sat Dec 08, 2007 6:39 pm 
Offline
Space Squid

Joined: Wed Sep 08, 2004 3:20 pm
Posts: 60
Location: Switzerland
I have some problems regarding the sortable listbox. I noticed that GG::ListBox has already support for sorting rows. But it seems not finished or just buggy or I am using it wrong. I made a small testcase and noticed a couple of things that are not how they should be.

1. If I supply a compare function it is ignored during row insertion. Only string comparison is done here. So I have to set the Sort column again after the list has been populated and sort it again.
2. But this introduces another problem. During this sorting the positions of the rows are not corrected. So now the rows have been sorted but they are drawn at the same positions as before. And if you select them, the selection is drawn at the correct position where the row should be.
3. During a call to ListBox::Clear() the head row also gets deleted.

So should I fix this in ListBox, just hack around it in CUISortedListBox or just implement something that works for the BuildDesignator only?

Question regarding rows: How can I make the control in the rightmost cell automatically scale up to the available space?


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Sat Dec 08, 2007 7:46 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8062
Location: Vancouver, BC
Have you e mailed tzlaine? He's probably the only person who can usefully answer...


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Mon Dec 10, 2007 11:00 am 
Offline
Space Squid

Joined: Wed Sep 08, 2004 3:20 pm
Posts: 60
Location: Switzerland
Nope. I haven't. I don't have his email adress. Or should I just PM him?


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Mon Dec 10, 2007 2:05 pm 
Offline
Graphics Lead Emeritus
User avatar

Joined: Mon Mar 08, 2004 6:17 pm
Posts: 1933
Location: 52°16'N 10°31'E
He checks his PMs regularly and that's the way I've been talking to him lately.


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Mon Dec 10, 2007 8:26 pm 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
This sure looks like a bug. Can you provide a code snippet that exercises the bug?


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Tue Dec 11, 2007 8:41 am 
Offline
Space Squid

Joined: Wed Sep 08, 2004 3:20 pm
Posts: 60
Location: Switzerland
I just toyed around with ListBox in your controls.cpp tutorial example. If you step through the Insert code you will notice
that DefaultRowCMP<...> is not called (line 1443-1446).
In this particular example it doesn't make any difference though:
Code:
m_lb->SetSortCmp(GG::ListBox::DefaultRowCmp<GG::ListBox::Row>());

m_lb->Insert(new CustomTextRow("Number", 3));
m_lb->Insert(new CustomTextRow("Number", 5));
m_lb->Insert(new CustomTextRow("Number", 1));
m_lb->Insert(new CustomTextRow("Number", 7));
m_lb->Insert(new CustomTextRow("Number", 2));
m_lb->Insert(new CustomTextRow("Number", 4));
m_lb->Insert(new CustomTextRow("Number", 6));

m_lb->SetSortCol(1);


Whereas in "Insert" the vertical row positions are determined correctly, any later sorting (by calling SetSortCol or SetStyle) doesn't update them.
I was wondering anyway wouldn't it be more elegant to have row as a lightweight object that only knows how high it is, and where it's cells are aligned horizontally. But the position is determined by ListBox?
Then to fix the problem that the head row gets deleted during Clear, i just made a little fix. It's not that elegant but it works:
Code:
Index: src/ListBox.cpp
===================================================================
--- src/ListBox.cpp>----(revision 623)
+++ src/ListBox.cpp>----(working copy)
@@ -901,7 +901,9 @@
     bool signal = !m_rows.empty(); // inhibit signal if the list box was already empty
     m_rows.clear();
     m_caret = -1;
+    DetachChild(m_header_row); //header_row gets deleted in DeleteChildren() without this
     DeleteChildren();
+    AttachChild(m_header_row);
     m_vscroll = 0;
     m_hscroll = 0;
     m_first_row_shown = m_first_col_shown = 0;


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Tue Dec 11, 2007 5:33 pm 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
Wow. I just looked at the relevant place in the code. It looks like a drunk person wrote it. I'll have a fix in tonight.


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Wed Dec 12, 2007 5:19 am 
Offline
Programming Lead Emeritus
User avatar

Joined: Thu Jun 26, 2003 1:33 pm
Posts: 1092
These problems should be fixed in GG.


Top
 Profile  
 
 Post subject: Re: Sortable ListBox
PostPosted: Wed Dec 12, 2007 10:40 am 
Offline
Space Squid

Joined: Wed Sep 08, 2004 3:20 pm
Posts: 60
Location: Switzerland
Thanks. Works perfectly now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group