Fix #98: tab traversal in native look editors. Use bounding_box instead of style.left/top/etc.

This commit is contained in:
Twan van Laarhoven
2020-09-27 14:44:55 +02:00
parent 7a788c724d
commit cf19bc76c3
2 changed files with 16 additions and 12 deletions
+1
View File
@@ -6,6 +6,7 @@ HEAD: new items added as changes are made
Bug fixes: Bug fixes:
* Fixed: crash in expand_keywords when given empty tags (#90) * Fixed: crash in expand_keywords when given empty tags (#90)
* Fixed: tab traversal in native look editors (style and set info tabs) (#98)
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
version 2.1.1, 2020-06-14 version 2.1.1, 2020-06-14
+15 -12
View File
@@ -79,7 +79,7 @@ template <typename It, typename V, typename Comp>
It next_element(It first, It last, V const& x, Comp comp) { It next_element(It first, It last, V const& x, Comp comp) {
It best = last; It best = last;
for (It it = first ; it != last ; ++it) { for (It it = first ; it != last ; ++it) {
if (comp(x, *it)) { if (*it != x && comp(x, *it)) {
// this is a candidate // this is a candidate
if (best == last || comp(*it, *best)) { if (best == last || comp(*it, *best)) {
best = it; best = it;
@@ -118,34 +118,37 @@ void DataEditor::select(ValueViewer* new_viewer) {
} }
struct CompareTabOrder { struct CompareTabOrder {
bool operator() (ValueViewer* a, ValueViewer* b) { bool operator() (ValueViewer const& a, ValueViewer const& b) {
assert(a && b); Style& as = *a.getStyle(), &bs = *b.getStyle();
Style& as = *a->getStyle(), &bs = *b->getStyle();
// if tab_index differs, use that // if tab_index differs, use that
if (as.tab_index < bs.tab_index) return true; if (as.tab_index < bs.tab_index) return true;
if (as.tab_index > bs.tab_index) return false; if (as.tab_index > bs.tab_index) return false;
// otherwise look at the positions // otherwise look at the positions
// To get a total order, we look at the viewer center. // To get a total order, we look at the viewer center.
// Not completely (y,x), because for viewers that are almost at the same y we prefer to sort by x // Not completely (y,x), because for viewers that are almost at the same y we prefer to sort by x
double ax = 2*as.left + as.right; // bias a bit to the left double ax = a.bounding_box.x + 0.25*a.bounding_box.width; // bias a bit to the left of the middle
double bx = 2*bs.left + bs.right; double bx = b.bounding_box.x + 0.25*b.bounding_box.width;
double ay = as.top + as.bottom + 0.1*ax; // a bit of x, so that dominates when y is approximately equal double ay = a.bounding_box.top() + a.bounding_box.bottom() + 0.1*ax; // a bit of x, so that dominates when y is approximately equal
double by = bs.top + bs.bottom + 0.1*bx; double by = b.bounding_box.top() + b.bounding_box.bottom() + 0.1*bx;
if (ay < by) return true; if (ay < by) return true;
if (ay > by) return false; if (ay > by) return false;
if (ax < bx) return true; if (ax < bx) return true;
if (ax > bx) return false; if (ax > bx) return false;
// arbitrary order otherwise // arbitrary order otherwise
return a < b; return a.getField()->name < b.getField()->name;
}
bool operator() (ValueViewer* a, ValueViewer* b) {
assert(a && b);
return operator () (*a, *b);
} }
bool operator() (ValueViewerP const& a, ValueViewer* b) { bool operator() (ValueViewerP const& a, ValueViewer* b) {
return operator () (a.get(), b); return operator () (*a, *b);
} }
bool operator() (ValueViewer* a, ValueViewerP const& b) { bool operator() (ValueViewer* a, ValueViewerP const& b) {
return operator () (a, b.get()); return operator () (*a, *b);
} }
bool operator() (ValueViewerP const& a, ValueViewerP const& b) { bool operator() (ValueViewerP const& a, ValueViewerP const& b) {
return operator () (a.get(), b.get()); return operator () (*a, *b);
} }
}; };