Browse Source

Removed the LockScrolling attribute, because disabling automatically is simpler.

David Piuva 5 years ago
parent
commit
78e8763c30
2 changed files with 22 additions and 31 deletions
  1. 22 30
      Source/DFPSR/gui/components/ListBox.cpp
  2. 0 1
      Source/DFPSR/gui/components/ListBox.h

+ 22 - 30
Source/DFPSR/gui/components/ListBox.cpp

@@ -33,7 +33,6 @@ void ListBox::declareAttributes(StructureDefinition &target) const {
 	target.declareAttribute(U"Color");
 	target.declareAttribute(U"List");
 	target.declareAttribute(U"SelectedIndex");
-	target.declareAttribute(U"LockScrolling");
 }
 
 Persistent* ListBox::findAttribute(const ReadableString &name) {
@@ -43,8 +42,6 @@ Persistent* ListBox::findAttribute(const ReadableString &name) {
 		return &(this->list);
 	} else if (string_caseInsensitiveMatch(name, U"SelectedIndex")) {
 		return &(this->selectedIndex);
-	} else if (string_caseInsensitiveMatch(name, U"LockScrolling")) {
-		return &(this->lockScrolling);
 	} else {
 		return VisualComponent::findAttribute(name);
 	}
@@ -235,34 +232,29 @@ int64_t ListBox::getVisibleScrollRange() {
 // Optional limit of scrolling, to be applied when the user don't explicitly scroll away from the selection
 // limitSelection should be called before limitScrolling, because scrolling limits depend on selection
 void ListBox::limitScrolling(bool keepSelectedVisible) {
-	if (this->lockScrolling.value) {
-		this->firstVisible = 0;
-		this->hasVerticalScroll = false;
+	// Try to load the font before estimating how big the view is
+	this->completeAssets();
+	if (this->font.get() == nullptr) {
+		throwError("Cannot get the font size because ListBox failed to get a font!\n");
+	}
+	int64_t itemCount = this->list.value.length();
+	int64_t visibleRange = this->getVisibleScrollRange();
+	int64_t maxScroll;
+	int64_t minScroll;
+	// Big enough list to need scrolling but big enough list-box to fit two buttons inside
+	this->hasVerticalScroll = itemCount > visibleRange && this->location.width() >= scrollWidth * 2 && this->location.height() >= scrollEndHeight * 2;
+	if (keepSelectedVisible) {
+		maxScroll = this->selectedIndex.value;
+		minScroll = maxScroll + 1 - visibleRange;
 	} else {
-		// Try to load the font before estimating how big the view is
-		this->completeAssets();
-		if (this->font.get() == nullptr) {
-			throwError("Cannot get the font size because ListBox failed to get a font!\n");
-		}
-		int64_t itemCount = this->list.value.length();
-		int64_t visibleRange = this->getVisibleScrollRange();
-		int64_t maxScroll;
-		int64_t minScroll;
-		// Big enough list to need scrolling but big enough list-box to fit two buttons inside
-		this->hasVerticalScroll = itemCount > visibleRange && this->location.width() >= scrollWidth * 2 && this->location.height() >= scrollEndHeight * 2;
-		if (keepSelectedVisible) {
-			maxScroll = this->selectedIndex.value;
-			minScroll = maxScroll + 1 - visibleRange;
-		} else {
-			maxScroll = itemCount - visibleRange;
-			minScroll = 0;
-		}
-		if (this->firstVisible > maxScroll) {
-			this->firstVisible = maxScroll;
-		}
-		if (this->firstVisible < minScroll) {
-			this->firstVisible = minScroll;
-		}
+		maxScroll = itemCount - visibleRange;
+		minScroll = 0;
+	}
+	if (this->firstVisible > maxScroll) {
+		this->firstVisible = maxScroll;
+	}
+	if (this->firstVisible < minScroll) {
+		this->firstVisible = minScroll;
 	}
 }
 

+ 0 - 1
Source/DFPSR/gui/components/ListBox.h

@@ -36,7 +36,6 @@ public:
 	PersistentColor color;
 	PersistentStringList list;
 	PersistentInteger selectedIndex; // Should always be inside of the list's 0..length-1 bound or zero.
-	PersistentBoolean lockScrolling; // When true, the first item will always be visible at the top.
 	void declareAttributes(StructureDefinition &target) const override;
 	Persistent* findAttribute(const ReadableString &name) override;
 private: