Home » Community » Coffee corner » Quiz #5
|
|
Re: Quiz #5 [message #57910 is a reply to message #57907] |
Mon, 27 December 2021 23:50   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Lance wrote on Mon, 27 December 2021 21:04mirek:
Yeah, it's a very handy facility. I tried and learned something new.
When designing layout, we turn to add new Ctrl, copy& paste, and moving things around, resulting in Ctrls not in sensible tab-order. By selecting a group of Ctrls and apply the button, the layout designer will order the Ctrls in a left-to-right-top-to-bottom order so navigate by tabbing will not seem to be random.
Note the selected Ctrls will be removed from the layout and then insert to the very front of the layout after sorting by their position.
Great to know. I used to do it manually with a lot of effort and many rounds of try-and-error.
BTW, it is a rare example of bubblesort usecase 
The one and only advantage of pure bubblesort is that it can work well when the sorting predicate has "fuzzy" state (the ordering of two elements is not known), which is sometimes the case when deciding order here...
|
|
|
|
Re: Quiz #5 [message #57913 is a reply to message #57912] |
Tue, 28 December 2021 03:04   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
It's good to understand the logic the system used to order Ctrls. So I copy the Predicate herebool RectLess(const Rect& a, const Rect& b)
{
int d = min(a.bottom, b.bottom) - max(a.top, b.top);
int w = min(a.GetHeight(), b.GetHeight());
return d > w / 2 ? a.left < b.left : a.top < b.top;
}
If the height of common vertical part is over half of height of the shorter ctrs, compare horizontally, otherwise , compare vertically.
Given any two Ctrls, the predicate is deterministic. Is this predicate not transitive, ie. a<b, b<c doesn't imply a<c? What if we pass the predicate to a quicksort like algorithm?
[Updated on: Tue, 28 December 2021 03:05] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Thu Apr 24 19:04:51 CEST 2025
Total time taken to generate the page: 0.01896 seconds
|