forked from Mirrorlandia_minetest/minetest
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.
This commit is contained in:
parent
6b408248a1
commit
c4d1862344
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user