From cf19bc76c3bfb279b6c9041e15d42afbf3d5beef Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Sun, 27 Sep 2020 14:44:55 +0200 Subject: [PATCH] Fix #98: tab traversal in native look editors. Use bounding_box instead of style.left/top/etc. --- CHANGES.md | 1 + src/gui/control/card_editor.cpp | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c83da674..0d0fc887 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ HEAD: new items added as changes are made Bug fixes: * 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 diff --git a/src/gui/control/card_editor.cpp b/src/gui/control/card_editor.cpp index 407e3967..cb3b4331 100644 --- a/src/gui/control/card_editor.cpp +++ b/src/gui/control/card_editor.cpp @@ -79,7 +79,7 @@ template It next_element(It first, It last, V const& x, Comp comp) { It best = last; for (It it = first ; it != last ; ++it) { - if (comp(x, *it)) { + if (*it != x && comp(x, *it)) { // this is a candidate if (best == last || comp(*it, *best)) { best = it; @@ -118,34 +118,37 @@ void DataEditor::select(ValueViewer* new_viewer) { } struct CompareTabOrder { - bool operator() (ValueViewer* a, ValueViewer* b) { - assert(a && b); - Style& as = *a->getStyle(), &bs = *b->getStyle(); + bool operator() (ValueViewer const& a, ValueViewer const& b) { + Style& as = *a.getStyle(), &bs = *b.getStyle(); // if tab_index differs, use that if (as.tab_index < bs.tab_index) return true; if (as.tab_index > bs.tab_index) return false; // otherwise look at the positions // 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 - double ax = 2*as.left + as.right; // bias a bit to the left - double bx = 2*bs.left + bs.right; - double ay = as.top + as.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 ax = a.bounding_box.x + 0.25*a.bounding_box.width; // bias a bit to the left of the middle + double bx = b.bounding_box.x + 0.25*b.bounding_box.width; + 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 = b.bounding_box.top() + b.bounding_box.bottom() + 0.1*bx; if (ay < by) return true; if (ay > by) return false; if (ax < bx) return true; if (ax > bx) return false; // 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) { - return operator () (a.get(), b); + return operator () (*a, *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) { - return operator () (a.get(), b.get()); + return operator () (*a, *b); } };