Changeset - r27009:2a13cdb5a0cf
[Not reviewed]
master
0 3 0
PeterN - 15 months ago 2023-03-09 15:19:58
peter1138@openttd.org
Fix #10554: Let Scrollbar::SetPosition clamp instead of assert. (#10555)
3 files changed with 4 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -795,7 +795,7 @@ public:
 
		/* Position scrollbar to selected group */
 
		for (uint i = 0; i < this->rows; i++) {
 
			if (this->groups[i]->index == sel) {
 
				this->vscroll->SetPosition(Clamp(i - this->vscroll->GetCapacity() / 2, 0, std::max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
 
				this->vscroll->SetPosition(i - this->vscroll->GetCapacity() / 2);
 
				break;
 
			}
 
		}
src/script/script_gui.cpp
Show inline comments
 
@@ -866,9 +866,7 @@ struct ScriptDebugWindow : public Window
 
		}
 
		if (this->autoscroll) {
 
			int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity());
 
			if (scroll_pos != this->vscroll->GetPosition()) {
 
				this->vscroll->SetPosition(scroll_pos);
 

	
 
			if (this->vscroll->SetPosition(scroll_pos)) {
 
				/* We need a repaint */
 
				this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
 
				this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
src/widget_type.h
Show inline comments
 
@@ -746,10 +746,8 @@ public:
 
	 */
 
	bool SetPosition(int position)
 
	{
 
		assert(position >= 0);
 
		assert(this->count <= this->cap ? (position == 0) : (position + this->cap <= this->count));
 
		uint16 old_pos = this->pos;
 
		this->pos = position;
 
		this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
 
		return this->pos != old_pos;
 
	}
 

	
 
@@ -768,7 +766,7 @@ public:
 
			case SS_BIG:   difference *= this->cap; break;
 
			default: break;
 
		}
 
		return this->SetPosition(Clamp(this->pos + difference, 0, std::max(this->count - this->cap, 0)));
 
		return this->SetPosition(this->pos + difference);
 
	}
 

	
 
	/**
0 comments (0 inline, 0 general)