ide: Layout Designer sorting of items improved #484

git-svn-id: svn://ultimatepp.org/upp/trunk@6303 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-09-02 13:05:51 +00:00
parent 27736e1630
commit ded21fe5d2
2 changed files with 27 additions and 14 deletions

View file

@ -1263,23 +1263,36 @@ void LayDes::SortItems()
if(currentlayout < 0 || cursor.GetCount() < 2)
return;
LayoutData& l = CurrentLayout();
Vector<int> sc(cursor, 1);
Sort(sc);
int count = sc.GetCount();
Sort(cursor);
int count = cursor.GetCount();
Array<LayoutItem> item;
Vector<Rect> rect;
for(int i = 0; i < count; ++i)
rect.Add(CtrlRect(l.item[sc[i]].pos, l.size));
// Use selection sort as RectLess is not transitive
for(int i = 0; i < count - 1; i++) {
int ii = i;
for(int j = i + 1; j < count; j++)
if(RectLess(rect[j], rect[ii]))
ii = j;
Swap(rect[i], rect[ii]);
Swap(l.item[sc[i]], l.item[sc[ii]]);
for(int i = 0; i < count; ++i) {
rect.Add(CtrlRect(l.item[cursor[i]].pos, l.size));
item.Add() = l.item[cursor[i]];
}
l.item.Remove(cursor);
bool swap = false;
do {
swap = false;
for(int i = 0; i < count - 1; i++)
if(RectLess(rect[i + 1], rect[i])) {
Swap(rect[i], rect[i + 1]);
Swap(item[i], item[i + 1]);
swap = true;
}
}
while(swap);
int ii = cursor[0];
l.item.InsertPick(ii, item);
cursor.Clear();
for(int i = 0; i < count; i++)
cursor.Add(i + ii);
ReloadItems();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After