Skip to content

Commit

Permalink
Fixing the issue of listview always being reset on change
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed May 1, 2023
1 parent 96d1e8e commit cb48771
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ public class ListView : WindowElement, ElementContainer, TextInputListener {
* Must be called every time when adding new items is finished.
*/
public void refresh() {
selection = -1;
if (selection >= entries.length)
selection = cast(int)entries.length - 1;
recalculateTotalSizes;
draw;
}
Expand All @@ -584,7 +585,8 @@ public class ListView : WindowElement, ElementContainer, TextInputListener {
foreach (ListViewItem key; entries) {
totalHeight += key.height;
}
totalHeight += _header.height;
if (_header)
totalHeight += _header.height;
StyleSheet ss = getStyleSheet();
bool needsVSB, needsHSB;
if (totalWidth > position.width)
Expand All @@ -596,6 +598,11 @@ public class ListView : WindowElement, ElementContainer, TextInputListener {
if (needsHSB && totalHeight > position.height - ss.drawParameters["HorizScrollBarSize"])
needsVSB = true;
totalHeight -= _header.height;
int hPos, vPos;
if (horizSlider)
hPos = horizSlider.value;
if (vertSlider)
vPos = vertSlider.value;
if (needsVSB) {
const int maxvalue = needsHSB ? totalHeight - (position.height - ss.drawParameters["HorizScrollBarSize"]
- _header.height) : totalHeight - (position.height - _header.height);
Expand All @@ -604,16 +611,18 @@ public class ListView : WindowElement, ElementContainer, TextInputListener {
position.right, needsHSB ? position.bottom - ss.drawParameters["VertScrollBarSize"] : position.bottom);
vertSlider = new VertScrollBar(maxvalue, source ~ "VSB", target);
vertSlider.setParent(this);
vertSlider.value = vPos;
vertSlider.onScrolling = &scrollBarEventOut;
} else vertSlider = null;
if (needsHSB){
if (needsHSB) {
const int maxvalue = needsVSB ? totalWidth - (position.width - ss.drawParameters["VertScrollBarSize"]) :
totalWidth - position.width;
const Box target = Box(position.left, position.bottom - ss.drawParameters["VertScrollBarSize"] + 2,
needsVSB ? position.right - ss.drawParameters["HorizScrollBarSize"] : position.right,
position.bottom);
horizSlider = new HorizScrollBar(maxvalue, source ~ "VSB", target);
horizSlider.setParent(this);
horizSlider.value = hPos;
horizSlider.onScrolling = &scrollBarEventOut;
} else horizSlider = null;
}
Expand Down

0 comments on commit cb48771

Please sign in to comment.