Minor tree view improvements

This commit is contained in:
Markus Gans 2017-10-15 15:27:36 +02:00
parent 2e506a1367
commit af2caf8fcf
3 changed files with 18 additions and 17 deletions

View File

@ -82,7 +82,7 @@ struct Treeview::TreeItem
{ return &name; } { return &name; }
const char* const* end() const const char* const* end() const
{ return &density + 1; } { return reinterpret_cast<const char* const*>(&child_element); }
// Data Members // Data Members
const char* name; const char* name;

View File

@ -318,6 +318,7 @@ class FListView : public FWidget
FObjectIterator appendItem (FListViewItem*); FObjectIterator appendItem (FListViewItem*);
void processClick(); void processClick();
void processChanged(); void processChanged();
void setRelativePosition (int);
void stepForward(); void stepForward();
void stepBackward(); void stepBackward();
void stepForward (int); void stepForward (int);

View File

@ -912,10 +912,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
int new_pos = first_visible_line.getPosition() + mouse_y - 2; int new_pos = first_visible_line.getPosition() + mouse_y - 2;
if ( new_pos < int(getCount()) ) if ( new_pos < int(getCount()) )
{ setRelativePosition (mouse_y - 2);
current_iter = first_visible_line;
current_iter += mouse_y - 2;
}
if ( isVisible() ) if ( isVisible() )
drawList(); drawList();
@ -977,10 +974,7 @@ void FListView::onMouseMove (FMouseEvent* ev)
int new_pos = first_visible_line.getPosition() + mouse_y - 2; int new_pos = first_visible_line.getPosition() + mouse_y - 2;
if ( new_pos < int(getCount()) ) if ( new_pos < int(getCount()) )
{ setRelativePosition (mouse_y - 2);
current_iter = first_visible_line;
current_iter += mouse_y - 2;
}
if ( isVisible() ) if ( isVisible() )
drawList(); drawList();
@ -1158,13 +1152,13 @@ void FListView::onWheel (FWheelEvent* ev)
} }
else else
{ {
// Save relative position from the top line // Save relative position from the first line
int ry = current_iter.getPosition() - first_visible_line.getPosition(); int ry = current_iter.getPosition() - first_visible_line.getPosition();
// Save difference from top
int difference = first_visible_line.getPosition(); int difference = first_visible_line.getPosition();
first_visible_line -= difference; first_visible_line -= difference;
last_visible_line -= difference; last_visible_line -= difference;
current_iter = first_visible_line; setRelativePosition(ry);
current_iter += ry;
} }
break; break;
@ -1181,13 +1175,13 @@ void FListView::onWheel (FWheelEvent* ev)
} }
else else
{ {
// Save relative position from the top line // Save relative position from the first line
int ry = current_iter.getPosition() - first_visible_line.getPosition(); int ry = current_iter.getPosition() - first_visible_line.getPosition();
// Save difference from bottom
int differenz = element_count - last_visible_line.getPosition() - 1; int differenz = element_count - last_visible_line.getPosition() - 1;
first_visible_line += differenz; first_visible_line += differenz;
last_visible_line += differenz; last_visible_line += differenz;
current_iter = first_visible_line; setRelativePosition(ry);
current_iter += ry;
} }
break; break;
@ -1753,6 +1747,13 @@ void FListView::processChanged()
emitCallback("row-changed"); emitCallback("row-changed");
} }
//----------------------------------------------------------------------
void FListView::setRelativePosition (int ry)
{
current_iter = first_visible_line;
current_iter += ry;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::stepForward() void FListView::stepForward()
{ {
@ -1883,8 +1884,7 @@ void FListView::scrollToY (int y)
{ {
first_visible_line = itemlist.begin(); first_visible_line = itemlist.begin();
first_visible_line += y; first_visible_line += y;
current_iter = first_visible_line; setRelativePosition (ry);
current_iter += ry;
last_visible_line = first_visible_line; last_visible_line = first_visible_line;
last_visible_line += pagesize; last_visible_line += pagesize;
} }