mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-18 14:16:12 -06:00
.reference
git-svn-id: svn://ultimatepp.org/upp/trunk@11351 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
3a18a7bca3
commit
39e6d995cb
6 changed files with 68 additions and 47 deletions
35
reference/ArrayCtrlSorting/main.cpp
Normal file
35
reference/ArrayCtrlSorting/main.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
ArrayCtrl list;
|
||||
list.AddColumn("Trivial").Sorting();
|
||||
|
||||
list.AddColumn("With function")
|
||||
.SortingBy( // sort with sorting function
|
||||
[](int a, int b) -> int {
|
||||
int q = SgnCompare(a % 100, b % 100);
|
||||
if(q) return q;
|
||||
return SgnCompare(a, b);
|
||||
}
|
||||
)
|
||||
.SortDefault(); // set his column to be the initial sorting column;
|
||||
|
||||
list.AddColumn("Line comparison").SortingLined( // row indices passed to predicate
|
||||
[&list](int i, int j) -> bool {
|
||||
return int(list.Get(i, 0)) + int(list.Get(i, 1)) // sort by sum of first two columns
|
||||
< int(list.Get(i, 0)) + int(list.Get(i, 1));
|
||||
}
|
||||
);
|
||||
|
||||
for(int i = 0; i < 300; i++)
|
||||
list.Add((int)Random(1000), (int)Random(10000), 0);
|
||||
|
||||
TopWindow app;
|
||||
app.Add(list.SizePos());
|
||||
app.Sizeable();
|
||||
list.DoColumnSort(); // sort by current sorting column (which is "With function" column because of SortDefault
|
||||
app.Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue