diff options
author | Kahrl <kahrl@gmx.net> | 2015-10-17 23:34:45 +0200 |
---|---|---|
committer | Kahrl <kahrl@gmx.net> | 2015-10-17 23:57:28 +0200 |
commit | c4d18623440b58b9f90629c798687608bc32c6da (patch) | |
tree | d864e0ebbbf752a9909a69dda4685488f5e16e6a | |
parent | 6b408248a16b0c61007247d8bce23a349f86b45c (diff) | |
download | minetest-c4d18623440b58b9f90629c798687608bc32c6da.tar.gz minetest-c4d18623440b58b9f90629c798687608bc32c6da.tar.bz2 minetest-c4d18623440b58b9f90629c798687608bc32c6da.zip |
Fix GUITable selection issues with trees
- setOpenedTrees(): this internal function was calling setSelected()
to update m_selected. Since setSelected() calls autoScroll(),
this caused the scrollbar to scroll back to the selected row
in some cases when that shouldn't be done.
For example, clicking the "+" to open a tree caused autoscroll.
Fix this by making setOpenedTrees() modify m_selected directly.
- setDynamicData(): set scrollbar position after calling
setSelected(), not before. This avoids setSelected()'s autoscroll
messing up the scrollbar position again.
- setSelected(): If an invisible row is selected, open all parents
of the selected row in order to make the selected row visible.
This fixes the issue where all the trees are closed again whenever
you return from the setting edit dialog to the settings tab.
-rw-r--r-- | src/guiTable.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/guiTable.cpp b/src/guiTable.cpp index ed5b0d87b..b327782e2 100644 --- a/src/guiTable.cpp +++ b/src/guiTable.cpp @@ -560,14 +560,31 @@ void GUITable::setSelected(s32 index) m_sel_column = 0; m_sel_doubleclick = false; - --index; + --index; // Switch from 1-based indexing to 0-based indexing s32 rowcount = m_rows.size(); - - if (index >= rowcount) + if (rowcount == 0) { + return; + } else if (index < 0) { + index = 0; + } else if (index >= rowcount) { index = rowcount - 1; - while (index >= 0 && m_rows[index].visible_index < 0) - --index; + } + + // If the selected row is not visible, open its ancestors to make it visible + if (m_rows[index].visible_index < 0) { + std::set<s32> opened_trees; + getOpenedTrees(opened_trees); + s32 indent = m_rows[index].indent; + for (s32 j = index - 1; j >= 0; --j) { + if (m_rows[j].indent < indent) { + opened_trees.insert(j); + indent = m_rows[j].indent; + } + } + setOpenedTrees(opened_trees); + } + if (index >= 0) { m_selected = m_rows[index].visible_index; assert(m_selected >= 0 && m_selected < (s32) m_visible_rows.size()); @@ -596,11 +613,11 @@ void GUITable::setDynamicData(const DynamicData &dyndata) m_keynav_time = dyndata.keynav_time; m_keynav_buffer = dyndata.keynav_buffer; - m_scrollbar->setPos(dyndata.scrollpos); - setSelected(dyndata.selected); m_sel_column = 0; m_sel_doubleclick = false; + + m_scrollbar->setPos(dyndata.scrollpos); } const c8* GUITable::getTypeName() const @@ -1091,7 +1108,9 @@ void GUITable::getOpenedTrees(std::set<s32> &opened_trees) const void GUITable::setOpenedTrees(const std::set<s32> &opened_trees) { - s32 old_selected = getSelected(); + s32 old_selected = -1; + if (m_selected >= 0) + old_selected = m_visible_rows[m_selected]; std::vector<s32> parents; std::vector<s32> closed_parents; @@ -1143,7 +1162,9 @@ void GUITable::setOpenedTrees(const std::set<s32> &opened_trees) updateScrollBar(); - setSelected(old_selected); + // m_selected must be updated since it is a visible row index + if (old_selected >= 0) + m_selected = m_rows[old_selected].visible_index; } void GUITable::openTree(s32 to_open) |